(|n|, n)의 형식으로 넣으면 첫 번째 값은 |n| 이면 전부 동일하지만 두 번째 값은 n을 기준으로 작은 순으로 정렬해줌
import heapq
import sys
input = sys.stdin.readline
N = int(input())
hq = []
for i in range(N):
n = int(input())
if n == 0:
if not hq:
print(0)
else:
print(heapq.heappop(hq)[1])
else:
heapq.heappush(hq, (abs(n), n))