Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/stack-asteroidlar

Asteroid collisions

Medium 1000 ms 128 MB 49%
Share

$n$ asteroids fly along a line at the same speed; from left to right they are in the order $a_{1}, a_{2}, \dots, a_{n}$. $|a_{i}|$ is the size of the asteroid and the sign is its direction: positive means it flies to the right, negative to the left. When two asteroids collide, the smaller one disappears; if their sizes are equal, both do. Asteroids flying in the same direction never collide. Print the asteroids left after all collisions from left to right; if none are left, print -.

Asteroids with arrows: those flying towards each other collide, the ones left at the end are highlighted

Input

The first line contains a positive integer $n$.
The second line contains $n$ non-zero integers $a_{i}$.

Output

The remaining asteroids (separated by spaces) or -.

Note

$1 \le n \le 2 \cdot 10^{5}$
$1 \le |a_{i}| \le 10^{9}$

Examples

Input #1
5
5 10 -5 -12 3
Output #1
-12 3
Input #2
2
8 -8
Output #2
-

Sign in to submit a solution

Signing up is free and takes a minute.