407642: GYM102862 F Cell Borders

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Cell Borderstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

You are given a strip of paper that consists of $$$n$$$ consecutive square cells. The cells are numbered $$$1$$$ to $$$n$$$ from left to right. Each cell has an integer written in it, which is either $$$0$$$, $$$1$$$, or $$$2$$$. Denote the integer in the $$$i$$$-th cell by $$$a_i$$$. You can color black any number of the left or right borders of these cells (there are $$$n+1$$$ such borders in total). Is it possible to color the borders in such a way that for each cell $$$i$$$, the number of its borders that is colored is equal to $$$a_i$$$?

For example, if you are given the numbers $$$1~2~1~0~1~2$$$, then it is possible to color the borders as follows:

Input

The first line of input contains a single integer $$$n$$$, the number of cells ($$$1 \leq n \leq 10^5$$$). The next line contains $$$n$$$ integers $$$a_1$$$, $$$\ldots$$$, $$$a_n$$$ ($$$0 \leq a_i \leq 2$$$), the numbers of colored borders the cells $$$1$$$, $$$\ldots$$$, $$$n$$$ should have.

Output

If it is possible, output "Yes" in a single line, otherwise output "No".

ExamplesInput
6
1 2 1 0 1 2
Output
Yes
Input
2
2 0
Output
No

加入题单

算法标签: