GEM  Gem
You are given a board with 8*8 squares. In each square, there can be either a colored gem or no gem at all. Gems with different colors are represented by different integers. It is guaranteed that there are no more than two consecutive gems with the same color either in a row or in a column.
........ ........ ........ ........ ........ ..43366. ..121556 44212335
For two neighboring (up, down, left or right, we don't consider diagonal neighbors) squares, you can exchange the gems.
........ ........ ........ ........ ........ ..43366. ..111556 44222335
You can also exchange a gem with a space. After that, if there are more than two consecutive gems with the same color in a row or in a column after exchange, these gems will be taken away simultaneously. Note that a gem could be counted both in its row and in its column; refer to the sample test cases for details.
........ ........ ........ ........ ........ ..43366. .....556 44...335
If there is no gem under a gem, the gem will fall to the square below.
........ ........ ........ ........ ........ .....66. .....556 44433335
After all the squares falling down to the floor or another gem square, repeat the procedure until there's no gem can be taken away: if there are more than two gems with the same color in a row or in a column, these gems will be taken away simultaneously. Then some gems will fall to the squares below, if there are no gems under those gems.
........ ........ ........ ........ ........ .....66. .....556 .......5 ........ ........ ........ ........ ........ ........ .....666 .....555 ........ ........ ........ ........ ........ ........ ........ ........
Given a board with 8*8 squares. This board is stable and you can't take away any gems in the original board. Your task is to determine whether all gems can be taken away by a single exchange or not.
Input
The input consists of several test cases. Each test case will be eight lines, and each line contains eight characters. If in a square there is no gem, ‘.’ is used to identify it, otherwise an integer k is used to identify the gem's color, 1<= k <=9.
There is a blank line between two consecutive test cases.
End of input is indicated by a line consisting of 0.
Output
For each test case, output a single line. If all gems can be taken away by a single exchange, output Yes; otherwise output No.
Example
Input: ........ ........ ........ ........ ........ ..43366. ..121556 44212335 ........ ........ ........ .2...... .2.22... .1.11... .2.22... .2.22... 12121212 21212121 12121212 21212121 12121212 21212121 12121212 21212121 ........ ........ ........ ........ ........ ...96... ...96... .996966. 0 Output: Yes Yes No Yes
hide comments
vincecao:
20171229 08:53:37
Be careful, gems like .:. won't be all taken away, the top middle one will be left. 

Avinash:
20110329 12:06:50
Interesting problem....!!!


abhijith reddy d:
20100404 13:49:31
Cool Problem !! 
Added by:  Fudan University Problem Setters 
Date:  20090523 
Time limit:  0.5s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: C99 ERL JSRHINO NODEJS PERL6 VB.NET 
Resource:  Fudan University Local Contest #1 