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.
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.
For each test case, output "YES" or "NO" in a single line.
4 1 3 4 2 4 2 3 4 1
YES NO
Migrated from old NTUJ.
POI 17th Stage I Railway
No. | Testdata Range | Score |
---|