import heapq
count = int(input())
heap = list()
for _ in range(count):
data = input()
if data == "0":
if heap:
print(heapq.heappop(heap))
else:
print(0)
else:
heapq.heappush(heap, int(data))
import sys
import heapq
count = int(sys.stdin.readline().strip())
heap = list()
for _ in range(count):
data = int(sys.stdin.readline().strip())
if data:
heapq.heappush(heap,data)
else:
if heap:
print(heapq.heappop(heap))
else:
print(0)
https://claude-u.tistory.com/153
import sys
import heapq
numbers = int(input())
heap = []
#Max Heap
for _ in range(numbers):
num = int(sys.stdin.readline())
if num != 0:
heapq.heappush(heap, num)
else:
try:
print(heapq.heappop(heap))
except:
print(0)