2319.The Last Fight Between Human and AI

Time Limit: 1s Memory Limit: 256MB

100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet.

The following game was chosen for the fights: initially there is a polynomial
P(x)=anxn+an-1xn-1+...+a1x+a0, with yet undefined coefficients and the integer k. Players alternate their turns. At each turn, a player pick some index j, such that coefficient aj that stay near xj is not determined yet and sets it to any value (integer or real, positive or negative, 0 is also allowed). Computer moves first. The human will be declared the winner if and only if the resulting polynomial will be divisible by Q(x)=x-k.
Polynomial P(x) is said to be divisible by polynomial Q(x) if there exists a representation P(x)=B(x)Q(x), where B(x) is also some polynomial.

Some moves have been made already and now you wonder, is it true that human can guarantee the victory if he plays optimally?

Input Format(From the terminal/stdin)

The first line of the input contains two integers n and k (1 \le n \le 100000,|k| \le 10000)- the size of the polynomial and the integer k.

The i-th of the following n+1 lines contain character '?' if the coefficient near xi-1 is yet undefined or the integer value ai, if the coefficient is already known (-10000 \le ai \le 10000). Each of integers ai (and even an) may be equal to 0.

Please note, that it's not guaranteed that you are given the position of the game where it's computer's turn to move.

Output Format(To the terminal/stdout)

Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.

Sample Input 1

Copy
1 2
-1
?
 · \n
  \n
 \n

Sample Output 1

Copy
Yes
   \n

Sample Input 2

Copy
2 100
-10000
0
1
 ·   \n
      \n
 \n
 \n

Sample Output 2

Copy
Yes
   \n

Sample Input 3

Copy
4 5
?
1
?
1
?
 · \n
 \n
 \n
 \n
 \n
 \n

Sample Output 3

Copy
No
  \n

Hints

In the first sample, computer set a0 to -1 on the first move, so if human can set coefficient a1 to 0.5 and win.

In the second sample, all coefficients are already set and the resulting polynomial is divisible by x-100, so the human has won.

Submit

请先 登录

© 2025 FAQs