atcoder#ABC289D. [ABC289D] Step Up Robot

[ABC289D] Step Up Robot

Score : 400400 points

Problem Statement

There is a staircase with infinite steps. The foot of the stairs is the 00-th step, the next step is the 11-st step, the next is the 22-nd, and so on.

There is a stair-climbing robot on the 00-th step. The robot can climb up A1,A2,A _ 1,A _ 2,\ldots, or ANA _ N steps at a time. In other words, when the robot is on the ii-th step, it can step onto one of the (i+A1)(i+A _ 1)-th step, (i+A2)(i+A _ 2)-th step, \ldots, and (i+AN)(i+A _ N)-th step, but not onto the others in a single step. The robot cannot descend the stairs, either.

There are traps on the B1B _ 1-th, B2B _ 2-th, \ldots, and BMB _ M-th steps. Once the robot steps onto a step with a trap, it cannot move anymore.

The robot wants to step onto the XX-th step. Determine whether it is possible to do so.

Constraints

  • 1N101\leq N\leq10
  • 1A1<A2<<AN1051\leq A _ 1\lt A _ 2\lt\cdots\lt A _ N\leq10^5
  • 1M1051\leq M\leq10^5
  • $1\leq B _ 1\lt B _ 2\lt\cdots\lt B _ M\lt X\leq10^5$
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

A1A _ 1 A2A _ 2 \ldots ANA _ N

MM

B1B _ 1 B2B _ 2 \ldots BMB _ M

XX

Output

In a single line, print Yes if the robot can step onto the XX-th step, and No otherwise.

3
3 4 5
4
4 5 6 8
15
Yes

For example, the robot can reach the 1515-th step as follows.

  • Climb up 33 steps. The robot is now on the 33-rd step.
  • Climb up 44 steps. The robot is now on the 77-th step.
  • Climb up 55 steps. The robot is now on the 1212-th step.
  • Climb up 33 steps. The robot is now on the 1515-th step.
4
2 3 4 5
4
3 4 5 6
8
No

No matter how the robot moves, it cannot step onto the 88-th step.

4
2 5 7 8
5
2 9 10 11 19
20
Yes