2414. Brain Training

单点时限: 3.0 sec

内存限制: 256 MB

Recently, a game for training our brain is popular. As we know, abilities of our brain fails with age if we don’t train our brain. One of trainings for brain is to judge whether two 2-dimension blocks exactly fit or not. In this training, we use two blocks with width n. One of them is called base block, and the other is called query block. We vertically combine the query block from upside of the base block. In this case, we should judge whether all upside edges of the base block fit to the query block without any space. If it is possible, the query block exactly fit to the base block. We can rotate a query block but mirror image is not allowed.

Let us consider the following figure I for example.

In this case, the query block exactly fit to the base block if we rotate the query block. This is the same situation as the first one in the sample input.

Let us consider the following figure II for another example.

In this case, the query block does not exactly fit to the base block. For example, even if we rotate the query block like the most right figure on the above, the query block does not “exactly fit” to the base block because there are four spaces with red color. This is the same situation as the second one in the sample input.

Your job is to write a program to judge whether a given query block exactly fit to a given base block.

输入格式

Input consists of multiple test cases. The first line of each test case contains a single positive integer n ( n <= 1,024 ), which indicates the width of blocks. The following two lines contain n positive integers, which indicate a shape of the base block and the query block respectively. The i-th integer hi (hi < 1,024 ) of each line indicates the height of i-th column. Input is terminated by a case of n = 0, and it should not be processed.

输出格式

For each test case, you should output “Yes” if the query block exactly fits to the base block. Otherwise, output “No”.

样例

Input
4
2 3 1 4
1 4 2 3
4
2 3 1 4
1 2 3 4
0
Output
Yes
No

1 人解决,4 人已尝试。

1 份提交通过,共有 14 份提交。

9.9 EMB 奖励。

创建: 15 年,5 月前.

修改: 6 年,7 月前.

最后提交: 3 年,4 月前.

来源: Winter Contest 2008

题目标签