cswork / OAOpen practice workspace

MicrosoftOA #8

Find Suitable Locations

Estimated MediumJudge-ready

Topics (AI-labelled)Grid SearchBits & Math

In the grid, 0 is an empty lot and 1 is a house. A store can be built on an empty lot whose Manhattan distance to every house is at most K. Find the number of suitable empty lots; if there are no houses, every empty lot qualifies.

Input

This site's input: the first line contains R C K (1≤R,C≤500, 0≤K≤1000), followed by R lines each with C values 0 or 1.

Output

Output a single integer, the answer.

Example 1

Input:

2 2 1
1 0
0 0

Output:

2

Example 2

Input:

1 1 0
0

Output:

1

Example 3

Input:

1 1 2
1

Output:

0

Example notes

Example 1: only the two empty lots to the right of and below the house are at distance 1; the bottom-right corner is at distance 2 and does not qualify, so the answer is 2.

Example 2: there are no houses, and the only empty lot satisfies every constraint, so the answer is 1.

Example 3: there are only houses and no empty lots, so the answer is 0.

Editorial

Loading solution…