SWAPS
Given a sequence consisting of integers, all non-zero. We start playing the following game: In each step of the game, we find all pairs of adjacent numbers in the sequence, where the left number is positive and the right number is negative. For each such pair, we swap the two numbers. We then proceed to the next step. We repeat as many steps as needed until no more swaps can be made.
Write a program that calculates: how many swaps will be made throughout the game, what will be the first and the last number of the sequence after the last step.
Input
The first line of the input will contain the number of elements in the sequence. The second line of the input will contain the integers of the sequence, separated in pairs by spaces. Assume that the input will be valid and that .
Output
The output should consist of three lines, each containing exactly one integer. The first line will contain the number of swaps, while the second and third will contain the first and the last number of the sequence after the last step correspondingly.
Constraints
Time Limit: 1 sec.
Maximum Available Memory: 64 MB.
Example of Input - Output
STDIN (swaps.in)
7
10 -9 -4 5 -2 3 8
STDOUT (swaps.out)
4
-9
8
Comments