#P5121. Mooyo Mooyo
Mooyo Mooyo
Mooyo Mooyo
Farmer John's cows love to play a video game called Mooyo Mooyo, a variant of the popular game Puyo Puyo. The game is played on a board of height \(N\) (with \(1\le N\le 100\)) and width 10. Each cell in the board is either empty (denoted by 0) or contains a hay bale of one of nine colors (denoted by the digits 1 to 9). Due to gravity, hay bales fall down so that there is never an empty cell with a hay bale below it.
A move in Mooyo Mooyo is defined as follows. At any moment, any connected region (cells adjacent vertically or horizontally) consisting of at least \(K\) cells (\(K\) is given) of the same nonzero digit will disappear, i.e. all those cells are set to 0. If multiple such regions exist simultaneously, they all disappear at once. After that, gravity is applied so that any hay bale falls as far down as possible. New regions that qualify (size at least \(K\)) may then be formed. The process is repeated until no region of size at least \(K\) exists.
Given the initial state of a Mooyo Mooyo board, simulate the game and output the final board state.
inputFormat
The first line contains two integers \(N\) and \(K\). \(N\) is the number of rows and \(K\) is the minimum size of a region to be removed.
Each of the next \(N\) lines contains a string of 10 digits representing a row of the board, from top to bottom.
outputFormat
Output the final state of the board in \(N\) lines, each line containing 10 digits.
sample
6 3
0000000000
0000000300
0054000300
1054502230
2211122220
1111111223
0000000000
0000000000
0000000000
0000000000
1054000000
2254500000
</p>