Under construction

Still being built. Things may change

Hypothermia

Time limit2sMemory limit1024 MB

Summary
Given an N by M grid of normal and hypothermic people, count those who stay at normal temperature forever when at most K can fall ill each night.
Level

Medium7 of 10

Topics
Graph, BFS, Matrix
Solved
No attempts yet

Problem

NN rows by MM columns of people are gathered in a rectangle. At the start, each person is either at normal body temperature or suffering from hypothermia, and their states change as days and nights pass. During the day, the warmth gives hypothermia patients a chance to recover. If a person has two or more orthogonally adjacent people at normal body temperature, that person shares their warmth and recovers from hypothermia to normal body temperature. After a person recovers, that person can help recover other adjacent people in the same way, and this recovery process can be repeated many times during the day. At night, it is cold, so people at normal body temperature can fall into hypothermia. However, at most KK people newly fall into hypothermia during a single night. Assume days and nights keep repeating, so people keep falling into hypothermia or recovering. Some people may never recover from hypothermia permanently. Other people have enough normal-temperature neighbors nearby that they can still recover during the day, no matter which KK people fall ill each night. Given the state of the people on the first day, find the number of people who, after days and nights have repeated many times, still keep normal body temperature during the day in the worst case.

Input

The first line contains three integers NN, MM, and KK, separated by spaces: the number of rows, the number of columns, and the maximum number of people who can newly fall into hypothermia at night. (1≤N,M≤2 0001\leq N,M\leq 2\,000; 1≤K≤N×M1\leq K\leq N\times M)

From the second line, NN lines follow, each a string of length MM. The jj-th character of the ii-th line gives the initial state of the person in row ii, column jj. O means normal body temperature, and . means hypothermia. All characters are guaranteed to be O or ..

Output

Print the number of people who, even after days and nights repeat indefinitely, keep normal body temperature during the day.

Examples2

  1. Example 1

    Input
    5 7 1
    O......
    ..O....
    .O.....
    .O...O.
    ....O.O
    
    Expected output
    35
    
  2. Example 2

    Input
    5 7 2
    O.....O
    ..O....
    .O....O
    .O...O.
    ......O
    
    Expected output
    12