import sys
import heapq
numbers = int(input())
heap = []
for _ in range(numbers):
num = int(sys.stdin.readline())
if num != 0:
heapq.heappush(heap, (abs(num), num))
else:
try:
print(heapq.heappop(heap)[1])
except:
print(0)
https://claude-u.tistory.com/154