input = sys.stdin.readline 이 부분을 추가해줘야 했음 ㅋㅋ 🤬import heapq
import sys
input = sys.stdin.readline
heap = []
for _ in range(int(input())):
num = int(input())
if not num:
print(heapq.heappop(heap) if len(heap) else 0)
else:
heapq.heappush(heap, num)