ΠΔΠ-27 (2015) - Καμπ κοινά - 5 (swaps)

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
C, C++, Java, Pascal, Python

SWAPS

Given a sequence consisting of N 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 N of elements in the sequence. The second line of the input will contain the N integers of the sequence, separated in pairs by spaces. Assume that the input will be valid and that 2 \le N \le 100.000.

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

There are no comments at the moment.