LogiQuest

310. Game of Life — One Step

MediumSimulation

Apply one step of Conway's Game of Life (8 neighbours; a live cell survives with 2 or 3 live neighbours; a dead cell becomes live with exactly 3). Print the new grid.

Input format

Line 1: r c Next r lines: c values (0/1)

Output format

The next grid.

Example 1

Input

4 3
0 1 0
0 0 1
1 1 1
0 0 0

Output

0 0 0
1 0 1
0 1 1
0 1 0

Example 2

Input

2 2
1 1
1 0

Output

1 1
1 1

Constraints

1 ≤ r, c ≤ 100

Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.

Loading the MyLoginn IDE…