Asteroid Collision
Simulate collisions of asteroids represented as an array of integers, using a stack.
Input format
The first line contains N. The second line contains N non-zero integers — positive moves right, negative moves left; absolute value is size. When two collide the smaller explodes (both explode if equal).
Output format
Print the surviving asteroids in order, space-separated (or -1 if none survive).
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
3
5 10 -5Expected output
5 10Example 2
Input
2
8 -8Expected output
-1