TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

A railroad siding consists of two (dead-end) sidetracks 1 and 2. The siding is entered by track A, and left by track B (see figure below).




There are cars on track A, numbered from 1 to n. They are arranged in such a way that they enter the siding in the order a1,a2,...,an. The cars are to be transferred to the siding, so that they leave it by track B in the order 1,2,...,n. Each car is to be transferred once from track A to one of the sidetracks 1 or 2, and later (possibly after some transfers of the remaining cars) once from that sidetrack to the track B. The sidetracks are long enough to store even the longest trains, so there is no need to worry about their capacity.

Input Format

There are multiple test cases, terminated by EOF.


For each test case, first line contains an integer n (1<=n<=100000) then n integers a1, a2, ..., an follow.

Output Format

For each test case, output "YES" or "NO" in a single line.

Sample Input 1

4
1 3 4 2
4
2 3 4 1

Sample Output 1

YES
NO

Hints

Problem Source

Migrated from old NTUJ.

POI 17th Stage I Railway

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 5000 65536 200