Hell on the Markets

Time limit2sMemory limit128 MB

Summary
Decide if signs (+1/-1) can be assigned to a given sequence with 1<=a_i<=i so the signed sum is zero.
Level

Medium6 of 10

Topics
Greedy, Math
Solved
No attempts yet

Problem

During a financial crisis many institutions became insolvent and were either liquidated or absorbed by larger ones, so that by the end only two banks were still operating. The financial markets, closed throughout the crisis, are now being reopened gradually by the regulators. To curb speculation and ramp up trading slowly, at first only a single financial instrument may be traded, and during the ii-th minute of operation the traded volume is limited to ii contracts.

The two banks agree in advance on the trading volume for every minute of this first session. During the ii-th minute (1≤i≤n1 \le i \le n) exactly aia_i contracts change hands (1≤ai≤i1 \le a_i \le i): one bank buys them and the other one sells them. An outside observer sees only the volume aia_i. Neither bank wants to carry any position once the session ends. Let bi=1b_i = 1 if the first bank is the buyer during the ii-th minute and bi=−1b_i = -1 if it is the seller (i.e. the second bank buys). Then both banks finish with no position exactly when

∑i=1naibi=0.\sum_{i=1}^{n} a_i b_i = 0.

Given the agreed volumes a1,…,ana_1, \ldots, a_n, determine whether a buyer and a seller can be assigned to every minute so that both banks end the session with no position.

Input

The first line contains a single integer nn (1≤n≤100 0001 \le n \le 100\,000).

The second line contains nn integers a1,…,ana_1, \ldots, a_n (1≤ai≤i1 \le a_i \le i).

Output

Print Yes if buyers and sellers can be assigned to every minute so that ∑i=1naibi=0\sum_{i=1}^{n} a_i b_i = 0, and No otherwise.

Examples3

  1. Example 1

    Input
    4
    1 2 3 4
    
    Expected output
    Yes
    
  2. Example 2

    Input
    4
    1 2 3 3
    
    Expected output
    No
    
  3. Example 3

    Input
    1
    1
    
    Expected output
    No