#include <iostream>
#include <limits>
#include <vector>
constexpr std::size_t N = 208, M = 206;
using game_map_t = bool[N][M];
using set_cells_t = std::vector<std::pair<std::size_t, std::size_t>>;
void set(const set_cells_t &input, game_map_t &map) {
for (const auto &[i, j] : input)
map[i][j] = true;
}
int count_live_neighbour_cell(game_map_t &map, int r, int c);
int main() {
game_map_t map = {};
set_cells_t set_cells {
{ 1, 2 },
{ 2, 3 },
{ 3, 1 },
{ 3, 2 },
{ 3, 3 },
{ 205, 204 },
{ 206, 204 },
{ 207, 204 }
};
int alive_count = set_cells.size();
set(set_cells, map);
for (int k = 0; k < std::numeric_limits<int>::max(); k++) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
const int alive_neighbours_count = count_live_neighbour_cell(map, i, j);
if (!map[i][j] && alive_neighbours_count == 3) {
map[i][j] = true;
alive_count++;
} else if (map[i][j] && alive_neighbours_count != 2 && alive_neighbours_count != 3) {
map[i][j] = false;
alive_count--;
}
if (alive_count == 0) {
std::cout << k + 1;
return 0;
}
}
}
}
}
int count_live_neighbour_cell(game_map_t &map, int r, int c) {
int i, j, count = 0;
for (i = r - 1; i <= r + 1; i++) {
for (j = c - 1; j <= c + 1; j++) {
if ((i == r && j == c) || (i < 0 || j < 0)
|| (i >= N || j >= M)) {
continue;
}
if (map[i][j] == 1) {
count++;
}
}
}
return count;
}