Shift

No attempts yetTime limit1sMemory limit128 MB

Problem

Byteasar bought his son Bytie a set of blocks numbered from 11 to nn and placed them in a row in some order. Bytie wants to rearrange the blocks so that their numbers read in increasing order, from the smallest to the largest.

The only moves Bytie may use are:

  • move a: take the last block and put it at the very front;
  • move b: take the third block (the block currently in position 33) and put it at the very front.

Move b can only be used when there are at least 33 blocks. Given the initial arrangement, decide whether the blocks can be sorted into increasing order using any sequence of these two moves.

Input

The first line contains a single integer nn (1n20001 \le n \le 2000).

The second line contains nn distinct integers between 11 and nn, separated by single spaces, giving the initial left-to-right arrangement of the blocks.

Output

Print YES if the blocks can be sorted into increasing order using the allowed moves, or NO otherwise.