ZOJ Problem Set - 1171
Imagine you have a pile of 1 <= N <= 10^5 photos. Some of them are faced
upwards and the others faced downwards. Your goal is to sort them so all the
photos are faced the same direction. The only operation you are allowed to do
is to take any amount of the photos from the top into the separate pile, turn
that pile upside-down as the whole and put it back over the rest of original
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.