There is a famous railway station in a city called "the City of stacking". Due to the constraints of the terrain and the relationship between funds, the railway station and the only railway look like:
Now the train is coming from a direction, it is scheduled to depart from the b direction. The train has n carriages (n <=1000), and the carriages are numbered 1 to n in turn. You can assume that each compartment can be separated from the other carriages before the pit stop, or you can leave the station separately and go to the rail on the B direction. You can also assume that at any time the train station can accommodate all the carriages. But once a car comes in, it can no longer return to the A-direction rail, and once it leaves the station heading B, it cannot return to the station.
Now your task is to write a program that determines whether the train can be arranged in a specific arrangement on the rails in the B direction.
Input
The input contains multiple sets of test data. The first column of each set of test data has 1 integer n, meaning as described above. For this group of test data there are next 0 to several tests, one for each column, with n integers for each column, and the content is any permutation of 1,2,......,n. When encountering a column that contains only one 0, the end of the test data on behalf of the group.
N=0 represents the input end, please refer to sample input.
Output
For each test of each set of test data, it is possible to output any permutation of the 1,2,......,n. If possible, output Yes and output No if it is not possible.
Please also empty a column after each set of test data. Please refer to the sample Output
Sample Input
51 2 3 4 55 4 3 2 15 4 1 2 3074 5 3 7 6 2 100
Sample Output
Yesyesnoyes
6_2 Rail (UVa514)