# write your code here
class StackOverflowError(Exception):
def __init__(self):
pass
def __str__(self):
return 'StackOverflowError: The stack is full'
class StackEmptyError(Exception):
def __init__(self):
pass
def __str__(self):
return 'StackEmptyError: The stack is empty'
class Stack:
def __init__(self, n):
self.n = n
self.a = []
def push(self, item):
if len(self.a) == self.n:
raise StackOverflowError()
self.a.append(item)
def pop(self):
if len(self.a) == 0:
raise StackEmptyError()
f = self.a[-1]
del self.a[-1]
return f
def peek(self):
if len(self.a) == 0:
raise StackEmptyError()
return self.a[-1]
# FROZEN_SECTION_START
if __name__ == '__main__':
for command in input().split(';'):
command = command.strip()
try:
exec(command)
except Exception as e:
print(e)
Click Run or press shift + ENTER to run code