C - Electronic Sugoroku Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 333 点

問題文

高橋君は、円環状の盤面を持つ電子すごろくで遊んでいます。

盤面には円周上に N 個のマスが並んでおり、時計回りに順に 0 から N - 1 までの番号が付けられています。

最初、マス 0 にコマが 1 つ置かれています。

すごろろくの本体には M 種類のボタンがあり、i 番目のボタンを押すと、コマは現在いるマスから時計回りに A_i マス進みます。

すなわち、現在コマがマス x にあるとき、i 番目のボタンを押すと、コマはマス (x + A_i) \bmod N に移動します。

高橋君は、これらのボタンを任意の順序で好きな回数(0 回でもよい)押すことができます。

高橋君がコマをマス G に移動させることができるかどうかを判定してください。

制約

  • 2 \leq N \leq 10^9
  • 1 \leq M \leq 10^6
  • 0 \leq G \leq N - 1
  • 1 \leq A_i \leq 10^9(1 \leq i \leq M)
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N M G
A_1 A_2 ... A_M
  • 1 行目には、マスの個数を表す N、ボタンの種類数を表す M、目標とするマスの番号を表す G が、スペース区切りで与えられる。
  • 2 行目には、各ボタンで進むマス数を表す M 個の整数 A_1, A_2, \dots, A_M が、スペース区切りで与えられる。

出力

コマをマス G に移動させることができる場合は Yes を、移動させることができない場合は No を 1 行に出力せよ。


入力例 1

6 2 4
2 3

出力例 1

Yes

入力例 2

6 2 3
2 4

出力例 2

No

入力例 3

100 4 75
10 20 35 45

出力例 3

Yes

入力例 4

1000000000 10 582491200
123456700 234567800 345678900 456789100 567891200 678912300 789123400 891234500 912345600 987654300

出力例 4

Yes

入力例 5

2 1 1
2

出力例 5

No

Score : 333 pts

Problem Statement

Takahashi is playing an electronic sugoroku game with a circular board.

On the board, N squares are arranged in a circle, numbered 0 through N - 1 in clockwise order.

Initially, a piece is placed on square 0.

The game console has M types of buttons. Pressing the i-th button moves the piece A_i squares clockwise from its current square.

That is, if the piece is currently at square x, pressing the i-th button moves it to square (x + A_i) \bmod N.

Takahashi can press these buttons any number of times (possibly zero) in any order.

Determine whether he can move the piece to square G.

Constraints

  • 2 \leq N \leq 10^9
  • 1 \leq M \leq 10^6
  • 0 \leq G \leq N - 1
  • 1 \leq A_i \leq 10^9 (1 \leq i \leq M)
  • All input values are integers.

Input

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

N M G
A_1 A_2 ... A_M
  • The first line contains N, the number of squares, M, the number of button types, and G, the target square number, separated by spaces.
  • The second line contains M integers A_1, A_2, \dots, A_M, representing the number of squares advanced by each button, separated by spaces.

Output

If it is possible to move the piece to square G, print Yes in a single line; otherwise, print No.


Sample Input 1

6 2 4
2 3

Sample Output 1

Yes

Sample Input 2

6 2 3
2 4

Sample Output 2

No

Sample Input 3

100 4 75
10 20 35 45

Sample Output 3

Yes

Sample Input 4

1000000000 10 582491200
123456700 234567800 345678900 456789100 567891200 678912300 789123400 891234500 912345600 987654300

Sample Output 4

Yes

Sample Input 5

2 1 1
2

Sample Output 5

No