using System;
class MainClass {//Conway's Game of Life
    
    enum cell {dead, alive, tempD, tempA,};
    static void Main()
    {
        int[,] life = {{0,0,0,0,0,0,0,0,0,0},
                       {0,0,0,0,0,0,0,0,0,0},
                       {0,0,0,0,0,0,0,0,0,0},
                       {0,0,0,0,0,0,0,0,0,0},
                       {0,0,0,0,0,1,0,0,0,0},
                       {0,0,0,0,1,1,1,0,0,0},
                       {0,0,0,0,0,1,0,0,0,0},
                       {0,0,0,0,0,0,0,0,0,0},
                       {0,0,0,0,0,0,0,0,0,0},
                       {0,0,0,0,0,0,0,0,0,0}};
        int y = 1;
        Console.WriteLine("{0}x{1}\n{2} {3} {4} {5}",life.GetLength(0),life.GetLength(1),(int)cell.dead,(int)cell.alive,(int)cell.tempD,(int)cell.tempA);
        foreach(int x in life)
        {
            Console.Write(x+" ");
            if(y++ % life.GetLength(0) == 0)
                Console.WriteLine("");
        }
        Console.WriteLine("--------------------------------------------");
        //Based on Conway's rules, the cells take up temporary states so as not to mess with the ongoing process
        y = 1;
        for(int i = 1; i < life.GetLength(0)-1; i ++)
        {
            for(int a = 1; a < life.GetLength(1)-1; a ++)
            {
                int count = -1;
                for(int w = -1; w <= 1; w ++)
                {
                    for(int z = -1; z <= 1; z ++)
                    {
                        if(life[(i+w),(a+z)] == (int)cell.alive || life[(i+w),(a+z)] == (int)cell.tempD)
                            ++count;
                    }
                }
                if((count < 2) || (count > 3))
                {
                    if(life[i,a] != (int)cell.dead)
                        life[i,a] = (int)cell.tempD;
                }
                else if(count == 2)
                {
                    if(life[i,a] != (int)cell.alive)
                        life[i,a] = (int)cell.tempA;
                }
                else if(count == 3)
                {
                    if(life[i,a] != (int)cell.alive)
                        life[i,a] = (int)cell.dead;
                }
            }
        }
        foreach(int x in life)
        {
            Console.Write(x+" ");
            if(y++ % life.GetLength(0) == 0)
                Console.WriteLine("");
        }
        for(int i = 0; i < life.GetLength(0)-1; i ++)//The cells are converted into the proper format
        {
            for(int a = 0; a < life.GetLength(1)-1; a ++)
            {
                int x = life[i,a];
                if(x == (int)cell.tempD)
                    x = (int)cell.dead;
                if(x == (int)cell.tempA)
                    x = (int)cell.alive;
                life[i,a] = x;
            }
        }
        Console.WriteLine("--------------------------------------------");
        foreach(int x in life)
        {
            Console.Write(x+" ");
            if(y++ % life.GetLength(0) == 0)
                Console.WriteLine("");
        }
    }
}