Welcome to ZOJ
Information
Problems
Runs
Statistics
Ranklist
Clarification
54 - ZJPCPC Sunny Cup 2006, Online Round - 1001
Toy Bricks

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Tom has a lot of toy bricks. All of them are 1*1*L cuboids. This day, Tom gets a picture on which is a beautiful house. "Great, I'll build this house with my toy bricks!" Tom shouts excitedly. However, he does not know it is possible to build this house. So he asks for your help.

The house model designed by Tom can be viewed as a N*N*N cube losing some of its blocks. However, his toy bricks are limited and his design may not be stable. In other words, the house may not be able to stand on ground stably. It is your job to help him to find out these defects.

You may assume that all toy bricks can glue to each other tightly.

Input

The input consists of multiple test cases. Each test case starts with a positive integer N(<=5). Following is the description of the house model. The description consists of N 0-1 matrixes, which represent N layers of the cube from bottom to top respectively. Each matrix is N*N. If an element is 1, then there is a block, otherwise there is not. After the house model, there is a single line containing several positive integers representing Tom's toy bricks. Each integer is the length of corresponding toy brick.

Output

For each test case, output "Yes" if the house can be built, "No" otherwise.

Sample Input

3
101
000
101
101
000
101
111
111
111
1 1 1 2 2 2 3 3 3
3
100
000
000
110
010
000
100
010
000
1 1 1 1
/* not stable */
2
11
11
10
01
1 1 1
/* not enough bricks */

Sample Output

Yes
No
No

Author: XU, Chuan


Submit    Status