Go: package main

import "fmt"

func main() {
	stack := []int{}
	for {
		var a int
		i, _ := fmt.Scan(&a)
		if i == 0 {
			break
		}
		if a == 0 {
			fmt.Println(stack[len(stack)-1])
			stack = stack[:len(stack)-1]
			continue
		}
		stack = append(stack, a)
	}
}

Python: import sys
a=[map(int,i)for i in sys.stdin]

b=[]
for j in a:
	if j == 0:
		print(b.pop())
	else:
		b.append(j)

Python: l=[]
l.append(int(input()))
while l:
    o=int(input())
    if not o:
        print(l.pop())
    else:
        l.append(o)

Python: import sys
cars = []
num = -1

for user in sys.stdin:
    i = int(user)
    if i == 0:
        print(cars[num])
        cars.pop(num)
        num -= 1
    else:
        cars.append(i)
        num += 1

Python: array = []
array2 = []
import sys
for i in sys.stdin.readlines():
    n = i.rstrip()
    if n == "0":
        array2.append(array[-1])
        array.pop(-1)
    else:
        array.append(n)
for i in range(len(array2)):
    print(array2[i])

Python: from collections import deque
import sys

train = deque([])
for line in sys.stdin:
    n = int(line)
    if n == 0:
        t = train.popleft()
        print(t)
    else:
        train.appendleft(n)

Python: import sys

d = sys.stdin.readline().rstrip()
stack = list()
while d:
    if d != '0':
        stack.append(d)
    else:
        print(stack.pop())
    d = sys.stdin.readline().rstrip()

Python: import sys
stk = []
ans = []
for i in sys.stdin:
    if(int(i)==0):
        ans.append(stk.pop())
    else:
        stk.append(int(i))
print('\n'.join(map(str,ans)))

Python: garage = []
cars = []
while True:
    num = int(input())
    if num == 0:
        cars.append(garage.pop())
    else:
        garage.append(num)
        print(garage)
    if not garage:
        break
[print(car) for car in cars]

Python: import sys
a=[int(i)for i in sys.stdin]

b=[]
print(a)
for j in a:
	if j == 0:
		print(b.pop())
	else:
		b.append(j)

Python: a = []
i = 0
while True:
    try:
        n = int(input())
        if (n):
            a.append(n)
            i += 1
        else:
            i -= 1
            print(a[i])
            a.pop()

    except EOFError:
        break

Python: memory=[]
while True:
  try:
    n=int(input())
  except EOFError:
    break
  if n==0:
    print(memory.pop())
  else:
    memory.append(n)

Python: # coding: utf-8

class Stack(object):
	maxnum = 100
	array = []
	for i in range(100):
		array.append(0)
	index = 0
	def push(self, data):
		self.array[self.index] = data
		self.index += 1
	def pop(self):
		print(self.array[self.index-1])
		self.index -= 1

road = Stack()
while True:
	try:
		num = int(raw_input())
		if num != 0:
			road.push(num)
		else:
			road.pop()
	except EOFError:
		break

Python: st = []
while True:
  try:
    n = int(input())
    if n == 0:
      print(st.pop())
    else:
      st.append(n)
  except EOFError:
    break

Python: train = []
while True:
    try:
        tmp = int(input())
        if tmp:
            train.append(tmp)
        else:
            print(train.pop())
    except:
        break

Python: car = []
while 1:
    try:
        i = int(input())
        if  i == 0:
            print(car.pop()) 
        else:
            car.append(i)
    except ValueError:
        print(car)
        for j in range(len(car)):
            print(car.pop())
        break
    except EOFError:
        break

Python: tracks=[]
while True:
    try:
        s=int(input())
        if s==0:
            print(tracks.pop())
        else:
            tracks.append(s)
    except:
        break

Python: import sys
s=[]
while True:
    try:
        n=int(input())
    except:
        sys.exit()
    if n==0:
        print(s.pop())
    else:
        s.append(n)

Python: li = []
while True:
    try:
        x = int(input())
    except:
        break

    if x == 0:
        print(li.pop())
    else:
        li.append(x)

Python: a = [] 
while True: 
  try: 
    i = int(input()) 
  except: 
    break 
  if i == 0: 
    c = a.pop() 
    print(c) 
  else: 
    a.append(i)

Python: # coding=utf-8


if __name__ == '__main__':
    train_list = []
    while True:
        try:
            n = int(input())
        except EOFError:
            break
        if n == 0:
            leaving = train_list.pop()
            print(leaving)
        else:
            train_list.append(n)

Python: list = {}
while True:
    try:
        num = int(input())
        if num == 0:
            print(list.pop())
        else:
            list.append(num)
    except:
        break

Python: import sys
a=[]
for e in map(int,sys.stdin):
 a.append(e)if e else print(a.pop())

Python: import sys
a=[]
stack=[]
for line in sys.stdin:
    a.append(int(line))
for i in range(len(a)):
    if a[i]==0:
        print(stack[-1])
        del stack[-1]
    else:stack.append(a[i])

Python: lst = []
stack = []
while True :
    try :
        lst.append(int(input()))
    except EOFError :
        break
for i in lst :
    if i == 0 :
        print(stack.pop(-1))
    else :
        stack.append(i)

Python: stack = []
while True:
    try:
        n = int(input())
    except:
        break
    stack.append(n) if n else print(stack.pop())

Python: import sys


def main():
    stack = []
    for x in sys.stdin:
        x = int(x)
        if x:
            stack.append(x)
        else:
            print(stack.pop())


if __name__ == '__main__':
    main()

Python: st = []
while 1:
    try:
        x = int(input())
        st.append(x) if x != 0 else print(st.pop())
    except EOFError:
        break

Python: import sys
queue = []
for line in sys.stdin:
    n = int(line)
    if n != 0:
        queue.append(n)
    else:
        print(queue.pop())

Python: import sys


shako = []

s = sys.stdin.read().strip().split("\n")

for i in s:
    if i != "0":
        # print("appended",i)
        shako.append(i)
        # print(shako)
    else:
        print(shako.pop())

Python: bottom = []
while True:
	carnum = input()
	if carnum == '':
		break
	elif carnum == 0:
		bottom.pop()
		continue
	else:
		nottom.append(carnum)
		continue

Python: # -*- coding:utf-8 -*-
array = []
while True:
    try:
        n = int(input())
        array.append(n)
    except EOFError:
        break
data = []
for i in range(len(array)):
    if array[i] == 0:
        elm = data.pop()
        print(elm)
    else:
        data.append(array[i])

Python: s = []

while 1:
    try:
        d = int(input())
    except:
        break
    if d == 0:
        print(s.pop())
    else:
        s.append(d)

Python: import sys

cars = list()

for line in sys.stdin.readlines():
    line = line.strip()
    N = int(line)
    if N != 0:
        cars.append(N)
    else:
        print(cars.pop())

Python: c=[]
s=[]
e=[]
while True:
    try:
        t=input()
        if not t:break
    except:break
    c.append(int(t))

for i in c:
    if i==0:
        e.append(s.pop(-1))
    else:
        s.append(i)
[print(i) for i in e]

Python: train=[]
while 1:
    try:
        n=input()
        if n==0:
            print(train.pop())
        else:
            train.append(n)
    except:
        break

Python: l = []

while(1):
    try:
        n = int(input())
    except:
        break

    if n == 0:
        ans = l.pop(-1)
        print(ans)
    else:
        l.append(n)

Python: l = []
while True:
	try:
		train = raw_input()
		if train == '0':
			print(l.pop())
		else:
			l.append(train)
	except EOFError:
		break

Python: import sys

arr = []
for line in sys.stdin:
    n = int(line)
    if n == 0:
        print(arr.pop())
    else:
        arr.append(n)

Python: import sys
a=[int(i)for i in sys.stdin]

b=[]
for j in a:
	if j == 0:
		print(b.pop())
	else:
		b.append(j)

Python: import sys

def run():
    cars = []
    for _n in sys.stdin:
        n = int(_n)
        if n == 0:
            print(cars.pop())
        else:
            cars.append(n)

if __name__ == '__main__':
    run()