#P5457. Eternal Life: Immortal Configurations in the Game of Life

    ID: 18689 Type: Default 1000ms 256MiB

Eternal Life: Immortal Configurations in the Game of Life

Eternal Life: Immortal Configurations in the Game of Life

The Game of Life is a classic zero-player game played on an \(n \times m\) grid. Each cell is either alive or dead initially. At the beginning of each day, the following rules are applied simultaneously to every cell:

  • If a cell is alive and it has exactly 2 or 3 live neighbors (considering up to 8 adjacent cells, fewer on the boundary), then it remains alive on the next day.
  • If a cell is dead but has exactly 3 live neighbors, a new life is born in that cell.
  • In all other cases, a cell dies or remains dead.

Once a day comes when all the cells on the board are dead, they will remain so forever, and we say that "life has gone extinct."

Now, given that each cell's initial state is chosen independently by Fifi, Niu Niu wants to know how many different initial configurations exist under which life never goes extinct.

Note: All formulas are written in \(\LaTeX\) format.

inputFormat

The input consists of a single line with two integers \(n\) and \(m\) (1 ≤ n, m ≤ small values) representing the dimensions of the grid.

outputFormat

Output one integer, the number of initial configurations for which life never goes extinct.

sample

1 1
0