Under construction

Still being built. Things may change

Success

Time limit2sMemory limit512 MB

Summary
Find the fewest D by D blasts needed to clear obstacles so a path of open cells exists from the top-left to the bottom-right of an N by M grid.
Level

Medium6 of 10

Topics
BFS, Shortest path, Matrix
Solved
No attempts yet

Problem

The road to success is never smooth. Obstacles fill it, and you can get stuck and stop right where you are. So you want to blow them up.

The road to success lies on an N×MN \times M grid. To succeed, start at the top-left cell, step only onto cells without obstacles that are adjacent up, down, left, or right, and reach the bottom-right cell. One blast operation can remove every obstacle inside a D×DD \times D subgrid. Blasting takes a lot of effort, so find the minimum number of blasts needed to succeed.

Input

The first line contains the number of rows NN, the number of columns MM, and the blast range DD (D≤ND \le N, M≤500M \le 500, 1≤D≤1001 \le D \le 100). Next, NN lines follow, each a string of length MM describing one row of the grid. "." is a cell without an obstacle, and "#" is a cell with an obstacle. The start and the goal cells have no obstacles.

Output

Print the minimum number of blast operations on the first line.

Hint

Examples1

  1. Example 1

    Input
    8 9 3
    .########
    ##.....##
    ######.##
    ####...##
    ####.####
    #########
    ####.####
    ########.
    
    Expected output
    2