Олимпиадный тренинг

Задача 21839. life


Задача

Темы:

Dmitry works as a biologist and recently discovered a new type of bacteria that live in unusual conditions — in tables of 10 by 10 cells. Tabular bacteria consist of several living cells. Dmitry calculated that the bacterium exists according to the following rules:

  • If some bacterial cell has two or three living neighbors, then at the next moment in time it remains alive.
  • If some bacterial cell has less than two living neighbors, then at the next moment of time it dies of loneliness and becomes an empty cell.
  • If some bacterial cell has more than three living neighbors, then at the next moment of time it dies from overpopulation and becomes an empty cell.
  • If an empty table cell has exactly three live cell neighbors, then at the next moment of time a live cell is born in it.
Cell neighbors are the nearest cells horizontally (left and right), vertically (bottom and top), as well as four diagonals. Thus, a cell can have a maximum of 8 neighbors.

 

Dmitry needs a program that, based on the current shape of a bacterium, predicts how it will look at the next moment in time. Help him with this.

Input data format

The input consists of 10 lines. Each line contains 10 characters. The character '#' means that the corresponding cell contains a living bacterial cell, and the character '.' means the cell is empty.

Output format

It is necessary to output a table 10 by 10 — image of a bacterium at the next point in time.

Input:

..........
..........
..........
.....#....
......#...
....###...
..........
..........
..........
..........

Conclusion:
..........
..........
..........
..........
....#.#...
.....##...
.....#....
..........
..........
..........

Input:
..........
..........
....#.....
...###....
..#.#.#...
.###.###..
..#.#.#...
...###....
....#.....
..........

Conclusion:
..........
..........
...###....
..........
.#.....#..
.#.....#..
.#.....#..
..........
...###....
..........