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 10 6  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 × 10 9 ≤ values in the stack ≤ 10 9  Sample Input 1 1 2 + Sample Output 1 3 Sample Input 2 1 2 + 3 4 - * Sample Output 2 -3 Notes Template in C

Solution (Python):
A = input().split()
S = []


for i in A:
    if i == '+' or i == '-' or i == '*':
        a = S.pop()
        b = S.pop()
        if i == '+': S.append(b+a)
        elif i == '-': S.append(b-a)
        else: S.append(b*a)
    else:
        x = int(i)
        S.append(x)
    

print(S[0])

Solution (Python):
def add(a,b): 
    return a + b
def sub(a,b): 
    return a - b
def mul(a,b): 
    return a * b
def div(a,b): 
    return a/ float(b)

A=input().split()
i=0
for j in range(len(A)):
    if A[i]=="+":
        A[i-2]=(int)(A[i-2])
        A[i-1]=(int)(A[i-1])
        A[i]=add(A[i-2],A[i-1])
        r=A[i]
        del A[i-2]
        del A[i-2]
        i=i-2
    if A[i]=="-":
        A[i-2]=(int)(A[i-2])
        A[i-1]=(int)(A[i-1])
        A[i]=sub(A[i-2],A[i-1])
        r=A[i]
        del A[i-2]
        del A[i-2]
        i=i-2
    if A[i]=="*":
        A[i-2]=(int)(A[i-2])
        A[i-1]=(int)(A[i-1])
        A[i]=mul(A[i-2],A[i-1])
        r=A[i]
        del A[i-2]
        del A[i-2]
        i=i-2
    if A[i]=="/":
        A[i-2]=(int)(A[i-2])
        A[i-1]=(int)(A[i-1])
        A[i]=div(A[i-2],A[i-1])
        r=A[i]
        del A[i-2]
        del A[i-2]
        i=i-2
    i=i+1
print(r)

Solution (Python):

A=input().split()
i=0
for j in range(len(A)):
    if A[i]=="+":
        r=int(A[i-2])+int(A[i-1])
        A[i]=r
        del(A[i-2])
        del(A[i-2])
        i-=2
    if A[i]=="-":
        r=int(A[i-2])-int(A[i-1])
        A[i]=r
        del(A[i-2])
        del(A[i-2])
        i-=2
    if A[i]=="*":
        r=int(A[i-2])*int(A[i-1])
        A[i]=r
        del(A[i-2])
        del(A[i-2])
        i-=2
    i+=1

print(r)

Solution (Python):
s=input().split()
x=[]
top=len(s)
for i in range(top):
        
    if s[i]=="+":
        a=x.pop()
        b=x.pop()
        x.append(int(b)+int(a))
    elif s[i]=="-":
        a=x.pop()
        b=x.pop()
        x.append(int(b)-int(a))
    elif s[i]=="*":
        a=x.pop()
        b=x.pop()
        x.append(int(b)*int(a))
    else:
        x.append(s[i])
   
print(x[0])

Solution (Python):
def cal(ope,a,b):
    if ope=="+":
        x=a+b
    elif ope=="-":
        x=a-b
    elif ope=="*":
        x=a*b
    return x

lst=input().split()
stack=[]
for i in range(len(lst)):
    if lst[i]=="+" or lst[i]=="-" or lst[i]=="*": pass
    else:
        lst[i]=int(lst[i])
for i in range(len(lst)):
    if lst[i]=="+" or lst[i]=="-" or lst[i]=="*": 
        a=stack.pop()
        b=stack.pop()
        c=cal(lst[i],b,a)
        stack.append(c)
    else:
        stack.append(lst[i])
print(stack[0])

Solution (Python):
import sys
a = list(input().split())
stack = []
for i in range(len(a)):
    n = len(stack)
    if a[i] == '+':
        if (n-2) <0:
            sys.exit("スタックアンダーフロー")
        tmp = int(stack.pop(n-1)) + int(stack.pop(n-2))
        stack.append(tmp)
        
    elif a[i] == '-':
        if (n-2) <0:
            sys.exit("スタックアンダーフロー")
        tmp_1 = int(stack.pop(n-1))
        tmp_2 = int(stack.pop(n-2))
        tmp = tmp_2 - tmp_1
        stack.append(tmp)
        
    elif a[i] == '*':
        if (n-2) <0:
            sys.exit("スタックアンダーフロー")
        tmp = int(stack.pop(n-1)) * int(stack.pop(n-2))
        stack.append(tmp)
        
    elif a[i] == '/':
        if (n-2) <0:
            sys.exit("スタックアンダーフロー")
        tmp_1 = int(stack.pop(n-1))
        tmp_2 = int(stack.pop(n-2))
        tmp = tmp_2 / tmp_1
        stack.append(tmp)
    else:
        stack.append(int(a[i]))
print(stack[0])

Solution (Python):


a=input().split()

stack=[]

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

print(stack[0])

Solution (Python):



symbols = input().split(' ')
stack = []

def calc(op):
    global stack
    if op == '+':
        return stack.pop()+stack.pop()
    elif op == '-':
        return -1 * stack.pop()+stack.pop()
    elif op == '*':
        return stack.pop()*stack.pop()

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

print(stack.pop())

Solution (Python):
def kei(a,i,x,y):
	if a[i]=="+":
		st=x+y
		
	elif a[i]=="-":
		st=y-x
		
	elif a[i]=="*":
		st=x*y
		
	return st


a=[]
stac=[]
a=list(input().split())
for i in range(len(a)):
	if a[i].isdigit():
		stac.append(int(a[i]))
		
	else:
		x=stac.pop()
		y=stac.pop()
		stac.append(kei(a,i,x,y))
		
print(stac[0])

Solution (Python):
l=list(input().split())  
stack=[]

for x in l: 
    if x in ['+','-','*']: 
        t=str(stack.pop()) 
        r=str(stack.pop())
        c=r+x+t
        stack+=[int(eval(c))] 

    else:
        stack+=[int(x)] 

print(stack.pop())

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

Solution (Python):

"""
Created on Sun Apr 29 14:04:29 2018
ALDS1-3a
@author: maezawa
"""
maxn=200
s = input().split()
st = [0 for _ in range(maxn)]
top = 0

for i in range(len(s)):
    c = s.pop(0)
    if c == '+':
        b = st[top]
        top -= 1
        a = st[top]
        top -= 1
        ans = a + b
        top += 1
        st[top] = ans
    elif c == '-':
        b = st[top]
        top -= 1
        a = st[top]
        top -= 1
        ans = a - b
        top += 1
        st[top] = ans
    elif c == '*':
        b = st[top]
        top -= 1
        a = st[top]
        top -= 1
        ans = a * b
        top += 1
        st[top] = ans
    else:
        top += 1
        st[top] = int(c)
print(st[top])

Solution (Python):
s = input().split()
st = []

for i in range(len(s)):
    c = s.pop(0)
    if c == '+':
        b = st.pop(0)
        a = st.pop(0)
        ans = a + b
        st.insert(0,ans)
    elif c == '-':
        b = st.pop(0)
        a = st.pop(0)
        ans = a - b
        st.insert(0,ans)
    elif c == '*':
        b = st.pop(0)
        a = st.pop(0)
        ans = a * b
        st.insert(0,ans)
    else:
        st.insert(0, int(c))

print(st.pop(0))

Solution (Python):
a=input().split()
operator={
  '+':(lambda x,y:x+y),
  '-':(lambda x,y:x-y),
  '*':(lambda x,y:x*y),
  '/':(lambda x,y:float(x)/y)
}
stack=[]
for i,j in enumerate(a):
  if j not in operator.keys():
    stack.append(int(j))
    continue
  y=stack.pop()
  x=stack.pop()
  stack.append(operator[j](x,y))
print(stack[0])

Solution (Python):


x = input().split()
flag = 0
j = -1
y = []
for i in range(len(x)):
    j = len(y) -1
    if x[i] == "+":
        a = y.pop(j)
        b = y.pop(j-1)
        y.append(b+a)
    elif  x[i] == "-":
        a = y.pop(j)
        b = y.pop(j-1)
        y.append(b-a)
    elif x[i] == "*":
        a = y.pop(j)
        b = y.pop(j-1)
        y.append(b*a)
    else:
        y.append(int(x[i]))
print(y[0])

Solution (Python):
symbol = list(input().split())
stack = []

while len(symbol) > 0:
    x = symbol.pop(0)
    if x.isdigit():
        stack.append(int(x))
    else:
        a,b = stack.pop(),stack.pop()
        if x == "+":
            stack.append(b + a)
        elif x == "-":
            stack.append(b - a)
        elif x == "*":
            stack.append(b * a)

print(stack.pop())

Solution (Python):
from collections import deque as D
line, stack = D(input().split()), D()
while line:
    hoge = line.popleft()
    if hoge.isdigit():
        stack.append(hoge)
    else:
        a, b = int(stack.pop()),int(stack.pop())
        if hoge =="*":
            stack.append(a*b)
        elif hoge == "+":
            stack.append(a+b)
        elif hoge == "-":
            stack.append(b-a)
        else:
            stack.append(b//a)
print(stack.popleft())

Solution (Python):
def add(x,y):
    return x+y
def sub(x,y):
    return x-y
def mul(x,y):
    return x*y
def div(x,y):
    return x/float(y)

a=input().split()
i=0
for j in range(len(a)):
    if a[i]=="+":
        a[i-2]=int(a[i-2])
        a[i-1]=int(a[i-1])
        a[i]=int(add(a[i-2],a[i-1]))
        del a[i-2]
        del a[i-2]
        i=i-2
    elif a[i]=="-":
        a[i-2]=int(a[i-2])
        a[i-1]=int(a[i-1])
        a[i]=int(sub(a[i-2],a[i-1]))
        del a[i-2]
        del a[i-2]
        i=i-2
    elif a[i]=="*":
        a[i-2]=int(a[i-2])
        a[i-1]=int(a[i-1])
        a[i]=int(mul(a[i-2],a[i-1]))
        del a[i-2]
        del a[i-2]
        i=i-2
    elif a[i]=="/":
        a[i-2]=int(a[i-2])
        a[i-1]=int(a[i-1])
        a[i]=int(div(a[i-2],a[i-1]))
        del a[i-2]
        del a[i-2]
        i=i-2
    i=i+1
print(a[0])

Solution (Python):

list=input().split()

i=0

for j in range(len(list)):
	if list[i]=='+':
		list[i]=int(list[i-1])+int(list[i-2])
		del list[i-2]
		del list[i-2]
		i-=2
	elif list[i]=='-':
		list[i]=int(list[i-2])-int(list[i-1])
		del list[i-2]
		del list[i-2]
		i-=2
	elif list[i]=='*':
		list[i]=int(list[i-1])*int(list[i-2])
		del list[i-2]
		del list[i-2]
		i-=2
	elif list[i]=='/':
		list[i]=int(list[i-2])/float(list[i-1])
		del list[i-2]
		del list[i-2]
		i-=2
	i+=1

print(list[0])

Solution (Python):
a=input().split()
b=[]
for i in range(len(a)):

	if a[i]=="+":

		b[len(b)-2]=b[len(b)-2]+b[len(b)-1];
		del b[len(b)-1]

	elif a[i]=="-":

		b[len(b)-2]=b[len(b)-2]-b[len(b)-1];
		del b[len(b)-1]

	elif a[i]=="*":

		b[len(b)-2]=b[len(b)-2]*b[len(b)-1];
		del b[len(b)-1]

	else:
		b.append(int(a[i]))

		
print(b[len(b)-1])

Solution (Python):
s = list(input().split())
a = []
for x in s:
    if  x in  ['+', '-', '*']:
        c, b = str(a.pop()), str(a.pop())
        b+= x+c
        a+=[int(eval(b))]
    else:
        a+= [int(x)]
print(a.pop())

Solution (Python):
A=input().split()
l=len(A)
x=[]

for i in range(l):
    
    if A[i]=="+":
        a=x.pop() 
        b=x.pop()
        x.append(int(b)+int(a))

    elif A[i]=="-":
        a=x.pop()
        b=x.pop()
        x.append(int(b)-int(a))

    elif A[i]=="*":
        a=x.pop()
        b=x.pop()
        x.append(int(b)*int(a))

    else:
        x.append(A[i])

print(x[0])

Solution (Python):
class Stack:
    def __init__(self, full_idx=10):
        self.stack = [None] * full_idx
        self.top = 0
        self.MAX = full_idx

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

    def is_full(self):
        return self.top >= self.MAX - 1

    def push(self, x):
        if self.is_full():
            raise IndexError

        self.top += 1
        self.stack[self.top] = x

    def pop(self):
        if self.is_empty():
            raise IndexError

        self.top -= 1
        return self.stack[self.top+1]


def main():
    e = input().split()
    s = Stack(101)

    for i in range(len(e)):
        if e[i].isdigit():
            s.push(int(e[i]))
        elif e[i] == '+':
            a, b = s.pop(), s.pop()
            s.push(a+b)
        elif e[i] == '-':
            a, b = s.pop(), s.pop()
            s.push(b-a)
        else:
            a, b = s.pop(), s.pop()
            s.push(a*b)

    print(s.pop())


if __name__ == '__main__':
    main()

Solution (Python):

def main():
    l = input().split(' ')

    while len(l) > 1:
        idx = 0
        while l[idx] not in ["+", "-", "*"]:
            idx += 1
        res = str(eval(str(l[idx-2] + l[idx] + l[idx-1])))
        l[idx-2] = res
        l.pop(idx-1)
        l.pop(idx-1)

    print(l[0])

main()

Solution (Python):

def main():
    l = input().split(' ')

    s = []

    for el in l:
        if el in ["+", "-", "*"]:
            a = s.pop(-1)
            b = s.pop(-1)
            s.append(eval(str(b) + el + str(a)))
        else:
            s.append(int(el))

    print(s[0])

main()

Solution (Python):
L = input().split()
n = len(L)
A  = []
top = -1
for i in range(n):
    if L[i] not in {"+","-","*"}:
        A.append(int(L[i]))
        top += 1
    else:
        if(L[i] == "+"):
            A[top - 1] = A[top - 1] + A[top]
        elif(L[i] == "-"):
            A[top - 1] = A[top -1] - A[top]
        elif(L[i] == "*"):
            A[top - 1] = A[top - 1] * A[top]
        del A[top]
        top -= 1
print(A[top])

Solution (Python):
input_list = list(map(str, input().split()))
stack_list = []

for i in input_list:
    if i not in ['+', '-', '*']:
        stack_list.append(i)
    else:
        a = stack_list.pop()
        b = stack_list.pop()
        stack_list.append(str(eval(b + i + a)))

print(stack_list[0])

Solution (Python):
stk = []
for c in input().split():
    if c in "+-*":
        a = stk.pop()
        b = stk.pop()
        stk.append(str(eval(b + c + a)))
    else:
        stk.append(c)
print(stk.pop())

Solution (Python):
stak = []
for i in input().split():
    if i in "+-*":
        a = stak.pop()
        b = stak.pop()
        stak.append(str(eval(b + i + a)))
    else:
        stak.append(i)
print(stak.pop())

Solution (Python):
stak = []
for i in input().split():
    if i in "+-*":
        x = stak.pop()
        y = stak.pop()
        stak.append(str(eval(y + i + x)))
    else:
        stak.append(i)
print(stak.pop())

Solution (Python):
list=[]
for i in input().split():
    if i=='+':
        list[len(list)-2]=int(list[len(list)-2])+int(list[len(list)-1])
        list.pop()
    elif i=='-':
        list[len(list)-2]=int(list[len(list)-2])-int(list[len(list)-1])
        list.pop()
    elif i=='*':
        list[len(list)-2]=int(list[len(list)-2])*int(list[len(list)-1])
        list.pop()
    else:
        list.append(i)
print(list[0])

Solution (Python):
a=[]
for i in input().split():
	if i=='+':
		a[len(a)-2]=int(a[len(a)-2])+int(a[len(a)-1])
		a.pop()
	elif i=='-':
		a[len(a)-2]=int(a[len(a)-2])-int(a[len(a)-1])
		a.pop()
	elif i=='*':
		a[len(a)-2]=int(a[len(a)-2])*int(a[len(a)-1])
		a.pop()
	else :
		a.append(i)

print(a[0])

Solution (Python):
l=list(input().split())
a=[]
for x in l:
    if x in ['+','-','*']:
        c,b=str(a.pop()),str(a.pop())
        b+=x+c
        a+=[int(eval(b))]
    else:a+=[int(x)]
print(a.pop())

Solution (Python):

s=list(input().split())
a=[]
for x in s:
    if x in ['+','-','*']:
        c,b=str(a.pop()),str(a.pop())
        b+=x+c
        a+=[int(eval(b))]
    else:a+=[int(x)]
print(a.pop())

Solution (Python):
l=[0]*1000
c=0
s=input().split()
for i in s:
	if i=="+":
		l[c-2]=l[c-2]+l[c-1]
		c=c-1
	elif i=="-":
		l[c-2]=l[c-2]-l[c-1]
		c=c-1
	elif i=="*":
		l[c-2]=l[c-2]*l[c-1]
		c=c-1
	else:
		l[c]=int(i)
		c=c+1
print(l[0])

Solution (Python):
class Stack:
    def __init__(self, n):
        self.n = n
        self._l = [None for _ in range(self.n + 1)]
        self._top = 0

    def push(self, x):
        if self.isFull():
            raise IndexError("stack is full")
        else:
            self._top += 1
            self._l[self._top] = x

    def pop(self):
        if self.isEmpty():
            raise IndexError("pop from empty stack")
        else:
            e = self._l[self._top]
            self._l[self._top] = None
            self._top -= 1
            return e

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

    def isFull(self):
        return self._top == self.n

def poland_calculator(s):
    n = len(s)
    stack = Stack(n)
    i = 0
    while i < n:
        if s[i] == ' ':
            i += 1
            continue
        elif s[i].isdigit():
            sn = ''
            while s[i].isdigit():
                sn += s[i]
                i += 1
            stack.push(int(sn))
        else:
            b = stack.pop()
            a = stack.pop()
            if s[i] == '+':
                e = a + b
            elif s[i] == '-':
                e = a - b
            else:
                e = a * b
            stack.push(e)
            i +=1

    return stack.pop()


if __name__ == '__main__':
    s = input()
    res = poland_calculator(s)
    print(res)

Solution (Python):
inputs = input().split()
stack = []

for i in inputs:
    if i.isdigit():
        stack.append(int(i))
    else:
        b = stack.pop()
        a = stack.pop()

        if i == "+":
            ans = a + b
        elif i == "-":
            ans = a - b
        elif i == "*":
            ans = a * b
        elif i == "/":
            ans = a / b

        stack.append(ans)

print(stack.pop())

Solution (Python):
lis = input().split()
st = []
for i in lis:
  if i == "+":
    x = st.pop()
    y = st.pop()
    st.append(x+y)
  elif i == "-":
    x = st.pop()
    y = st.pop()
    st.append(y-x)
  elif i == "*":
    x = st.pop()
    y = st.pop()
    st.append(x*y)
  else:
    st.append(int(i))
print(st[0])

Solution (Python):
def solve_operator(left_num, operator, right_num):
    if operator == '+':
        return left_num + right_num
    elif operator == '-':
        return left_num - right_num
    else:
        return left_num * right_num

if __name__ == '__main__':
    stack = []
    for ele in [x for x in input().split()]:
        if ele.isdigit():
            stack.append(int(ele))
        else:
            right_num = stack.pop()
            left_num = stack.pop()
            stack.append(solve_operator(left_num, ele, right_num))
print(stack[0])

Solution (Python):
inputs = input().strip().split(' ')
stack = list()
out = list()
for i in inputs:
    if(i == '+'):
        y = int(stack.pop())
        x = int(stack.pop())
        z = x + y
        stack.append(z)
    elif(i=='-'):
        y = int(stack.pop())
        x = int(stack.pop())
        z = x - y
        stack.append(z)
    elif(i=='*'):
        y = int(stack.pop())
        x = int(stack.pop())
        z = x * y
        stack.append(z)
    else:
        stack.append(i)
print(stack[-1])

Solution (Python):
a = []
for c in input().split():
    if c == '+':
        y = a.pop(); x = a.pop()
        a.append(x+y)
    elif c == '-':
        y = a.pop(); x = a.pop()
        a.append(x-y)
    elif c == '*':
        y = a.pop(); x = a.pop()
        a.append(x * y)
    else:
        a.append(int(c))
print(a[0])

Solution (Python):
comands = input().split()
stack = []
for command in comands:
    if command == "+":
        stack = stack[:-2] + [stack[-1] + stack[-2]]
    elif command == "-":
        stack = stack[:-2] + [stack[-2] - stack[-1]]
    elif command == "*":
        stack = stack[:-2] + [stack[-1] * stack[-2]]
    else:
        stack.append(int(command))
assert len(stack) == 1
print(stack[0])

Solution (Python):


S = raw_input().split()

lst = []

for s in S:
	if s == '+':
		num1 = lst.pop()
		num2 = lst.pop()
		lst.append(num1 + num2)
	elif s == '-':
		num1 = lst.pop()
		num2 = lst.pop()
		lst.append(num2 - num1)
	elif s == '*':
		num1 = lst.pop()
		num2 = lst.pop()
		lst.append(num2 * num1)
	else:
		lst.append(int(s))

print lst[0]

Solution (Python):
poly = input().split()

stack = []

for _ in poly:

    if _ == '+':
        right = stack.pop()
        left = stack.pop()
        stack.append(left + right)

    elif _ == '-':
        right = stack.pop()
        left = stack.pop()
        stack.append(left - right)

    elif _ == '*':
        right = stack.pop()
        left = stack.pop()
        stack.append(left * right)

    else:
        stack.append(int(_))

print(stack[0])

Solution (Python):



def main():
    A = input().split()
    A.reverse()
    B = []
    
    
    while len(A) > 0:
        op = A.pop()
        if op == '+' or op == '-' or op == '*':
            y = B.pop(); x = B.pop()
            if op == '+': B.append(x + y)
            elif op == '-': B.append(x - y)
            elif op == '*': B.append(x * y)
        else:
            n = int(op); B.append(n)
    print(B[0])

if __name__ == "__main__":
    main()

Solution (Python):


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

string = list(input().split())
num_list = []
for num in string:
    if num in ope:
        b = int(num_list.pop())
        a = int(num_list.pop())
        if num == "+":
            num_list.append(a+b)
        if num == "-":
            num_list.append(a-b)
        if num == "*":
            num_list.append(a*b)
    else:
        num_list.append(num)

print(num_list[0])

Solution (Python):
input_line = input().split()
stack = []
for i in input_line:
    if i == '+':
        stack.append(stack.pop() + stack.pop())
    elif i == '-':
        a = stack.pop()
        b = stack.pop()
        stack.append(b - a)
    elif i =='*':
        stack.append(stack.pop() * stack.pop())
    else:
        stack.append(int(i))
print(stack[0])

Solution (Python):



S = []


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


def pop():
    return S.pop()


if __name__ == '__main__':
    for c in raw_input().split():
        if c == '+':
            push(pop() + pop())
        elif c == '-':
            b = pop()
            a = pop()
            push(a - b)
        elif c == '*':
            push(pop() * pop())
        else:
            push(int(c))
    print pop()

Solution (Python):
def polish(s):
    stack = []
    for x in s:
        if x == "+":
            tmp = stack[-2] + stack[-1]
            stack.pop()
            stack.pop()
            stack.append(tmp)
        elif x == "-":
            tmp = stack[-2] - stack[-1]
            stack.pop()
            stack.pop()
            stack.append(tmp)
        elif x == "*":
            tmp = stack[-2] * stack[-1]
            stack.pop()
            stack.pop()
            stack.append(tmp)
        else:
            stack.append(int(x))
    return stack[0]


s = input().split()

print(polish(s))

Solution (Python):
line = input().split()
stack = []
ans = 0
for elem in line:
    if elem in ['+', '-', '*']:

        ele2 = int(stack.pop())
        ele1 = int(stack.pop())
        if elem == '+':
            tmp = ele1 + ele2
        if elem == '-':
            tmp = ele1 - ele2
        if elem == '*':
            tmp = ele1 * ele2
        stack.append(tmp)
    else:
        stack.append(elem)
print(stack[0])

Solution (Python):
def main():
    s = input().split()
    stack = []
    for c in s:
        if c == '+':
            a = stack.pop()
            b = stack.pop()
            stack.append(a + b)
        elif c == '-':
            a = stack.pop()
            b = stack.pop()
            stack.append(b - a)
        elif c == '*':
            a = stack.pop()
            b = stack.pop()
            stack.append(a * b)
        else:
            stack.append(int(c))
    print(stack[-1])

if __name__ == '__main__':
    main()

Solution (Python):

Stack = []

A = [i for i in input().split()]

for inputData in A:
    if inputData == "+":
        x = Stack.pop()
        y = Stack.pop()
        Stack.append(x+y)

    elif inputData == "-":
        y = Stack.pop()
        x = Stack.pop()
        Stack.append(x-y)

    elif inputData == "*":
        x = Stack.pop()
        y = Stack.pop()
        Stack.append(x*y)

    else:
        Stack.append(int(inputData))

print(Stack[0])

Solution (Python):
from sys import stdin
def stdinput():
    return stdin.readline().strip()

def main():
    A = list(map(convert, stdinput().split()))
    frame = []
    while len(A) > 0:
        frame.append(A.pop())
        while can_calc(frame):
            v1 = frame.pop()
            v2 = frame.pop()
            op = frame.pop()
            if op == '+':
                frame.append(v1 + v2)
            elif op == '-':
                frame.append(v1 - v2)
            elif op == '*':
                frame.append(v1 * v2)
    print(*frame)

OPERANTS = ('+', '-', '*')
def convert(a):
    if a in OPERANTS:
        return a
    else:
        return int(a)

def can_calc(s):
    if len(s) < 3:
        return False
    else:
        return s[-3] in OPERANTS and type(s[-2]) is int and type(s[-1]) is int

if __name__ == '__main__':
    main()

Solution (Python):
s = list(input().split())

stack = []

for x in s:
    try:
        t = int(x)
        stack.append(t)
    except:
        a = stack.pop()
        b = stack.pop()
        if x == '+':
            stack.append(a+b)
        elif x == '-':
            stack.append(b-a)
        else:
            stack.append(a*b)

print(stack[0])

Solution (Python):
stack = []

for x in input().split():
    try:
        t = int(x)
        stack.append(t)
    except:
        a = stack.pop()
        b = stack.pop()
        if x == '+':
            stack.append(a+b)
        elif x == '-':
            stack.append(b-a)
        else:
            stack.append(a*b)

print(stack[0])

Solution (Python):
stack = []

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

print(stack[0])

Solution (Python):
arr = list(map(str, input().split()))
stack = []

for i in range(len(arr)):
	current = arr[i]
	if current == '+' or current == '-' or current == '*':
		n1 = stack.pop()
		n2 = stack.pop()
		if current == '+':
			n1 = n1 + n2
		elif current == '-':
			n1 = n2 - n1
		else:
			n1 = n1 * n2
		stack.append(n1)
	else:
		stack.append(int(current))
print(stack.pop())

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

stack = []

for i in range(len(arr)):
	current = arr[i]
	if current.isnumeric():
		stack.append(int(current))
	else:
		n1 = stack.pop()
		n2 = stack.pop()
		if current == '+':
			n1 = n1 + n2
		elif current == '-':
			n1 = n2 - n1
		else:
			n1 = n1 * n2
		stack.append(n1)

print(stack.pop())

Solution (Python):
stack = []
store_num = []
store_result = []

for i,c in enumerate(input().split()): 
        
        def pop_and_stack(list_,num):
                     
            list_.pop()
            list_.pop()
            list_.append(num)
            
            return list_
            
    
        if c == '+' :
            a = stack[-2]
            b = stack[-1]
            num = a+b
            pop_and_stack(stack,num)

        elif c== "-":
            a = stack[-2]
            b = stack[-1]
            num = a-b
            pop_and_stack(stack,num)
        elif c =='*':
            a = stack[-2]
            b = stack[-1]
            num = a*b
            pop_and_stack(stack,num)  
        elif c == '/':
            a = stack[-2]
            b = stack[-1]
            num = a/b
            pop_and_stack(stack,num)
        else:
            stack.append(int(c))
            
print(stack[-1])

Solution (Python):
def main():
    numbers = list(map(str, input().split()))
    stuck = []

    for c in numbers :
        if c == '+':
            a = stuck.pop(-1)
            b = stuck.pop(-1)
            stuck.append(a + b)

        elif c == '-':
            a = stuck.pop(-1)
            b = stuck.pop(-1)
            stuck.append(b - a)

        elif c == '*' :
            a = stuck.pop(-1)
            b = stuck.pop(-1)
            stuck.append(a * b)

        else :
            stuck.append(int(c))

    print(stuck[0])

if __name__ == '__main__':
    main()

Solution (Python):
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

    def is_full(self):
        return self.top >= self.__class__.MAX - 1

    def push(self, x):
        self.top += 1
        self.S[self.top] = x

    def pop(self):
        self.top -= 1
        return self.S[self.top + 1]


arr = [str(s) for s in input().split()]
stack = Stack()
for s in arr:
    if s in ["+", "-", "*"]:
        stack.push(
            eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
    else:
        stack.push(int(s))

print(stack.pop())

Solution (Python):
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

    def is_full(self):
        return self.top >= self.__class__.MAX - 1

    def push(self, x):
        self.top += 1
        self.S[self.top] = x

    def pop(self):
        self.top -= 1
        return self.S[self.top + 1]


arr = [str(s) for s in input().split()]
stack = Stack()






[stack.push(
    eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1])))) if s in ["+", "-", "*"]
    else stack.push(int(s)) for s in arr]
print(stack.pop())

Solution (Python):
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

    def is_full(self):
        return self.top >= self.__class__.MAX - 1

    def push(self, x):
        self.top += 1
        self.S[self.top] = x

    def pop(self):
        self.top -= 1
        return self.S[self.top + 1]


arr = [str(s) for s in input().split()]
stack = Stack()
[stack.push(eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
 if s in["+", "-", "*"] else stack.push(int(s)) for s in arr]
print(stack.pop())

Solution (Python):
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

    def is_full(self):
        return self.top >= self.__class__.MAX - 1

    def push(self, x):
        self.top += 1
        self.S[self.top] = x

    def pop(self):
        self.top -= 1
        return self.S[self.top + 1]


arr = [str(s) for s in input().split()]
stack = Stack()
[stack.push(eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
 if s in["+", "-", "*"] else stack.push(int(s)) for s in arr]
print(stack.pop())

Solution (Python):
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

    def is_full(self):
        return self.top >= self.__class__.MAX - 1

    def push(self, x):
        self.top += 1
        self.S[self.top] = x

    def pop(self):
        self.top -= 1
        return self.S[self.top + 1]


arr = [str(s) for s in input().split()]
stack = Stack()
[stack.push(eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
    if s in["+", "-", "*"] else stack.push(int(s)) for s in arr]
print(stack.pop())