Problem:


Reverse Polish notation is a notation where every operator follows all of its operands. For example, an expression (1+2)*(5+4) in the conventional Polish notation can be represented as 1 2 + 5 4 + * in the Reverse Polish notation. One of advantages of the Reverse Polish notation is that it is parenthesis-free.

Write a program which reads an expression in the Reverse Polish notation and prints the computational result.

An expression in the Reverse Polish notation is calculated using a stack. To evaluate the expression, the program should read symbols in order. If the symbol is an operand, the corresponding value should be pushed into the stack. On the other hand, if the symbols is an operator, the program should pop two elements from the stack, perform the corresponding operations, then push the result in to the stack. The program should repeat this operations.

Input

An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character.

You can assume that +, - and * are given as the operator and an operand is a positive integer less than 106

Output

Print the computational result in a line.

Constraints

2 ≤ the number of operands in the expression ≤ 100

1 ≤ the number of operators in the expression ≤ 99

-1 &times; 109 ≤ values in the stack ≤ 109

Sample Input 1

1 2 +

Sample Output 1

3

Sample Input 2

1 2 + 3 4 - *

Sample Output 2

-3

Notes

Template in C



Sample input:
1 2 +


Sample output:
3

Submission status: Accepted

Solution code:
data = [str(i) for i in input().split()]
stack = []


def is_int(num) -> bool:
    try:
        int(num)
    except ValueError:
        return False
    return True


for d in data:
    if is_int(d):
        stack.append(d)
    else:
        if d == '+':
            a = int(stack.pop())
            b = int(stack.pop())
            stack.append(a + b)
        elif d == '-':
            a = int(stack.pop())
            b = int(stack.pop())
            stack.append(b - a)
        elif d == '*':
            a = int(stack.pop())
            b = int(stack.pop())
            stack.append(a * b)
        else:
            raise ValueError('+, -, *以外の演算子が出現。')
print(stack.pop())

Submission status: Accepted

Solution code:
s = input().split()
stack = []
for v in s:
    # print("v", v)
    # print("stack", stack)
    if v in ["+", "-", "*"]:
        v1 = stack.pop()
        v2 = stack.pop()
        statement = v2 + v + v1
        r = eval(statement)
        stack.append(str(r))
    else:
        stack.append(v)

assert len(stack) == 1
print(stack[0])

Submission status: Accepted

Solution code:
class Stack:
    data_list = []
    def push(self, a):
        self.data_list.append(a)
    def pop(self):
        return self.data_list.pop()

data = input()
lines = data.strip().split()
stack = Stack()
for line in lines:
    if line == '+':
        num = int(stack.pop()) + int(stack.pop())
        stack.push(num)
    elif line == '-':
        num = int(stack.pop()) - int(stack.pop())
        stack.push(-1*num)
    elif line == '*':
        num = int(stack.pop()) * int(stack.pop())
        stack.push(num)
    else:
        stack.push(line)

print(stack.pop())

Submission status: Accepted

Solution code:
vs = input().split()

stack = []
for v in vs:
    if v == '+':
        stack.append(stack.pop() + stack.pop())
    elif v == '-':
        stack.append(-stack.pop() + stack.pop())
    elif v == '*':
        stack.append(stack.pop() * stack.pop())
    else:
        stack.append(int(v))

print(stack.pop())

Submission status: Accepted

Solution code:
def stacker(l):
  stack=[0]
  a=0
  b=0
  for i in l:
    if i=="+":
      a=int(stack[-1])
      b=int(stack[-2])
      stack.pop()
      stack.pop()
      stack.append(a+b)
    elif i=="-":
      a=int(stack[-1])
      b=int(stack[-2])
      stack.pop()
      stack.pop()
      stack.append(-a+b)
    elif i=="*":
      a=int(stack[-1])
      b=int(stack[-2])
      stack.pop()
      stack.pop()
      stack.append(a*b)
    else:
      stack.append(i)
  print(stack[-1])
l=list(input().split())
stacker(l)

Submission status: Accepted

Solution code:
def main():
  inps = list(input().split(" "))
  # print(inps)

  stack = []
  for inp in inps:
    if inp == "+":
      a = int(stack.pop(-2))
      b = int(stack.pop(-1))
      stack.append(a+b)
    elif inp == "-":
      a = int(stack.pop(-2))
      b = int(stack.pop(-1))
      stack.append(a-b)
    elif inp == "*":
      a = int(stack.pop(-2))
      b = int(stack.pop(-1))
      stack.append(a*b)
    else:
      stack.append(inp)
    # print(inp, type(inp), stack)
  print(int(stack[0]))

main()

Submission status: Accepted

Solution code:
S = list(input().split())
a = []

kazu = []
for i in range(1+10**6):
    kazu.append(str(i))


for i in range(len(S)):
    if S[i] in kazu:
        a.append(int(S[i]))

    elif S[i] == "+":
        x = a.pop()
        y = a.pop()
        a.append(x+y)
    
    elif S[i] == "-":
        x = a.pop()
        y = a.pop()
        a.append(y-x)

    elif S[i] == "*":
        x = a.pop()
        y = a.pop()
        a.append(x*y)
        
print(a[0])

Submission status: Accepted

Solution code:
s = []
for t in input().split():
	try:
		v = int(t)
	except ValueError:
		a = s.pop()
		b = s.pop()
		if t == '+': v = b + a
		elif t == '-': v = b - a
		elif t == '*': v = b * a
	s.append(v)
print(s.pop())

Submission status: Accepted

Solution code:
def calc(stack, s):
	a = stack.pop()
	b = stack.pop()
	if s=='+':
		stack.append(b+a)
	elif s=='-':
		stack.append(b-a)
	elif s=='*':
		stack.append(b*a)

		

S = list(input().split())

stack = []
for s in S:
	if s in ['+', '-', '*']:
		calc(stack, s)
	else:
		stack.append(int(s))

print(stack[0])

Submission status: Accepted

Solution code:
s = []
for i in input().split():
    if i in ('+', '-', '*'):
        s.append(eval(str(s.pop(-2)) + i + str(s.pop(-1))))
    else:
        s.append(i)
print(s.pop())

Submission status: Accepted

Solution code:
line= input().split(" ")
op = ["+","-","*"]

stack = []

def push(i):
	stack.append(i)

def pop(i):
	return stack.pop(i)

for i in line:
	if i not in op:
		push(int(i))
	else:
		if i == "+":
			push(pop(-1) + pop(-1))
		elif i == "-":
			push(pop(-2) - pop(-1))
		elif i == "*":
			push(pop(-1) * pop(-1))

print(*stack)

Submission status: Accepted

Solution code:
l=list(input().split())
l=l[::-1]
stack=[]
while len(l)>0:
  n=l.pop()
  if n in ["+","-","*"]:
    a=int(stack.pop())
    b=int(stack.pop())
    if n=="+":
      stack.append(a+b)
    elif n=="-":
      stack.append(b-a)
    else:
      stack.append(a*b)
  else:
    stack.append(n)
print(stack[-1])

Submission status: Accepted

Solution code:
s = list(input().split())
keep =[]
for i in range(len(s)):
  if s[i] == "+":
    keep.append(keep[-1]+keep[-2])
    del keep[-3:-1]
  elif s[i] == "-":
    keep.append(keep[-2]-keep[-1])
    del keep[-3:-1]
  elif s[i] == "*":
    keep.append(keep[-2]*keep[-1])
    del keep[-3:-1]
  elif s[i] == "/":
    keep.append(keep[-2]/keep[-1])
    del keep[-3:-1]
  else:
    keep.append(int(s[i]))
print(keep[-1])

Submission status: Accepted

Solution code:
a = list(map(str,input().split()))
stack = []

for x in a:
    if x == '+':
        stack.append(int(stack.pop()) + int(stack.pop()))
    elif x == '-':
        stack.append(-int(stack.pop()) + int(stack.pop()))
    elif x == '*':
         stack.append(int(stack.pop()) * int(stack.pop()))
    else:
        stack.append(x)
print(int(stack.pop()))

Submission status: Accepted

Solution code:
# Stack

class MyStack:
    def __init__(self):
        self.stack = []
    
    def pop(self):
        return self.stack.pop()
    
    def push(self, x):
        self.stack.append(x)

    def isEmpty(self):
        if len(self.stack)==0:
            return True
        else:
            return False
    
    def isFull(self):
        pass
    
    def calculate(self, x):
        if type(x)==int:
            self.push(x)
        elif type(x)==str:
            b = self.pop()
            a = self.pop()
            if x=='+':
                self.push(a+b)
            elif x=='-':
                self.push(a-b)
            elif x=='*':
                self.push(a*b)


def main():
    A = list(map(lambda x: int(x) if x.isdigit() else x, input().split()))
    stack = MyStack()
    for a in A:
        stack.calculate(a)
    print(stack.pop())

main()

Submission status: Accepted

Solution code:
a = input().split()
b = []
for i in range(len(a)):
    if a[i] == "+":
        b[-2] = b[-2] + b[-1]
        b.pop()
    elif a[i] == "-":
        b[-2] = b[-2] - b[-1]
        b.pop()
    elif a[i] == "*":
        b[-2] = b[-2] * b[-1]
        b.pop()
    else:
        b.append(int(a[i]))
print(b[-1])

Submission status: Accepted

Solution code:
equ = input().split()

stack = []


def push(x, stack):
    stack.append(x)
    return stack
def pop(stack):
    val = stack.pop()
    return val,stack

for symbol in equ:
    if symbol.isnumeric():
        stack = push(int(symbol),stack)
    else:
        val1, stack = pop(stack)
        val2, stack = pop(stack)
        if symbol == '+':
            stack = push(val1+val2, stack)
        elif symbol == '-':
            stack = push(val2-val1, stack)
        elif symbol == '*':
            stack = push(val1*val2, stack)

print(stack[0])

Submission status: Accepted

Solution code:
def isop(s):
    if s == "+" or s == "-" or s == "*":
        return True
    return False


def main():
    line = list(input().split())
    stack = []
    while len(line) > 0:
        tmp = line.pop()
        if isop(tmp):
            stack.append(tmp)
        else:
            stack.append(int(tmp))
        while len(stack) > 2 and isop(stack[-1]) == False and isop(stack[-2]) == False:
            num1 = stack.pop(-1)
            num2 = stack.pop(-1)
            op = stack.pop(-1)
            if op == "+":
                stack.append(num1 + num2)
            elif op == "-":
                stack.append(num1 - num2)
            else:
                stack.append(num1 * num2)

    print(*stack)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def isop(s):
    if s == "+" or s == "-" or s == "*":
        return True
    return False


def main():
    line = list(input().split())
    stack = []
    while len(line) > 0:
        tmp = line.pop(-1)
        if isop(tmp):
            stack.append(tmp)
        else:
            stack.append(int(tmp))
        while len(stack) > 2 and isop(stack[-1]) == False and isop(stack[-2]) == False:
            num1 = stack.pop(-1)
            num2 = stack.pop(-1)
            op = stack.pop(-1)
            if op == "+":
                stack.append(num1 + num2)
            elif op == "-":
                stack.append(num1 - num2)
            else:
                stack.append(num1 * num2)

    print(*stack)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
arr = list(map(str, input().split()))

i = 0

operand = []

while i < len(arr):
    if arr[i] == '+':
        a = operand.pop(-1)
        b = operand.pop(-1)
        operand.append(b + a)
    elif arr[i] == '-':
        a = operand.pop(-1)
        b = operand.pop(-1)
        operand.append(b - a)
    elif arr[i] == '*':
        a = operand.pop(-1)
        b = operand.pop(-1)
        operand.append(b * a)
    else:
        operand.append(int(arr[i]))
    i += 1

print(operand[0])

Submission status: Accepted

Solution code:
S = list(map(str, input().split()))
count = len(S)
stack = []
for i in range(count):
    if S[i] == "+":
        b = stack.pop()
        a = stack.pop()
        stack.append(a + b)
    elif S[i] == "-":
        b = stack.pop()
        a = stack.pop()
        stack.append(a - b)
    elif S[i] == "*":
        b = stack.pop()
        a = stack.pop()
        stack.append(a * b)
    else:
        stack.append(int(S[i]))

print(stack[0])

Submission status: Accepted

Solution code:
data = list(map(str,input().split()))
stack = []
op1 = 0
op2 = 0
k = 0
for i in data:
# print(i,type(i))
  if(i == "+" or i == "-" or i == "*" or i == "/"):
    op1 = stack.pop()
    op2 = stack.pop()
    if(i == "+"): stack.append(op2+op1)
    elif(i == "-"): stack.append(op2-op1)
    elif(i == "*"): stack.append(op2*op1)
    elif(i == "/"): stack.append(int(op2/op1))
  else:
    stack.append(int(i))


print(stack.pop())

Submission status: Accepted

Solution code:
#!/usr/bin/env python                                                                                                                   
inputlist = map(str,raw_input().split())
numberlist = []
for a in inputlist:
    if a == "+":
        b = numberlist[-2]
	c = numberlist[-1]
	numberlist[-2:]=[]
	d = int(b) + int(c)
	numberlist.append(d)
    elif a == "-":
        b = numberlist[-2]
        c = numberlist[-1]
        numberlist[-2:]=[]
        d = int(b) - int(c)
        numberlist.append(d)
    elif a == "*":
	b = numberlist[-2]
        c = numberlist[-1]
        numberlist[-2:]=[]
        d = int(b) * int(c)
	numberlist.append(d)
    else:
        numberlist.append(a)
print(numberlist[0])

Submission status: Accepted

Solution code:
stack = []

for s in input().split():
    if s == '+':
        stack.append(stack.pop() + stack.pop())
    elif s == '-':
        stack.append(-stack.pop() + stack.pop())
    elif s == '*':
        stack.append(stack.pop() * stack.pop())
    else:
        stack.append(int(s))
print(stack[0])

Submission status: Accepted

Solution code:
S = []

W = raw_input().split()
    
for word in W:
    if word == "+":
        s1 = S.pop()
        s2 = S.pop()
        S.append(s1 + s2)
    elif word == "-":
        s1 = S.pop()
        s2 = S.pop()
        S.append(s2 - s1)
    elif word == "*":
        s1 = S.pop()
        s2 = S.pop()
        S.append(s2 * s1)
    else:
        S.append(int(word))

print S.pop()

Submission status: Accepted

Solution code:
s=[]
for i in raw_input().split():
    if i<"0":
        t=s.pop()
        s.append(str(eval(s.pop()+i+t)))
    else:
        s.append(i)
print s[0]

Submission status: Accepted

Solution code:
def main():
    e = raw_input().split()
    t = list()

    for i in e:
        if i == '+': t.append(t.pop() + t.pop())
        elif i == '-': t.append(-(t.pop()) + t.pop())
        elif i == '*': t.append(t.pop() * t.pop())
        else: t.append(int(i))

    print(t.pop())
main()

Submission status: Accepted

Solution code:
f = raw_input().split(" ")
stack = []
for i in f:
	if i.isdigit():
		stack.append(int(i))
	else:
		y = stack.pop()
		x = stack.pop()
		if i == "+":
			stack.append(x+y)
		if i == "-":
			stack.append(x-y)
		if i == "*":
			stack.append(x*y)
print stack.pop()

Submission status: Accepted

Solution code:
# coding:utf-8
# 演算を辞書に押し込む
ops = {	"+": lambda a, b: b + a,
		"-": lambda a, b: b - a,
		"*": lambda a, b: b * a,
		"/": lambda a, b: b / a}

stack = []

for s in raw_input().split():
	if s in ops:
		stack.append(ops[s](stack.pop(), stack.pop()))
	else:
		stack.append(int(s))
print stack[-1]

Submission status: Accepted

Solution code:
import operator

func = {'+':operator.add, '-':operator.sub, '*':operator.mul}

stack  = []
for symbol in input().split():
    if symbol.isdigit():
        stack.append(int(symbol))
    else:
        a = stack.pop()
        b = stack.pop()
        stack.append(func[symbol](b, a))
        
print(stack[0])

Submission status: Accepted

Solution code:
def add(a, b):
    return b+a
def sub(a, b):
    return b-a
def mul(a, b):
    return b*a
def div(a, b):
    if a!=0:
        return b/a
    else:
        return 10000
operators = {'+':add, '-':sub, '*':mul, '/':div}

def calc_PRN(symbols):
    stack = []
    for s in symbols:
        if s in operators.keys():
            stack.append(operators[s](stack.pop(), stack.pop()))
        else:
            stack.append(int(s))
    return stack[-1]


if __name__ == '__main__':
    symbols = input().split()
    print(int(calc_PRN(symbols)))

Submission status: Accepted

Solution code:
s = raw_input().split(' ')
st = []
for i in s:
    if i.isdigit():
        st.append(int(i))
    elif i == '+':
        tmp1 = st.pop()
        tmp2 = st.pop()
        st.append(int(tmp1 + tmp2))
    elif i == '-':
        tmp1 = st.pop()
        tmp2 = st.pop()
        st.append(int(tmp2 - tmp1))
    elif i=='*':
        tmp1 = st.pop()
        tmp2 = st.pop()
        st.append(int(tmp1 * tmp2))
print st[0]

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A
# Stack
# Result:
import sys

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

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

    def pop(self):
        if self.is_empty():
            return None
        return self.store.pop()

    def is_empty(self):
        if len(self.store) == 0:
            return True
        else:
            return False

    def __str__(self):
        """Show top to bottom"""
        val = ''
        for e in reversed(self.store):
            val += str(e) + ' '
        return val

def calculate(stack, func):
    v2 = stack.pop()
    v1 = stack.pop()
    return func(v1, v2)

items = sys.stdin.readline().rstrip().split(' ')
stack = Stack()

for e in items:
    if e == '+':
        v = calculate(stack, lambda v1, v2: v1 + v2)
    elif e == '-':
        v = calculate(stack, lambda v1, v2: v1 - v2)
    elif e == '*':
        v = calculate(stack, lambda v1, v2: v1 * v2)
    else:
        # numbers
        v = int(e)
    stack.push(v)

print stack.pop()

Submission status: Accepted

Solution code:
expressions = raw_input( ).split( " " )
stack = []
for op in expressions:
	if "+" == op:
		b = stack.pop( )
		a = stack.pop( )
		stack.append( a + b )
	elif "-" == op:
		b = stack.pop( )
		a = stack.pop( )
		stack.append( a - b	)
	elif "*" == op:
		b = stack.pop( )
		a = stack.pop( )
		stack.append( a * b )
	else:
		stack.append( int( op ) )
print( stack.pop( ) )

Submission status: Accepted

Solution code:
expressions = input( ).split( " " )
stack = []
for op in expressions:
	if "+" == op:
		b = stack.pop( )
		a = stack.pop( )
		stack.append( a + b )
	elif "-" == op:
		b = stack.pop( )
		a = stack.pop( )
		stack.append( a - b	)
	elif "*" == op:
		b = stack.pop( )
		a = stack.pop( )
		stack.append( a * b )
	else:
		stack.append( int( op ) )
print( stack.pop( ) )

Submission status: Accepted

Solution code:
l=map(str,raw_input().split())
chk=[]
op='-+*'
while len(l):
    k=l.pop(0)
    if k in op:
        b=chk.pop()
        a=chk.pop()
        chk.append(str(eval(a+k+b)))
    else:
        chk.append(k)
print chk[0]

Submission status: Accepted

Solution code:
#input
char_list = raw_input().split()

#calculation
stack = []
for x in char_list:
    if x == "+":
        a = stack.pop()
        b = stack.pop()
        stack.append(a+b)
    elif x=="-":
        a = stack.pop()
        b = stack.pop()
        stack.append(b-a)
    elif x=="*":
        a = stack.pop()
        b = stack.pop()
        stack.append(a*b)
    else:
        stack.append(int(x))

#output
print stack[0]

Submission status: Accepted

Solution code:
# coding: utf-8
from operator import add, sub, mul

op_dict = {'+': add, '-': sub, '*': mul}

def calcurate(list_):
    s = []
    for l in list_:
        if l.isdigit():
            s.append(int(l))
        elif l in ['+', '-', '*']:
            a = s.pop()
            b = s.pop()
            s.append(op_dict[l](b, a))
    return s[0]



def main():
    inputs = raw_input().split()
    print calcurate(inputs)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
poland = input().split()
num = []
for p in poland:
    if p.isdigit():
        num.append(int(p))
    else:
        b = num.pop()
        a = num.pop()
        if p == '*':
            num.append(a * b)
        elif p == '/':
            num.append(a / b)
        elif p == '+':
            num.append(a + b)
        elif p == '-':
            num.append(a - b)
print(num.pop())

Submission status: Accepted

Solution code:
ops = {"+": lambda a, b: b + a,
       "-": lambda a, b: b - a,
       "*": lambda a, b: b * a}

stack = []
for s in input().split():
    if s in ops:
        stack.append(ops[s](stack.pop(), stack.pop()))
    else:
        stack.append(int(s))
print(stack[-1])

Submission status: Accepted

Solution code:
A = raw_input().split()
S = []
for x in A:
    if x in ['+', '-', '*']:
        b = int(S.pop())
        a = int(S.pop())
        if x == '+':
            S.append(a + b)
        elif x == '-':
            S.append(a - b)
        else:
            S.append(a * b)
    else:
        S.append(x)

print S.pop()

Submission status: Accepted

Solution code:
s = raw_input()
sentence = s.split(" ")
stack = []

for factor in sentence:
	if factor == "+":
		b = stack.pop()
		a = stack.pop()
		c = a + b
		stack.append(c)
	elif factor == "-":
		b = stack.pop()
		a = stack.pop()
		c = a - b
		stack.append(c)
	elif factor == "*":
		b = stack.pop()
		a = stack.pop()
		c = a * b
		stack.append(c)
	else:
		stack.append(int(factor))
print stack[0]

Submission status: Accepted

Solution code:
import sys

for line in sys.stdin:
  items = line.strip().split()

stack = []

for item in items:
  if item == '+' or item == '-' or item == '*':
    x = stack.pop()
    y = stack.pop()
    exp = "%s %s %s" % (y, item, x)
    stack.append(eval(exp))
  else:
    stack.append(int(item))

print stack.pop()

Submission status: Accepted

Solution code:
A = raw_input().split()
B = []
def add(x, y):
    return x + y
def sub(x, y):
    return x - y
def mul(x, y):
    return x * y
operation = {'+':add, '-':sub, '*':mul}
for item in A:
    if item.isdigit():
        B.append(int(item))
    else:
        num2 = B.pop() 
        num1 = B.pop()
        ans = operation[item](num1, num2)
        B.append(ans)
print ans

Submission status: Accepted

Solution code:
A = raw_input().split()
B = []

def add(x,y):
    return x + y
def sub(x,y):
    return x - y
def mul(x,y):
    return x * y
operation = {'+':add, '-':sub, '*':mul}

for item in A:
    if item.isdigit():
        B.append(int(item))
    else:
        num2 = B.pop()
        num1 = B.pop()
        ans = operation[item](num1, num2)
        B.append(ans)
print ans

Submission status: Accepted

Solution code:
import sys

def isEmpty(S):
  if len(S) == 0:
    return True
  
def isFull(S):
  if len(S) >= 101:
    return True

def push(x):
  if isFull(S):
    print 'Error'
  S.append(x)
  
def pop(top):
  if isEmpty(S):
    print 'error'
  k = S[top]
  S.pop()
  return k

S = []
top = -1

x = sys.stdin.readline().strip()
x_list = x.split(" ")

for i in range(0, len(x_list)):
  if x_list[i] == '*':
    a = int(pop(top))
    top -= 1
    b = int(pop(top))
    top -= 1
    push(a * b)
    top += 1
    
  elif x_list[i] == '+':
    a = int(pop(top))
    top -= 1
    b = int(pop(top))
    top -= 1
    push(a + b)
    top += 1
    
  elif x_list[i] == '-':
    a = int(pop(top))
    top -= 1
    b = int(pop(top))
    top -= 1
    push(b - a)
    top += 1
    
  else:
    push(x_list[i])
    top += 1
    
a = int(pop(top))
print a

Submission status: Accepted

Solution code:
import sys


Stack = []
MAX = 1000

def push(x):
    #if isFull():
    #    print "ERROR!"
    #    sys.exit()
    Stack.append(x)

def pop():
    #if isEmpty():
    #    print "ERROR!"
    #    sys.exit()
    Stack.pop(-1)

def cul(exp):
    for v in exp:
        if v == "+":
            x = reduce(lambda a,b:int(a)+int(b), Stack[-2:])
            for i in range(2):
                pop()
            push(x)
        elif v == "-":
            x = reduce(lambda a,b:int(a)-int(b), Stack[-2:])
            for i in range(2):
                pop()
            push(x)
        elif v == "*":
            x = reduce(lambda a,b:int(a)*int(b), Stack[-2:])
            for i in range(2):
                pop()
            push(x)
        else:
            push(v)

    return Stack[0]

if __name__ == "__main__":
    exp = sys.stdin.read().strip().split(" ")
    ans = cul(exp)
    print ans

Submission status: Accepted

Solution code:
S = raw_input().split(" ")
Stack = list()

def push(x):
    Stack.append(x)

def pop():
    return Stack.pop(-1)

a = 0
b = 0
for i in range(len(S)):
    if S[i] == "+":
        a = pop()
        b = pop()
        push(b + a)
    elif S[i] == "-":
        a = pop()
        b = pop()
        push(b - a)
    elif S[i] == "*":
        a = pop()
        b = pop()
        push(b * a)
    elif S[i] == "/":
        a = pop()
        b = pop()
        push(b / a)
    else:
        push(int(S[i]))

print Stack.pop(-1)

Submission status: Accepted

Solution code:
import sys


Stack = []

def push(x):
    Stack.append(x)

def pop():
    Stack.pop(-1)


def cul(exp):
    for val in exp:
        if val in ["+", "-", "*"]:
            a = int(Stack[-2])
            b = int(Stack[-1])
            if val == "+":
                x = a + b
            elif val == "-":
                x = a - b
            elif val == "*":
                x = a * b
            for i in range(2):
                pop()
            push(x)
        else:
            push(val)

    return Stack[0]


if __name__ == "__main__":
    exp = sys.stdin.read().strip().split(" ")
    ans = cul(exp)
    print ans

Submission status: Accepted

Solution code:
class Stack(list):
    def __init__(self):
        self.length = 0
    def __len__(self):
        return self.length

    def push(self,x):
        self.insert(len(self),x)
        self.length += 1
    def pop(self):
        try:
            if(len(self)==0):
                raise NameError("stack is empty")
            tmp = self[len(self)-1]
            self.length -= 1
            return tmp
        except:
            print("stack is empty!!!!")
            return '#'

data = Stack()
s = input()
x = s.split()

for i in x:
    if i == '+':
        a = data.pop()
        b = data.pop()
        data.push(b+a)

    elif i == '-':
        a = data.pop()
        b = data.pop()
        data.push(b-a)


    elif i == '*':
        a = data.pop()
        b = data.pop()
        data.push(b*a)
  
    else:
        data.push(int(i))
print(data.pop())

Submission status: Accepted

Solution code:
class Stack():
    def __init__(self):
        self.stack = [0 for _ in range(1000)]
        self.top = 0

    def push(self, n):
        self.top += 1
        self.stack[self.top] = n

    def pop(self):
        a = self.stack[self.top]
        del self.stack[self.top]
        self.top -= 1
        return a

    def lol(self):
        return self.stack[self.top]


def main():
    input_data = raw_input()
    data = input_data.strip().split(" ")
    st = Stack()
    for l in data:
        if l == "+":
            a = st.pop()
            b = st.pop()
            st.push(a + b)

        elif l == "-":
            a = st.pop()
            b = st.pop()
            st.push(b - a)

        elif l == "*":
            a = st.pop()
            b = st.pop()
            st.push(a * b)

        else:
            st.push(int(l))

    print st.lol()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
class Trio:
    __pre=None
    __val=None
    __nex=None
    def __init__(self,val,p=None,n=None):
        self.__pre=p
        self.__val=val
        self.__nex=n
    
    def get_pre(self):return self.__pre
    
    def get_nex(self):return self.__nex
    
    def set_nex(self,n):self.__nex=n
    
    def set_val(self,n):self.__val=n
    
    def get_val(self):return self.__val

class Stack:
    member=Trio(None)
    def __init__(self,stri):
        if(isinstance(stri,str)):
            for i,e in enumerate(stri):
                if(i==0):
                    self.member.set_val(e)
                else:
                    self.push(e)

    
    def push(self,n):
        self.member.set_nex(Trio(n,self.member,None))
        self.member=self.member.get_nex()

    def pop(self):
        if(self.member==None):
            return None
        d=self.member.get_val()
        self.member=self.member.get_pre()
        return d

s=input()
stk = Stack(None)
stri=""
for i in s:
    if(i==" "):
        stk.push(stri)
        stri=""
    elif(i.isdigit()):
        stri="".join([stri,i])
    elif(i=="+" or i=="-" or i=="*"):
        b=stk.pop()
        b=int(b)
        a=int(stk.pop())
        if(i=="+"):
            stri=(str(a+b))
        elif(i=="-"):
            stri=(str(a-b))
        else:
            stri=(str(a*b))

print(stri)

Submission status: Accepted

Solution code:
class Stack():
    def __init__(self):
        self.stack = [0 for _ in range(200)]
        self.top = 0

    def isEmpty(self):
        return self.top == 0

    def isFull(self):
        return self.top >= len(self.stack) - 1

    def push(self, x):
        if self.isFull():
            print "error"
            return exit()
        self.top += 1
        self.stack[self.top] = x

    def pop(self):
        if self.isEmpty():
            print "error"
            return exit()
        a = self.stack[self.top]
        del self.stack[self.top]
        self.top -= 1
        return a

    def lol(self):
        return self.stack[self.top]

def main():
    st = Stack()
    data = raw_input().split()
    for i in data:
        if i == '+':
            b = int(st.pop())
            a = int(st.pop())
            st.push(a + b)
        elif i == '-':
            b = int(st.pop())
            a = int(st.pop())
            st.push(a - b)
        elif i == '*':
            b = int(st.pop())
            a = int(st.pop())
            st.push(a * b)
        else:
            st.push(i)
    print st.lol()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#coding:utf-8
#1_3_A
formula = input().split()
stack = []
for char in formula:
    if char.isdigit():
        stack.append(char)
    else:
        ans = str(eval(stack.pop(len(stack)-2) + char + stack.pop()))
        stack.append(ans)
print(stack.pop())

Submission status: Accepted

Solution code:
class Stack:
    # ???????????????????????§??????top??????????????????????????????Max???isFull??¨????????????stack???????????????????????§???
    def __init__(self):
        self.top = 0
        self.Max = 100
        self.stack = [None]

    def isEmpty(self):
        return self.top == 0
    
    def isFull(self):
        return self.top >= self.Max

    def push(self, x):
        if self.isFull():
            print("Stack overflow!")
        else:
            self.top += 1
            self.stack.append(x)

    def pop(self):
        if self.isEmpty():
            print("Stack underflow!")
        else:
            self.top -= 1
            return self.stack.pop()

d_e = input().split()

accumlator = Stack()

for i in d_e:
    if i in "+-*":
        post_op = accumlator.pop()
        pre_op = accumlator.pop()
        ans = eval(pre_op + i + post_op)
        accumlator.push(str(ans))
    else:
        accumlator.push(i)

print(int(accumlator.pop()))

Submission status: Accepted

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

OPERATORS = ["+", "-", "*"]


def calc(symbols):
    stack = []
    for s in symbols:
        if s in OPERATORS:
            a = stack.pop()
            b = stack.pop()
            if s == "+":
                stack.append(b + a)
            elif s == "-":
                stack.append(b - a)
            elif s == "*":
                stack.append(b * a)
        else:
            stack.append(int(s))
    return stack[-1]


def main():
    print(calc(input().split()))


if __name__ == "__main__":
    main()