COBOOOL Sugoroku

You are building a board game "COBOOOL Sugoroku" for smart phones. The "COBOOOL Sugoroku" have "n" lined cells from 1st cell to n-th cell. Each cell holds one integer value written.

First, you are at the first cell. You'll spin a wheel, and you'll see one number on the wheel. Then you'll move forward (to the n-th cell) by the number on the wheel.

Next, if the value of the cell is a positive number, you'll move forward (to the n-th cell) by the value of the cell. If the value of the cell is a negative number, you'll move backward (to the first cell). And again, you'll repeatedly see the value of the current cell, and move by the value. If there is no cell on the position where you'll move to, you'll stop moving and the game ends.

The following figure shows one example values of cells with n = 8:

On the cells, you'll move like:

If the wheel shows 7, you'll move: 1 -> 8, and the game ends.
If the wheel shows 3, you'll move: 1 -> 4 -> 2 -> 8, and the game ends.
If the wheel shows 4, you'll move: 1 -> 5, and the game ends.
If the wheel shows 2, you'll move: 1 -> 3 -> 1, and the game ends.
If the wheel shows 5, you'll move: 1 -> 6 -> 7 -> 6 , and the game ends.
If the wheel shows 10, you won't move, and the game ends.
The following figure shows the moves:

You are given the values of cells and the numbers wheel shows. Write a program that checks whether you will reach the n-th cells and output "Yes" or "No".
ミッション1

For each game, if you can reach the n-th cell, output "Yes". Otherwise output "No".

Input

Input is given in the following format:
n
t_1 t_2 ... t_n
m
d_1
d_2
...
d_m
"n" is the number of cells. "t_i" is an integer value written on the "i"-th cell. "m" is the number of the game. "d_j" is a positive integer value on the wheel at the "j"-th game.

Constraints

All test cases have the following constraints:
2 ≦ n ≦ 100
t_1 = t_n = 0
-100 ≦ t_i ≦ 100 (2 ≦ i ≦ n-1)
1 ≦ m ≦ 100
1 ≦ d_j ≦ 100 (1 ≦ j ≦ m)


Output

For each game, if you can reach the n-th cell, output "Yes". Otherwise output "No".
Add a newline character at the end of the output. Do not include any unnecessary characters or empty lines.
Input example 1
8
0 6 -2 -2 0 1 -1 0
6
7
3
4
2
5
10
Output example 1
Yes
Yes
No
No
No
No
Input example 2
5
0 1 0 1 0
4
1
1
2
3
Output example 2
No
No
No
Yes

Answer

Please enter and submit the code that solves the problem above using the text box below.
You can use the following languages: Java, PHP, Ruby, Perl, Python, C, C#, and C++.

To find out about methods for reading values from standard input, please refer to the sample codes shown in the pages below:

Let's take the challenge!!Choose your best programming language and write some code!

Select language

Select your best programming language!

Code execution result

Nickname (Required)
You can use letters and numbers. This nickname may be displayed on our site when we publish your codes as sample solutions, or when we announce the prize winners.
email (Required)
Your registered e-mail address will not be used outside of Paiza Online Hackathon.
Once you submit your code, we will e-mail your results page.

ページの先頭へ戻る