P28179 [洛谷] Number Game II
普及+
题目描述

Problem Description

There is a game of taking numbers. Initially, a ring is given, and each edge of the ring has a non-negative integer. Among these integers, at least one is $0$. Then, a coin is placed on a node of the ring. The two players start the game from this node where the coin is placed. They take turns following these rules:

  1. Choose an edge to the left or right of the coin, and the number on this edge must be non-zero;
  2. Reduce the number on this edge to any non-negative integer (it must be reduced at least a little);
  3. Move the coin to the other end of the edge.

If it's a player's turn and both edges adjacent to the coin have a value of $0$, that player loses.

The diagram below describes a game between Alice and Bob (where the black node indicates the position of the coin).

The results of each diagram are:

  • $\text{A}$: It's Alice's turn;
  • $\text{B}$: It's Bob's turn;
  • $\text{C}$: It's Alice's turn;
  • $\text{D}$: It's Bob's turn.

In $\text{D}$, when it's Bob's turn, both edges adjacent to the coin are $0$, so Alice wins.

Your task is to determine, based on the given ring, the values on the edges, and the starting position of the coin, whether the first player has a winning strategy.

Input Format

The first line contains an integer $N$ $(N \leq 20)$, representing the number of nodes on the ring.

The second line contains $N$ numbers, each no more than $30$, representing the values on the $N$ edges in order. The starting position of the coin is between the first and last edges.

Output Format

Output a single line. If there is a winning strategy, output YES; otherwise, output NO.

Sample Input and Output

Sample Input #1

4
2 5 3 0

Sample Output #1

YES

Sample Input #2

3
0 0 0

Sample Output #2

NO
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 2 5 3 0
样例输出
YES