
https://www.acmicpc.net/problem/1927
최소힙구현을 위한 heapq모듈을 사용했다.
x가 0이지만 힙이 비어있는 경우 0을 출력하고
힙이 비어있지 않다면 최소값을 출력하고 제거한다.
그냥 자연수라면 힙에 삽입한다.
import heapq
import sys
input=sys.stdin.readline
n=int(input())
exp=[]
for _ in range(n):
  exp.append(int(input()))
heap=[]
heapq.heapify(heap)
for i in exp:
  if i==0 and len(heap)==0:
    print(0)
  elif i==0:
    print(heapq.heappop(heap))
  else:
    heapq.heappush(heap,i)