#C8855. Distinct Sub-Grids Count

    ID: 52883 Type: Default 1000ms 256MiB

Distinct Sub-Grids Count

Distinct Sub-Grids Count

Given a garden represented as an $$n \times n$$ grid and an integer $$m$$, your task is to count the number of distinct square sub-grids of size $$m \times m$$ that can be extracted from the garden. A sub-grid is defined as a contiguous block of cells in the grid. Two sub-grids are considered distinct if there is at least one position in which their corresponding cell values differ.

Note: The sub-grids are obtained by sliding a $$m \times m$$ window over the $$n \times n$$ grid, and there are exactly $$(n-m+1)^2$$ such windows if $$n \ge m$$.

inputFormat

The input is read from standard input (stdin). The first line contains two integers $$n$$ and $$m$$, representing the size of the garden and the side length of the sub-grid respectively. This is followed by $$n$$ lines, each containing $$n$$ space-separated integers representing the cells of the garden.

outputFormat

Output a single integer to standard output (stdout): the number of distinct $$m \times m$$ sub-grids in the garden.## sample

4 2
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
9