Under construction

Still being built. Things may change

Bees

Interview

Time limit1sMemory limit512 MB

Summary
Given an n by m hexagonal honeycomb's initial honey pattern, apply the rule that each cell fills next day exactly when an odd number of its neighbors were filled, and print the state after k days.
Level

Medium6 of 10

Topics
Bit manipulation, Simulation, Matrix, Math
Solved
No attempts yet

Problem

Bees store honey in a honeycomb every day. The honeycomb is a grid of regular hexagonal cells arranged in rows and columns. During the night the larvae eat all of the honey, so the honeycomb is completely empty when a day begins. The bees do not pick cells at random. Which cells receive honey is decided by which cells held honey on the previous day. A cell holds honey exactly when the number of its neighboring cells that held honey on the previous day is odd, and it stays empty otherwise. A cell is not its own neighbor.

Two adjacent rows are offset by half a cell. The first cell of row 1 sits above and to the left of the first cell of row 2. The neighbors of the cell in row ii and column jj are therefore:

  • (i,j−1)(i, j-1) and (i,j+1)(i, j+1) in the same row
  • (i−1,j−1)(i-1, j-1), (i−1,j)(i-1, j), (i+1,j−1)(i+1, j-1), (i+1,j)(i+1, j) when ii is odd
  • (i−1,j)(i-1, j), (i−1,j+1)(i-1, j+1), (i+1,j)(i+1, j), (i+1,j+1)(i+1, j+1) when ii is even

Positions outside the honeycomb are not neighbors.

The picture shows the honeycomb of the first example input.

Input

The first line contains three natural numbers nn, mm and kk separated by spaces (2≤n,m≤102 \le n, m \le 10, 1≤k≤263−11 \le k \le 2^{63} - 1). Here nn is the number of rows of the honeycomb, mm is the number of columns, and kk is the number of days that pass.

Each of the next nn lines contains mm characters. A '#' means the cell holds honey at the start, and a '.' means it does not.

Output

Print the state of the honeycomb after kk days in nn lines, in the same format as the input.

Examples2

  1. Example 1

    Input
    4 4 3
    ....
    ....
    ..#.
    ....
    
    Expected output
    #...
    .###
    .#..
    #...
    
  2. Example 2

    Input
    3 10 8
    #.##..#...
    #.##.#....
    ...#..#...
    
    Expected output
    #..#...##.
    .#.#...###
    #..##.##..