#include <vector>
#include <iostream>

struct Point
{
	int x;
	int y;
	bool isAlive;
};
std::vector<Point> gameBoard;
std::vector<Point> bufferGirlNextDoor;
std::vector<Point> bufferNewBorn;

void checkNumForBorn(Point);
void checkNumForDead(Point&);
void checkGirlNextDoor(Point);
void createGameBoard()
{
	gameBoard.push_back(Point{ 0,0,true });
	gameBoard.push_back(Point{ 1,0,true });
	gameBoard.push_back(Point{ 2,0,true });
}

void mainLoop()
{
	createGameBoard();
	while (true)
	{
		bufferNewBorn.clear();
		for each (Point p in gameBoard)
		{
			checkGirlNextDoor(p);
			checkNumForBorn(Point{ p.x-1, p.y, true });
			checkNumForBorn(Point{ p.x-1, p.y+1, true });
			checkNumForBorn(Point{ p.x, p.y+1, true });
			checkNumForBorn(Point{ p.x+1, p.y+1, true });
			checkNumForBorn(Point{ p.x+1, p.y, true });
			checkNumForBorn(Point{ p.x+1, p.y-1, true });
			checkNumForBorn(Point{ p.x, p.y-1, true });
			checkNumForBorn(Point{ p.x-1, p.y-1, true });
			checkNumForDead(p);
		}
		for each (Point p in gameBoard)
		{
			if (p.isAlive) bufferNewBorn.push_back(p);
		}
		gameBoard.clear();
		gameBoard = bufferNewBorn;
		std::cout << gameBoard.size() << std::endl;
	}
}
void checkNumForBorn(Point currentPoint)
{
	int num = 0;
	bool isGirlNextDoor = false;
	for each (Point p in bufferGirlNextDoor)
	{
		if (p.x == currentPoint.x && p.y == currentPoint.y)
		{
			isGirlNextDoor = true;
			break;
		}
	}
	if (!isGirlNextDoor)
	{
		for each (Point p in bufferGirlNextDoor)
		{
			if (p.x > currentPoint.x - 2 && p.x < currentPoint.x + 2 && p.y > currentPoint.y - 2 && p.y < currentPoint.y + 2)
				++num;
			//добавить после тестов if (num > 2) break;
		}
	}
	if (num > 2) bufferNewBorn.push_back(currentPoint);
}
void checkNumForDead(Point &currentPoint)
{
	int num = 0;
	for each (Point p in bufferGirlNextDoor)
	{
		if (p.x > currentPoint.x - 2 && p.x < currentPoint.x + 2 && p.y > currentPoint.y - 2 && p.y < currentPoint.y + 2 && p.x != currentPoint.x && p.y != currentPoint.y)
			++num;
		//добавить после тестов if (num > 3) break;
	}
	if (num < 2 || num > 3) currentPoint.isAlive = false;
}
void checkGirlNextDoor(Point currentPoint)
{
	bufferGirlNextDoor.clear();
	for each(Point p in gameBoard)
	{
		if (p.x > currentPoint.x - 3 && p.x < currentPoint.x + 3 && p.y > currentPoint.y - 3 && p.y < currentPoint.y + 3 && p.x != currentPoint.x && p.y != currentPoint.y)
			bufferGirlNextDoor.push_back(p);
	}
}