
54  ZJPCPC Sunny Cup 2006, Online Round  1001
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 01 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
Sample Output Yes No No Author: XU, Chuan 