#K47367. Taco Grid Scoring Challenge

    ID: 28183 Type: Default 1000ms 256MiB

Taco Grid Scoring Challenge

Taco Grid Scoring Challenge

You are given a 2D grid of dimensions \(n \times m\) where each cell contains an integer value from \(\{0, 1, 2\}\). A \(3 \times 3\) subgrid is considered to form a perfect pattern if all its 9 cells contain the same non-zero value. In such a subgrid, if all the cells are \(1\) then it contributes one point to Alice, and if all the cells are \(2\) then it contributes one point to Bob. Your task is to compute the final scores for Alice and Bob by counting the number of perfect \(3 \times 3\) subgrids for each player.

Note: The subgrids are taken from contiguous blocks in the grid. Only consider subgrids fully within the grid boundaries.

For example, consider a grid of size \(4 \times 4\):

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

There is exactly one \(3 \times 3\) subgrid (top-left block) where all entries are \(1\) so the output should be 1 0 (Alice then Bob).

inputFormat

The first line of input contains two integers \(n\) and \(m\), representing the number of rows and columns of the grid respectively.

This is followed by \(n\) lines, each containing \(m\) integers separated by spaces. Each integer is in the set \(\{0, 1, 2\}\), representing the state of each cell in the grid.

Input is provided via standard input (stdin).

outputFormat

Output two integers separated by a space: the final score for Alice and the final score for Bob, respectively. The output should be printed to standard output (stdout).

For example, an output of 1 0 means Alice scores 1 and Bob scores 0.

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