#K12996. Checkerboard Pattern Generation

    ID: 23814 Type: Default 1000ms 256MiB

Checkerboard Pattern Generation

Checkerboard Pattern Generation

Given two integers n and m, generate an n x m checkerboard grid where the value of the cell in row i and column j is determined by the formula: \( (i+j) \mod 2 \). This ensures that no two adjacent cells (horizontally or vertically) have the same value.

The top-left cell is indexed as (0, 0) and its value is \(0\). Your task is to print the generated grid to standard output where each row is on a new line and values in the same row are separated by a space.

inputFormat

The input is read from standard input (stdin) and consists of two space-separated positive integers: n (the number of rows) and m (the number of columns).

Example:

3 3

outputFormat

The output should be printed to standard output (stdout). It consists of n lines, each containing m integers. The integers in each line are separated by a space, representing a row in the checkerboard grid.

For the sample input above, the expected output is:

0 1 0
1 0 1
0 1 0
## sample
1 1
0

</p>