UVa 514 - Rails


 * TJU problem 1036

Summary
There is a famous railway station in PopPush City. Country there is incredibly hilly. The station was built in last century. Unfortunately, funds were extremely limited that time. It was possible to establish only a surface track. Moreover, it turned out that the station could be only a dead-end one (see picture) and due to lack of available space it could have only one track.

Explanation
The problem requires reordering items on a stack, specifically to determine if the reordering can be done in a single pass. We can use stack to finish the question, stimulating the process.

Input
5 1 2 3 4 5 5 4 1 2 3 0 6 6 5 4 3 2 1 0 0

Output
Yes No

Yes