Asteroid Collision

MediumStack & Queue
Next
StackSimulation

Asteroids move in a row. The absolute value is the size and the sign is the direction (positive moves right, negative moves left). All move at the same speed. When two collide, the smaller one explodes; if they are the same size both explode. Asteroids moving in the same direction never meet. Print the asteroids that survive.

Input

Line 1: n. Line 2: n non-zero integers.

Output

Print the surviving asteroids in their original order, or empty if none survive.

Constraints

1 <= n <= 10^4 -1000 <= value <= 1000, value != 0

Example 1
Input
3
5 10 -5
Output
5 10

-5 hits 10 and explodes; 5 and 10 survive.

Example 2
Input
2
8 -8
Output
empty

Equal size, so both explode.

Hints

Asteroid Collision - Medium Stack & Queue Problem | Skill Shiksha