3777.Table with Letters - 2

Time Limit: 1s Memory Limit: 256MB

Vasya has recently started to learn English. Now he needs to remember how to write English letters. He isn't sure about some of them, so he decided to train a little.

He found a sheet of squared paper and began writing arbitrary English letters there. In the end Vasya wrote n lines containing m characters each. Thus, he got a rectangular n \times m table, each cell of the table contained some English letter. Let's number the table rows from top to bottom with integers from 1 to n, and columns - from left to right with integers from 1 to m.

After that Vasya looked at the resulting rectangular table and wondered, how many subtables are there, that matches both following conditions:
the subtable contains at most k cells with "a" letter; all letters, located in all four corner cells of the subtable, are equal.
Formally, a subtable's definition is as follows. It is defined by four integers x1,y1,x2,y2 such that 1 \le x1 \lt x2 \le n, 1 \le y1 \lt y2 \le m. Then the subtable contains all such cells (x,y) (x is the row number, y is the column number), for which the following inequality holds x1 \le x \le x2,y1 \le y \le y2. The corner cells of the table are cells (x1,y1), (x1,y2), (x2,y1), (x2,y2).

Vasya is already too tired after he's been writing letters to a piece of paper. That's why he asks you to count the value he is interested in.

Input Format(From the terminal/stdin)

The first line contains three integers n,m,k (2 \le n,m \le 400;0 \le k \le n \cdot m).

Next n lines contain m characters each - the given table. Each character of the table is a lowercase English letter.

Output Format(To the terminal/stdout)

Print a single integer - the number of required subtables.

Sample Input 1

Copy
3 4 4
aabb
baab
baab
 · · \n
    \n
    \n
    \n

Sample Output 1

Copy
2
 \n

Sample Input 2

Copy
4 5 1
ababa
ccaca
ccacb
cbabc
 · · \n
     \n
     \n
     \n
     \n

Sample Output 2

Copy
1
 \n

Hints

There are two suitable subtables in the first sample: the first one's upper left corner is cell (2,2) and lower right corner is cell (3,3), the second one's upper left corner is cell (2,1) and lower right corner is cell (3,4).

Submit

请先 登录

© 2025 FAQs