Problem:


Switching Railroad Cars

This figure shows railway tracks for reshuffling cars. The rail tracks end in the bottom and the top-left rail track is used for the entrace and the top-right rail track is used for the exit. Ten cars, which have numbers from 1 to 10 respectively, use the rail tracks.

We can simulate the movement (comings and goings) of the cars as follow: 

An entry of a car is represented by its number.

An exit of a car is represented by 0

For example, a sequence

1
6
0
8
10

demonstrates that car 1 and car 6 enter to the rail tracks in this order, car 6 exits from the rail tracks, and then car 8 and car 10 enter.

Write a program which simulates comings and goings of the cars which are represented by the sequence of car numbers. The program should read the sequence of car numbers and 0, and print numbers of cars which exit from the rail tracks in order. At the first, there are no cars on the rail tracks. You can assume that 0 will not be given when there is no car on the rail tracks.

Input

car number
car number or 0
car number or 0
  .
  .
  .
car number or 0

The number of input lines is less than or equal to 100.

Output

For each 0, print the car number.

Sample Input

1
6
0
8
10
0
0
0

Output for the Sample Input

6
10
8
1



Sample input:
1
6
0
8
10
0
0
0


Sample output:
6
10
8
1

Submission status: Accepted

Solution code:
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
stack = []
for l in range(len(N)):
    a = int(N[l])
    if a == 0:
        print(stack.pop())
        #print("POP")
    else:
        #print(a)
        stack.append(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys
s = []
[print(s.pop()) if int(e) == 0 else s.append(int(e)) for e in sys.stdin]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
l=[]
for line in sys.stdin:
    o=int(line)
    if not o:
        print(l.pop())
    else:
        l.append(o)

Submission status: Accepted

Solution code:
# AOJ 0013 Switching Railroad Cars
# Python3 2018.6.9 bal4u

class Stack:
    def __init__(self):
        self.items = []

    def isEmpty(self):
        return self.items == []

    def push(self, item):
        self.items.append(item)

    def pop(self):
        return self.items.pop()

    def peek(self):
        return self.items[len(self.items)-1]

    def size(self):
        return len(self.items)

s = Stack()
while True:
    try:
        a = int(input())
        if a > 0:
            s.push(a)
        else:	
            print(s.pop())
    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys

if __name__ == '__main__':
    stack = []
    for line in sys.stdin:
        n = int(line)
        if n == 0:
            print(stack.pop(len(stack) - 1))
        else:
            stack.append(n)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
import sys
def clearSpace(s):
    s.pop()
    return s
list=[]
for i in sys.stdin:
    if i.strip() != '0':
        list.append(i.strip())
    else:
        print list.pop()

Submission status: Accepted

Solution code:
import sys
list=[]
for i in sys.stdin:
    if i.strip() != '0':
        list.append(i.strip())
    else:
        print list.pop()

Submission status: Accepted

Solution code:
import sys
stack=[]
for i in sys.stdin:
    try:
        a=int(i)
        if a >0 :
            stack.append(a)
        else :
            print stack.pop()
    except:
        pass

Submission status: Accepted

Solution code:
tracks = []
while 1:
    try:
        c0 = raw_input()
        if c0 == '':
            break
        c = int(c0)
        if c == 0:
            print tracks.pop()
        else:
            tracks.append(c)
    except EOFError:
        break

Submission status: Accepted

Solution code:
stack = []

def datasets():
    import sys
    while True:
        s = sys.stdin.readline()
        if len(s) < 2:
            break
        yield int(s)

for n in datasets():
    if n == 0:
        print stack.pop()
    else:
        stack.append(n)

Submission status: Accepted

Solution code:
from collections import deque
garage = deque()
while True:
    try:
        came = int(raw_input())
        if came == 0:
            print garage.pop()
        else:
            garage.append(came)
    except ValueError:
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ans = []
while True:
  try:
    a = input()
    if a != 0: ans.append(a)
    elif a == 0: 
      print ans[-1]
      del ans[-1]
  except EOFError: break
  except SyntaxError: continue

Submission status: Accepted

Solution code:
stack = [];

while True:
 try:
  n = input();
  if (n == 0):
   print stack.pop()
  else:
   stack.append(n);
 except:
  break;

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
bottom = []
exits = []
while True:
	carnum = raw_input()
	if carnum == '':
		break
	elif carnum == '0':
		exits.append(bottom[0])
		del bottom[0]
		continue
	else:
		bottom.insert(0,int(carnum))
		continue
for val in exits:
	print val

Submission status: Accepted

Solution code:
import sys



#input_file = open(sys.argv[1], "r")


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

Submission status: Accepted

Solution code:
list = []
while True:
    try:
        a = int(raw_input()
)
        if a != 0:
            list.append(a)
        else:
            b = list.pop()
            print b

    except EOFError:
        break

Submission status: Accepted

Solution code:
x=[]
while True:
    try:
        n = input()
        if n==0: print x.pop()
        else: x.append(n)
    except:
        break

Submission status: Accepted

Solution code:
import sys

s = []

for line in sys.stdin:
    t =	int(line)
    if t == 0:
	print s.pop()
    else:
	s.append(t)

Submission status: Accepted

Solution code:
stack = []

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

Submission status: Accepted

Solution code:
#! /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)

Submission status: Accepted

Solution code:
t = []
while 1:
    try:
        a = input()
    except:
        break
    if a == 0:
        print(t[-1])
        t = t[:-1]
    else:
        t.append(a)

Submission status: Accepted

Solution code:
s = []
while 1:
    try:
        n = input()
        if n==0: print s.pop()
        else: s.append(n)
    except EOFError:
        break;

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys


lineNumber = 0
#for line in [ "1", "6", "0", "8", "10", "0", "0", "0" ]:
for line in sys.stdin.readlines():
    lineNumber += 1

    # except line
    if lineNumber == 1:
        cars = []
    
    # get data
    List = map(int, line.strip().split())

    n = List[0]
    if n == 0: print cars.pop()
    else     : cars.append(n)

Submission status: Accepted

Solution code:
stuck = []
while True:
    try:
        x = int(raw_input())
        if x == 0:
            go = stuck.pop()
            print go
        else:
            stuck.append(x)
    except:
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
x=[]
for n in map(int,sys.stdin):
  if n:x.append(n)
  else:print x.pop()

Submission status: Accepted

Solution code:
import sys
x=[]
for n in map(int, sys.stdin):
  if n: x.append(n)
  else: print x.pop()

Submission status: Accepted

Solution code:
import sys
storage = []
for car in sys.stdin:
    car = int(car)
    if car > 0:
        storage.append(car)
    elif car == 0:
        print storage.pop()
while storage:
    print storage.pop()

Submission status: Accepted

Solution code:
cars = []
ans = []

while True:
	try:
		n = int(raw_input())
		if n == 0:
			ans.append(cars.pop())
		else:
			cars.append(n)
	except EOFError:
		for car in ans:
			print car
		break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
i = 0
inn=[]
for i in sys.stdin:
    i=int(i)
    if i==0 and len(inn)>0:
        print inn[-1]
        inn.pop()
    elif i==0 and len(inn)==0:
        sys.exit()
    elif i!=0:
        inn.append(i)
for i in inn:
    print i

Submission status: Accepted

Solution code:

try:
    a = []
    while True:
        p = int(raw_input())
        if p == 0:
            print a.pop()
        else:
            a.append(p)
except:
    pass

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
stack = []

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

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
s = []

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

Submission status: Accepted

Solution code:
try:
    num = []
    while True:
        #標準入力
        i = int(input())
        #0だった場合１番後ろを出力し削除、それ以外はリストに追加
        if i == 0:
            print(num[-1])
            num.pop(-1)
        else:num.append(i)
#EOFErrorをひろい、ループを抜ける
except EOFError:
    pass

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
s = []
while 1:
    try:
        n = int(input())
        if n == 0:
            print(s.pop())
        else:
            s.append(n)
    except:
        break

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
l1 = []
l2 = []
try:
    while(True):
        n = int(input())
        if n == 0:
            l2.append(l1[-1])
            del l1[-1]
        else:
            l1.append(n)
except:
    pass

for i in l2:
    print(i)

Submission status: Accepted

Solution code:
list=[]

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

Submission status: Accepted

Solution code:
from collections import deque
q=deque([])
while True:
    try:
        n=int(input())
    except:
        break
    if n==0:
        print(q.pop())
    else:
        q.append(n)

Submission status: Accepted

Solution code:
D=[]
while True:
  try:
    n=int(input())
    if n==0:
      print(D.pop(-1))
    else:
      D.append(n)
  except EOFError:
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':

	A = []

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
cars = []
while True:
    try:
        inVal = int(input())
        if inVal == 0:
            print(cars.pop(-1))
        else:
            cars.append(inVal)
    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

Solution code:
car=[]
while True:
    try:
        n=int(input())
        if n!=0:
            car.append(n)
        else:
            print(car.pop())
    except:break

Submission status: Accepted

Solution code:
stack = []
while True:
  try:
    num = int(input())
  except EOFError:
    break
  if num != 0:
    stack.append(num)
  elif num == 0:
    print(stack.pop(-1))

Submission status: Accepted

Solution code:
import sys
  
stack = []

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

Submission status: Accepted

Solution code:
list1 = []
for i in range(1, 200):

    try:
        str1 = input()
        if str1 != '0' and str1 != '':
            list1.append(str1)
        elif str1 == '0':
            print(list1.pop())
        else:
            break
    except:
        break

Submission status: Accepted

Solution code:
stack = []

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
stack = []
while True:
    try:
        i = input()
        if i == "0":
            print(stack.pop(0))
        else:
            stack.insert(0, i)
    except EOFError:
        break

Submission status: Accepted

Solution code:
l = []

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
q = []

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
# Switching Railroad Cars
from collections import deque
num = int(input())
stk = deque()
while 1:
    if num == 0:
        print(stk.pop())
    else:
        stk.append(num)
    try: num = int(input())
    except EOFError: break
while stk: print(stk.pop())

Submission status: Runtime Error

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

lis = []
while True:
  d = input()
  if d == 0:
    print lis[-1]
    lis.pop()
  else:
    lis.append(d)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
rail = []
while True:
  n = int(raw_input())
  if n != 0:
    rail.append(n)
  else:
    print rail.pop()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
list=[]
list.append(input())

While list!=[]:
    inp=input()
    if inp==0:
        print list[-1]
        del list[-1]
    else:
        list.append(inp)

Submission status: Runtime Error

Solution code:
lis=[]
lis.append(input())

while True:
    inp=input()
    if inp==0:
        print lis[-1]
        del lis[-1]
    else:
        lis.append(inp)

Submission status: Runtime Error

Solution code:
lis=[]
lis.append(input())

while true:
    inp=input()
    if inp==0:
        print lis[-1]
        del lis[-1]
    else:
        lis.append(inp)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding:utf-8

syako = []
number = input()
while True:
    if number != 0:
        syako.append(number)
    elif number == 0:
        print syako.pop()
    number = input()
    if number == EOFError:
        break

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
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()

Submission status: Runtime Error

Solution code:
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())

Submission status: Runtime Error

Solution code:
import sys

cars = list()

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

Submission status: Runtime Error

Solution code:
import sys

stack = list()

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

Submission status: Runtime Error

Solution code:
import sys

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

Submission status: Runtime Error

Solution code:
import sys

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

Submission status: Runtime Error

Solution code:
import sys

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

Submission status: Runtime Error

Solution code:
import sys
list=[]
for i in sys.stdin.readlines():
    if int(i) != 0:
        list.append(int(i))
    else:
        print list.pop()

Submission status: Runtime Error

Solution code:
import sys
list=[]
for i in sys.stdin.readlines():
    if float(i) != 0:
        list.append(float(i))
    else:
        print int(list.pop())

Submission status: Runtime Error

Solution code:
import sys
stack=[]
for i in sys.stdin:
    a=int(i)
    if a >0 :
        stack.append(a)
    else :
        print stack.pop()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
stack=[]
for i in sys.stdin:
    a=int(i.split('\n')[0])
    if a >0 :
        stack.append(a)
    else :
        print stack.pop()

Submission status: Runtime Error

Solution code:
tracks = []
while 1:
    try:
        c = input()
        if c == 0:
            print tracks.pop()
        else:
            tracks.append(c)
    except EOFError:
        break

Submission status: Runtime Error

Solution code:
tracks = []
while 1:
    try:
        c = int(raw_input())
        if c == 0:
            print tracks.pop()
        else:
            tracks.append(c)
    except EOFError:
        break

Submission status: Runtime Error

Solution code:
tracks = []
while 1:
    try:
        c0 = raw_input()
        c = int(c0)
        if c == 0:
            print tracks.pop()
        else:
            tracks.append(c)
    except EOFError:
        break

Submission status: Runtime Error

Solution code:
from collections import deque
garage = deque()
while True:
    try:
        came = int(raw_input())
        if came == 0:
            print garage.pop()
        else:
            garage.append(came)
    except EOFError:
        break

Submission status: Runtime Error

Solution code:
from collections import deque
garage = deque()
while True:
    try:
        came = int(raw_input())
        if came == 0:
            print garage.pop()
            if len(garage) == 0:
                break
        else:
            garage.append(came)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
ans = []
while True:
  try:
    a = input()
    if a != 0: ans.append(a)
    elif a == 0: 
      print ans[-1]
      del ans[-1]
  except EOFError: break

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
ans=[]
cars=[]
while True:
    try:
        n=input()
    except EOFError:
        break
    if not n:
        ans.append(cars.pop())
    else:
        cars.append(n)
for i in ans:
    print i

Submission status: Runtime Error

Solution code:
ans=[]
cars=[]
while True:
    try:
        n=input()
    except EOFError:
        break
    if not n:
        out=cars.pop()
        ans.append(out)
    else:
        cars.append(n)
for i in ans:
    print i

Submission status: Runtime Error

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