import java.util.Scanner;
import java.util.Stack;
public class ShriRamAndArrows {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = scn.nextInt();
}
remainingArrows(arr);
}
public static void remainingArrows(int[] a) {
Stack<Integer> st = new Stack<>();
for (int i = 0; i < a.length; i++) {
int x = a[i];
if (!st.isEmpty() && x < 0 && st.peek() > 0) {
while (!st.isEmpty() && x < 0 && st.peek() > 0) {
if (Math.abs(x) > Math.abs(st.peek())) {
st.pop();
st.push(x);
} else if (Math.abs(x) == Math.abs(st.peek())) {
st.pop();
} else if(Math.abs(x) < Math.abs(st.peek())) {
break;
}
}
} else {
st.push(x);
}
}
Stack<Integer> st2=new Stack<>();
while(!st.isEmpty()) {
st2.push(st.peek());
st.pop();
}
while(!st2.isEmpty()) {
System.out.print(st2.pop()+" ");
}
}
}
