#ARC138B. [ARC138B] 01 Generation

[ARC138B] 01 Generation

Score : 500500 points

Problem Statement

Snuke is about to make an integer sequence of length NN consisting of 00 and 11. He starts with an empty sequence xx and does the following two kinds of operations NN times in total, in any order he likes.

  • Operation A: Flip every element of xx, that is, convert each 00 to 11 and vice versa. Then, add 00 to the beginning of xx.
  • Operation B: Add 00 to the end of xx.

You are given an integer sequence of length NN consisting of 00 and 11: A=(A1,A2,,AN)A=(A_1,A_2,\cdots,A_N). Determine whether it is possible to make xx equal to AA.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 0Ai10 \leq A_i \leq 1
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \cdots ANA_N

Output

If it is possible to make xx equal to AA, print Yes; otherwise, print No.

4
0 1 1 0
Yes

Snuke can do the following.

  • Start with x=()x=()
  • Do operation A, making x=(0)x=(0).
  • Do operation B, making x=(0,0)x=(0,0).
  • Do operation A, making x=(0,1,1)x=(0,1,1).
  • Do operation B, making x=(0,1,1,0)x=(0,1,1,0).
4
1 0 0 0
No
4
0 0 0 1
No