515. Ball Collision

0

Medium

We are given an array ball of integers representing balls in a row. Each ball contains a bomb inside them. Whenever two balls collide, they explode. For each ball, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each ball moves at the same speed. Find out the state of the balls after all collisions. If two balls meet, the smaller one will explode. If both are the same size, both will explode. Two balls moving in the same direction will never meet.

Input Format

First Line contains size of ball array.
Second Line contains elements of ball array.

Output Format

Print resulting array after all collisions

Example

Input

3 5 10 -5

Output

5 10

Constraints

2 <= balls.length <= 104
-1000 <= balls[i] <= 1000
balls[i] != 0
Loading...

View Submissions

Console