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: t = 0
numbers = []
while t == 0:
    try:
        number = int(input())
    except:
        break
    else:
        if number == 0:
            print(numbers[-1])
            numbers.pop(-1)
        else:
            numbers.append(number)

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

Python: try:
    l = []
    while 1:
        d = int(input())
        if d:
            l.append(d)
        else:
            print(l.pop())
except:
    pass

Python: from sys import stdin
stack = []
for line in stdin:
    line = int(line)
    if line == 0:
        print(stack.pop(0))
    else:
        stack.insert(0,line)

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

Python: garage = []
while True:
    num = int(input())
    if num == 0:
        print(garage.pop())
    else:
        garage.append(num)

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

Python: import sys
import math as mas

a=[]
for t in sys.stdin:
	i=int(t)
	if i:a.append(i)
	else:
		print(a[-1])
		a.pop()

#for i in sys.stdin:
#	a,b=map(int,i.split())
#	print(gcd(a,b),lcm(a,b))

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

Python: import sys
l = []
for i in sys.stdin.readlines():
  if int(i) == 0:
    print(l.pop())
  else:
    l.append(int(i))

Python: arr = []

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

    if n == 0:
        print(arr[-1])
        arr = arr[:-1]
    else:
        arr.append(n)

Python: li = []
li.append(int(input()))
depth = 1
while depth > 0:
    x = int(input())
    if x == 0:
        print(li.pop())
        depth -= 1
    else:
        li.append(x)
        depth += 1

Python: counter = -1
train = []
while True:
	try:
		x = int(input())
	except:
		break
	if x == 0 and len(train) != 0:
		print(train[counter])
		train.remove(train[counter])
		counter -= 1
	else:
		train.append(x)
		counter += 1

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

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

Python: # Aizu Problem 0013: Switching Railroad Cars
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


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

Python: # coding: utf-8
# Here your code !

stack = []

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

Python: import sys

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

Python: import sys

cars = []
for line in sys.stdin:
    car = int(line)
    if car:
        cars.append(car)
    else:
        print(cars.pop())

Python: #! /usr/bin/python

import sys

stack = []

for line in sys.stdin:
	#print "input = " + line.strip()

	num = int(line)
	if num == 0:
		pop = stack.pop()
		#print "pop " + str(pop)
		print(str(pop))
	else:
		stack.append(num)
		#print "pushed " + str(num)

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

Python: #!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys


def main():
    stack = []
    for a in sys.stdin.read().split("\n"):
        if a == "0":
            print(stack.pop())
        else:
            stack.append(a)

if __name__ == "__main__":
    main()

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

Python: import sys
from collections import deque


if __name__ == '__main__':
    s = deque()  # ?????????????????¢???????????¨?????????????????\??£???????????????append()??????????????????????????????pop()
    # ??????????????\?????¨???????????????
    for line in sys.stdin:
        if line.strip() == '0':
            print(s.pop())
        else:
            s.append(line.strip())

Python: # -*- coding: utf-8 -*-

pile = []

while True:
    try:
        num = int(input())
        if num != 0:
            pile.append(num)
        else:
            print(pile[-1])
            pile.pop(-1)
    except:
        break

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

Python: a=[]
while 1:
 try:n=int(input());a.append(e)if e else print(a.pop())
 except:break

Python: import sys
numbers = []
try:
    while True:
        a = int(input())
        if a != 0:
            numbers.append(a)
        elif a == 0:
            print(numbers.pop())
except Exception:
    sys.exit()

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

Python: in_ = []
out = []
try:
	while 1:
		in_.append(raw_input())
		if in_[-1] == "0":
			in_.pop()
			out.append(in_.pop())
except:
	pass

for i in out:
	print(i)

Python: # -*- coding: utf-8 -*-

import sys
import os
import math

stack = []
for s in sys.stdin:
    v = int(s)
    if v == 0:
        print(stack.pop())
    else:
        stack.append(v)

Python: import sys

a = []
for i in sys.stdin.readlines():
    n = i[:-1]
    if n == '0':
        print(a.pop())
    else:
        a.append(n)

Python: import sys

lst = []
for line in sys.stdin:
    if line:
        num = line.strip()
        if num == "0":
            print(str(lst.pop()) + "")
        else:
            lst.append(num)
sys.exit(0)

Python: import sys
orders = sys.stdin.readlines()
stack = []
for order in orders:
    if order == '0\n':
        print(stack.pop(), end = '')
    else:
        stack.append(order)

Python: import sys
def main():
    a = []
    for line in sys.stdin:
        hoge = int(line)
        if hoge != 0:
            a.append(hoge)
        elif hoge == 0:
            print(a.pop(-1))


if __name__ == "__main__":
    main()

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

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

Python: import sys
  
stack = []

for nstr in sys.stdin:
    n = int(nstr)
    if n == 0:
        print(stack.pop())
    else:
        stack.append(n)

Python: list=[]

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

Python: #!/usr/bin/env python
#-*- coding:utf-8 -*-

import sys
import math

railroad = []
outCar = []

for data in sys.stdin:
    data = int(data)
    if data != 0:
        railroad.append(data)
    else:
        outCar.append(railroad.pop())

for data in outCar:
    print(data)