Go: package main

import "fmt"

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

Python: a = []
while True:
    s = int(input())
    if s != 0:
        a.append(s)
    else:
        print(a.pop())
    if len(a) == 0:
        break

Python: import sys

s = []

for i in map(int, sys.stdin):
    if i:
        s.insert(len(s), i)
    else:
        print(s.pop())

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

Python: a = []
while True:
    s = int(input())
    if s != 0:
        a.append(s)
    else:
        print(a.pop())

Python: import sys

cars = []

while True:
  n = sys.stdin.readline()
  if not n: break
  n = int(n.rstrip())
  if n == 0:
    print(cars.pop())
  else:
    cars.append(n)

Python: cars = []
gone = []
while True:
    try:
        c = int(input())
        if c != 0:
            cars.append(c)
        else:
            gone.append(cars.pop())
    except:
        break
print('\n'.join(map(str, gone)))

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

Python: a = []
while True:
    try:
        s = int(input())
    except:
        break

    if s != 0:
        a.append(s)
    else:
        print(a.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: import sys
cars = []
for line in sys.stdin:
    car = int(line)
    if car:
        cars.append(car)
    else:
        print(cars.pop())

Python: DE = []
while True:
    try:
        N = int(input())
    except:
        break
    if N > 0:
        DE.insert(0,N)
    if N==0:
        print(DE[0])
        DE.pop(0)

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

Python: q = []

while True:
  try:
    i = int(input())
    if i == 0:
      print(q.pop())
    else:
      q.append( i )
  except:
    break

Python: import sys
a=[map(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: import sys
num_li = []
for line in sys.stdin:
    if int(line)==0: print(num_li.pop())
    else: num_li.append(int(line))

Python: from collections import deque
cars=deque()
while(True):
    try:
        n=int(input())
        print(cars.popleft()) if n==0 else cars.appendleft(n)
    except:
        break

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

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

Python: from collections import deque
d = deque()
while True:
    try:
        n = int(input())
        if n == 0:
            print(d.pop())
        else:
            d.append(n)
        
    except EOFError:
        break

Python: import sys

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

Python: import fileinput
a = []
for n in fileinput.input():
    n = int(n)
    if n == 0:
        print(a.pop())
    else:
        a.append(n)

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

Python: stack = list()
while True:
	try:
		num = eval(input())
		if num != 0:
			stack.append(num)
		else:
			print(stack.pop())
	except EOFError:
		break

Python: def get_input():
    while True:
        try:
            yield raw_input()
        except EOFError:
            break

num_lis = list(get_input())

train_lis = []
for num in num_lis:
    if num == '0':
        print(train_lis[0])
        del train_lis[0]
    else:
        train_lis.insert(0, num)

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

Python: import sys

stack = []

for line in sys.stdin:
  try:
    train = int(line)
    if train == 0:
      print(stack.pop())
    else:
      stack.append(train)
  except:
    break

Python: stack = []

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

    if n:
        stack.append(n)
    else:
        print(stack.pop())

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

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

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

Python: import sys

lst = [int(line) for line in sys.stdin.readlines()]

queue = []

for num in lst:
    if num != 0:
        queue.append(num)
    else:
        print(queue[-1])
        del queue[-1]

Python: # coding: utf-8
L=[]
while True:
    try:
        n=int(input())
        if n==0:
            print(L[-1])
            L.pop()
        else:
            L.append(n)
    except EOFError:
        break

Python: waits=[]
while 1:
    try:
        i=input()
        if i=="0":
            print(waits[-1])
            waits.pop()
        else:
            waits.append(i)
    except:break

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

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

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

Python: lis=[]
cnt=0

while True:
    try:
        n=int(input())
        if n:
            cnt+=1
            lis.append(n)
        else:
            print(lis.pop(cnt-1))
            cnt-=1

    except:
        break

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

Python: x = []
while(1):
    try:
        a = int(input())
        if a == 0:
            print(x[-1])
            x.pop(len(x)-1)
#            if len(x) == 0:
#                break
        else:
            x.append(a)
    except EOFError:
        break

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

Python: from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

L = []
for line in stdin:
    n = int(line)
    if not n:
        print(L.pop())
    else:
        L.append(n)

Python: s=[int(input())]
while(len(s)!=0):
    n=int(input())
    if n==0:
        print(s.pop())
    else:
        s.append(n)