P5953 [POI 2018] Różnorodność

Description

Given a matrix with $n$ rows and $m$ columns, for every consecutive sub-square with both side lengths equal to $k$, count the number of distinct values that appear inside it.

Input Format

The first line contains three positive integers $n, m, k$. The next $n$ lines each contain $m$ positive integers $a[i][j] (1

Output Format

Output one line with two integers $M$ and $S$. Let $f(i,j)$ denote the number of distinct values that appear in the square whose top-left corner is $(i,j)$. Then $M$ is the maximum value of $f$, and $S$ is the sum of all values of $f$.

Explanation/Hint

For $100\%$ of the testdata, $n, m \le 3000$, and $k \le \min(n, m)$. Translated by ChatGPT 5