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):
operators = {
	"+": (lambda a, b: a + b),
	"-": (lambda a, b: a - b),
	"*": (lambda a, b: a * b),
	"/": (lambda a, b: a / b)
}

def evaluate(tokens):
	stack = []
	for token in tokens:
		if token in operators:
			arg2 = stack.pop()
			arg1 = stack.pop()
			result = operators[token](arg1, arg2)	
			stack.append(result)
		else:
			stack.append(int(token))
	  
	return stack.pop()
  
expression = input()

tokens = expression.split()

print(evaluate(tokens))

Solution (Python):

operators = {
"+": (lambda a, b: a + b),
"-": (lambda a, b: a - b),
"*": (lambda a, b: a * b),
"/": (lambda a, b: a / b)
}

def evaluate(tokens):
    
    stack = []
    
    
    for token in tokens:
    
        if token in operators:
            
            arg2 = stack.pop()
            arg1 = stack.pop()
            result = operators[token](arg1, arg2)
            stack.append(result)
        else:
            
            stack.append(int(token))
    
    return stack.pop()
  

expression = input()


tokens = expression.split()


print(evaluate(tokens))

Solution (Python):

def pol_calc(symbols):
    stack = []
    for s in symbols:
        if s.isdigit():
            stack.append(int(s))
        elif s == '+':
            y = stack.pop()
            x = stack.pop()
            stack.append(x + y)
        elif s == '-':
            y = stack.pop()
            x = stack.pop()
            stack.append(x - y)
        elif s == '*':
            y = stack.pop()
            x = stack.pop()
            stack.append(x * y)
    return stack.pop()

if __name__ == "__main__":
    symbols = input().split()
    print(pol_calc(symbols))

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

Solution (Python):
class Node:
    def __init__(self, value, prev):
        self.value = value
        self.prev = prev


class Stack:
    def __init__(self):
        self.last = None

    def add(self, value):
        next_node = Node(value, self.last)
        self.last = next_node

    def pop(self):
        if not self.last:
            return -1
        v = self.last.value
        self.last = self.last.prev
        return v


stack = Stack()
s = input().split()
for c in s:
    if c in '+-*':
        a = stack.pop()
        b = stack.pop()
        if c == '+':
            stack.add(a + b)
        elif c == '-':
            stack.add(b - a)
        else:
            stack.add(a * b)
    else:
        stack.add(int(c))

print(stack.pop())

Solution (Python):
l=list(input().split())
s=[]
for c in l:

    
    if c=='+':
        b=s.pop()
        a=s.pop()
        s.append(a+b)
    elif c=='-':
        b=s.pop()
        a=s.pop()
        s.append(a-b)
    elif c=='*':
        b=s.pop()
        a=s.pop()
        s.append(a*b)
    else:
        s.append(int(c))
    


print(s.pop())

Solution (Python):

a = list(input().split())



r = int()
stack = []
for i in a:
    if i.isdigit():
        stack.append(int(i))
    elif i == "+": 
        
        r = stack[-1] + stack[-2]
        stack.pop()
        stack.pop()
        stack.append(r)
    elif i == "-":
        
        r = stack[-2] - stack[-1]
        stack.pop()
        stack.pop()
        stack.append(r)
    elif i == "*":
        
        r = stack[-1] * stack[-2]
        stack.pop()
        stack.pop()
        stack.append(r)
print(stack[0])

Solution (Python):
from operator import add,sub,mul

formula = input().split()
stack = []
op = {"+":add, "-":sub, "*":mul}

for i in formula:
    if i.isdigit():
        stack.append(int(i))
    else:
        op2 = stack.pop()
        op1 = stack.pop()
        stack.append(op[i](op1, op2))

print(stack[0])

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

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

print(stack[0])

Solution (Python):
import sys
A = list(map(str,input().split()))
B=[]
for i in range(len(A)):
  c=0
  if A[i].isdecimal():
    B.append(int(A[i]))
  else:
    if A[i]=='+':
      c=B.pop(-2)+B.pop(-1)
      B.append(c)
    elif A[i]=='-':
      c=B.pop(-2)-B.pop(-1)
      B.append(c)
    elif A[i]=='*':
      c=B.pop(-2)*B.pop(-1)
      B.append(c)
print(B[-1])

Solution (Python):
from collections import deque
l=deque()
a=list(input().split())
for i in range(len(a)):
    if a[i]=="+":
        b=l.pop()
        c=l.pop()
        l.append(b+c)
    elif a[i]=="-":
        b=l.pop()
        c=l.pop()
        l.append(c-b)
    elif a[i]=="*":
        b=l.pop()
        c=l.pop()
        l.append(b*c)
    else:
        l.append(int(a[i]))

print(l[0])

Solution (Python):
if __name__ == '__main__':
    exp = list(map(str, input().split()))
    tmp = []
    for e in exp:
        if e == '+':
            tmp.append(tmp.pop() + tmp.pop())
        elif e == '-':
            tmp.append(-tmp.pop() + tmp.pop())
        elif e == '*':
            tmp.append(tmp.pop()*tmp.pop())
        else:
            tmp.append(int(e))
    print(tmp[0])

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

for s in S:
  if s.isdigit():
    ope.append(s)
  else:
    a = int(ope.pop())
    b = int(ope.pop())
    if s == '+':
      ope.append(a + b)
    elif s == '-':
      ope.append(b - a)
    else:
      ope.append(a * b)
print(ope[0])

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

s =  []
for i in c:
    if i == "*":
        y = s.pop(-1)
        x = s.pop(-1)
        s.append(x*y)
    elif i == "-":
        y = s.pop(-1)
        x = s.pop(-1)
        s.append(x-y)
    elif i == "+":
        y = s.pop(-1)
        x = s.pop(-1)
        s.append(x+y)
    else:
        s.append(int(i))

print(s.pop(-1))

Solution (Python):
class stack:
    def __init__(self):
        self.s=[0 for _ in range(250)]
        self.top=0


    def push(self,x):
        self.s[self.top]=int(x)
        if(self.top< len(self.s)):
            self.top=self.top+1
        else:
            print('over flow')

    def pop(self):
        val=self.s[self.top-1]
        if (self.top > 0):
            self.top=self.top-1
        else:
            print('under flow')
        return val

inputs=input().split()

s=stack()
for _ in inputs:
    if _ !='+' and _ != '-' and _ !='*':
        s.push(_)
        
    elif _ =='+':
        x=s.pop()+s.pop()
        s.push(x)
        
    elif _ == '-':
        x=-s.pop()+s.pop()
        s.push(x)
        
    elif _=='*':
        x=s.pop()*s.pop()
        s.push(x)
        

print(s.pop())

Solution (Python):
l = list(input().split())
s = []
for p in l:
    if p == '+':
        s.append(s.pop() + s.pop())
    elif p == '-':
        s.append(-(s.pop() - s.pop()))
    elif p == '*':
        s.append(s.pop() * s.pop())
    else:
        s.append(int(p))

print(s.pop())

Solution (Python):
A = input().split()
n = len(A)
B = []

for i in range(n):
    B.append(A[i])
    if B[-1] == '+':
        B[-3] = int(B[-3]) + int(B[-2])
        B.pop()
        B.pop()
    elif B[-1] == '-':
        B[-3] = int(B[-3]) - int(B[-2])
        B.pop()
        B.pop()
    elif B[-1] == '*':
        B[-3] = int(B[-3]) * int(B[-2])
        B.pop()
        B.pop()

print(B[0])

Solution (Python):
def test():

	formula = input().split()
	stack = []

	for element in formula:

		if element == '+':

			a = stack.pop()
			b = stack.pop()
			stack.append(b+a)

		elif element == '-':

			a = stack.pop()
			b = stack.pop()
			stack.append(b-a)
			

		elif element == '*':

			a = stack.pop()
			b = stack.pop()
			stack.append(b*a)

		else:
			stack.append(int(element))


	print(stack.pop())

if __name__ == "__main__":
	test()

Solution (Python):
A = map(str,input().split())
s = []

for a in A:
    if a in ['+', '-', '*']:
        b = s.pop()
        c = s.pop()
        
        if a == '+':
            s.append(b+c)
        elif a == '-':
            s.append(c-b)
        else:
            s.append(b*c)
    else:
        s.append(int(a))

ans = s.pop()
print(ans)

Solution (Python):

in_list = []

register = []


if __name__ == "__main__":
    in_list = input().split(" ")
    for i in range(len(in_list)):
        if in_list[i].isdecimal():
            in_list[i] = int(in_list[i])

    for i in range(len(in_list)):
        if type(in_list[i]) is int:
            register.append(in_list[i])
        elif in_list[i] == "+":
            temp = register.pop() + register.pop()
            register.append(temp)
        elif in_list[i] == "-":
            temp = -register.pop() + register.pop()
            register.append(temp)
        elif in_list[i] == "*":
            temp = register.pop() * register.pop()
            register.append(temp)


    answer = register.pop()

    print(answer)

Solution (Python):
stack=[]
for i in input().split():
	if i.isdecimal():
		stack.append(i)
	else:
		a=stack.pop()
		b=stack.pop()
		stack.append(str(eval(b+i+a)))
print(stack[0])

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

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

Solution (Python):
strings = []

for string in input().strip().split():
  if string.isdigit():
    strings.append(string)
  else:
    strings.append(str(eval(strings.pop(-2) + string + strings.pop())))

print(strings.pop())

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

def Revpol(A):
    S = [] 
    for i in range(len(A)):
        if A[i] != '+' and A[i] != '-' and A[i] != '*':
            S.append(int(A[i]))
        elif len(S)>=2:
            if A[i] == '+':
                tmp = S[len(S)-2] + S[len(S)-1]
                S.pop()
                S.pop()
                S.append(tmp)
            elif A[i] == '-':
                tmp = S[len(S)-2] - S[len(S)-1]
                S.pop()
                S.pop()
                S.append(tmp)
            elif A[i] == '*':
                tmp = S[len(S)-2] * S[len(S)-1]
                S.pop()
                S.pop()
                S.append(tmp)
        else:
            print("error1")
            break
    if len(S) == 1:
        print(S[0])
    else:
        print("error2")

Revpol(A)

Solution (Python):
def getInput():
    a = input().split()
    return a

def convNum(s):
    if s.isdigit():
        return int(s)
    else:
        return s
def initArr(len_a):
    return 0, [0 for i in range(len_a+1)]

def initTop():
    return 0

def isEmpty(top):
    return top == 0
    
def isFull(top, len_a):
    return top >= len_a-1

def pop(top, a):
    if isEmpty(top):
        print("Err: Empty")
    val = a[top]
    top -= 1
    return top, val

def push(top, a, val):
    if isFull(top, len(a)):
        print("Err: Full")
    top += 1
    a[top] = val
    return top

a = getInput()
a = [convNum(i) for i in a]

top, s = initArr(len(a))
for i in range(len(a)):
    top = push(top, s, a[i])
    if type(a[i]) == str:
        top, val = pop(top, s)
        top, val_b = pop(top, s)
        top, val_a = pop(top, s)
        if val == "+":
            top = push(top, s, val_a + val_b)
        elif val == "-":
            top = push(top, s, val_a - val_b)
        elif val == "*":
            top = push(top, s, val_a * val_b)        
        else:
            print("Error: Invalid Operand")
print(s[1])

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

ls=[]
ln=len(a)

for i in range(ln):
    if a[i]=="+":
        ls[-2]+=ls[-1]
        ls.pop()
    elif a[i]=="-":
        ls[-2]-=ls[-1]
        ls.pop()
    elif a[i]=="*":
        ls[-2]*=ls[-1]
        ls.pop()
    else:
        ai=int(a[i])
        ls.append(ai)
        
print(ls[-1])

Solution (Python):
stack = [0]
top = 0

def push(x):
    global top
    top += 1
    stack.insert(top, x)

def pop():
    global top
    top -= 1
    return stack[top+1]

def main():
    input_line = input().split(" ")
    for i in input_line:
        if i == "+":
            a = pop()
            b = pop()
            push(a+b)
        elif i == "-":
            b = pop()
            a = pop()
            push(a-b)
        elif i == "*":
            a = pop()
            b = pop()
            push(a*b)
        else:
            push(int(i))
    
    print(pop())

if __name__ == '__main__':
    main()

Solution (Python):
class Stack():
  def __init__(self, max=100):
    self.max = max
    self.top = 0
    self.arr = [None for _ in range(max)]
  
  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.arr[self.top] = x

  def pop(self):
    if self.is_empty():
      raise IndexError()
    self.top -= 1
    return self.arr[self.top + 1]

s = input().split()

stack = Stack(300)

for x in s:
  if x == "+":
    a = int(stack.pop())
    b = int(stack.pop())
    stack.push(b + a)
  elif x == "-":
    a = int(stack.pop())
    b = int(stack.pop())
    stack.push(b - a)
  elif x == "*":
    a = int(stack.pop())
    b = int(stack.pop())
    stack.push(b * a)
  else:
    stack.push(int(x))

print(stack.pop())

Solution (Python):
A = input().split(' ')
S = []
operator = ''
operand_1 = ''
operand_2 = ''

def operate(operator, operand_1, operand_2):
    if operator == '+':
        return operand_1 + operand_2
    
    elif operator == '-':
        return operand_1 - operand_2
    
    elif operator == '*':
        return operand_1 * operand_2

for i in range(len(A)):
    v = A[i]
    if v == '+' or v == '-' or v == '*':
        S.append(v)
        operator = S.pop()
        operand_2 = int(S.pop())
        operand_1 = int(S.pop())
        S.append(operate(operator, operand_1, operand_2))
        
    else:
        S.append(v)

print(str(S[0]))

Solution (Python):
st = []
for c in input().split():
    if c in "+-*":
        v2 = st.pop()
        v1 = st.pop()
        st.append(str(eval(v1 + c + v2)))
    else:
        st.append(c)
print(st[0])

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

Solution (Python):
st = []
for c in input().split():
    if c in "+-*":
        v2 = st.pop()
        v1 = st.pop()
        st.append(str(eval(v1 + c + v2)))
    else:
        st.append(c)
print(st[0])

Solution (Python):
class MyStack:
    def __init__(self):
        self._lst = []

    def push(self, val):
        self._lst.append(val)

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

line_list = input().split()

stk = MyStack()

for t in line_list:
    if t == "+":
        stk.push(stk.pop() + stk.pop())
    elif t == "-":
        temp = stk.pop()
        stk.push(stk.pop() - temp)
    elif t == "*":
        stk.push(stk.pop() * stk.pop())
    else:
        stk.push(int(t))

print(stk.pop())

Solution (Python):
st = []

for c in input().split():
    if c in "+-*":
        v2 = st.pop()
        v1 = st.pop()
        st.append(str(eval(v1 + c + v2)))
    else:
        st.append(c)
        
print(st[0])

Solution (Python):
from enum import Enum
import sys
import math
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
line = list(map(str,input().split()))
 

S = []
 
for tmp_ch in line:
 
    if tmp_ch in ['+','-','*']:
        b = int(S.pop())
        a = int(S.pop())
 
        if tmp_ch == '+':
            S.append(a+b)
        elif tmp_ch == '-':
            S.append(a-b)
        else:
            S.append(a*b)
    else:
        S.append(tmp_ch)
 
print("%d"%(S[0]))

Solution (Python):
from enum import Enum
import sys
import math
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
line = list(map(str,input().split()))
 

S = []
 
for tmp_ch in line:
 
    if tmp_ch in ['+','-','*']:
        b = int(S.pop())
        a = int(S.pop())
 
        if tmp_ch == '+':
            S.append(a+b)
        elif tmp_ch == '-':
            S.append(a-b)
        else:
            S.append(a*b)
    else:
        S.append(tmp_ch)
 
print("%d"%(S[0]))

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

print(stack[0])

Solution (Python):
mathlist=list(map(str,input().split()))
resultlist = []
for ope in mathlist:
    if ope == "+":
        number1 = int(resultlist.pop(-1))
        number2 = int(resultlist.pop(-1))
        result = number1 + number2
        resultlist.append(result)
    elif ope =="*":
        number1 = int(resultlist.pop(-1))
        number2 = int(resultlist.pop(-1))
        result = number1 * number2
        resultlist.append(result)
    elif ope =="-":
        number1 = int(resultlist.pop(-1))
        number2 = int(resultlist.pop(-1))
        result = number2 - number1
        resultlist.append(result)
    else:
        result = ope
        resultlist.append(result)
print(*resultlist)

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=list(input().split())
Max=101
numstack=[0]*Max
top=0
def pop():
  if isEmpty():
    print('error')
  global top
  global numstack
  top-=1
  return numstack[top+1]

def push(x):
  if isFull():
    print('error')
  global top
  top+=1
  global numstack
  numstack[top]=x

def isEmpty():
  return top==0

def isFull():
  return top==Max-1

for i in range(len(A)):
  if A[i]=='+':
    push(pop()+pop())
  elif A[i]=='-':
    push(-pop()+pop())
  elif A[i]=='*':
    push(pop()*pop())
  else:
    push(int(A[i]))
print(numstack[1])

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

for x in s:
    if x not in "+-*":
        a += [int(x)]
    else:
        c = str(a.pop())
        b = str(a.pop())
        b += x + c
        a += [int(eval(b))]

print(a.pop())

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

for item in input_list:
  try:
    num = int(item)
    stack.append(num)

  except ValueError:
    num2 = stack.pop()
    num1 = stack.pop()

    if item == '+':
      stack.append(num1 + num2)
    elif item == '-':
      stack.append(num1 - num2)
    elif item == '*':
      stack.append(num1 * num2)
    elif item == '/':
      stack.append(num1 / num2)

print(stack.pop())

Solution (Python):
class Stack():
    def __init__(self, n):
        self.S = [0 for i in range(n)]
        self.top = 0
        self.Max = n + 1

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

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

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

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


l = list(input().split())
n = len(l)
st = Stack(n)

for i in l:
    if i != "+" and i != "-" and i != "*":
        st.push(int(i))
    else:
        b = st.pop()
        a = st.pop()
        if i == "+":
            st.push(a+b)
        elif i == "-":
            st.push(a-b)
        elif i == "*":
            st.push(a*b)

print(st.S[1])

Solution (Python):
def porland(M):
    for i in range(len(M)):
        if len(M)==1:
            print(' '.join(map(str, M)))
        elif M[i]=='+':
            M[i] = int(M[i-2])+int(M[i-1])
            M.pop(i-2)
            M.pop(i-2)
            porland(M)
            break
        elif M[i]=='-':
            M[i] = int(M[i-2])-int(M[i-1])
            M.pop(i-2)
            M.pop(i-2)
            porland(M)
            break
        elif M[i]=='*':
            M[i] = int(M[i-2])*int(M[i-1])
            M.pop(i-2)
            M.pop(i-2)
            porland(M)
            break
        else :
            M[i] = int(M[i])

if __name__ == '__main__':
    N = list(input().split())
    porland(N)

Solution (Python):
from typing import List


def stack_push(elems: List[int], value: int) -> None:
    elems.append(value)


def stack_pop(elems: List[int]) -> int:
    value = elems.pop()
    return value


def exec_operation(elems: List[int], operation: str) -> None:
    value2 = elems.pop()
    value1 = elems.pop()
    if ("+" == operation):
        elems.append(value1 + value2)
    elif ("-" == operation):
        elems.append(value1 - value2)
    elif ("*" == operation):
        elems.append(value1 * value2)


if __name__ == "__main__":
    stack: List[int] = []
    input_commands = input().split(" ")

    for command in input_commands:
        if (str.isdecimal(command)):
            stack_push(stack, int(command))
        else:
            exec_operation(stack, command)

    print(f"{stack_pop(stack)}")

Solution (Python):
class Stack:
    
    def __init__(self):
        self.li = []
        self.top = 0
    def push(self,value):
        
        self.li.append(int(value))
        self.top += 1
    def pop(self):
        self.top -= 1
        return self.li.pop()
    def isEmpty(self):
        return len(li)==0
    def __str__(self):
        return str(self.li[0])

l = list(map(str,input().split()))

save = Stack()

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

for i in l:
    
    if i in symble:
        b = save.pop()
        a = save.pop()
        if i=="+":
            save.push(a + b)
        elif i=="-":
            save.push(a - b)
        else:
            save.push(a * b)
    else:
        save.push(i)
else:
    print(save)

Solution (Python):
if __name__ == '__main__':
    data = input().split()
    stack = []

    for i in data:
        if i == '+':
            rhv = stack.pop()
            lhv = stack.pop()
            stack.append(lhv + rhv)
        elif i == '-':
            rhv = stack.pop()
            lhv = stack.pop()
            stack.append(lhv - rhv)
        elif i == '*':
            rhv = stack.pop()
            lhv = stack.pop()
            stack.append(lhv * rhv)
        else:
            stack.append(int(i))
    
    print(stack.pop())

Solution (Python):
class Stack:
    def __init__(self, data=[]):
        self.data = data

    def push(self, x):
        self.data.append(x)
        return self.data

    def pop(self):
        if len(self.data) == 0:
            return "Stack is Empty"
        else:
            return self.data.pop()


stack = Stack()
formula = list(map(str, input().split()))
for i in range(len(formula)):
    if formula[i] == '+':
        b = stack.pop()
        a = stack.pop()
        stack.push(a+b)
    elif formula[i] == '-':
        b = stack.pop()
        a = stack.pop()
        stack.push(a-b)
    elif formula[i] == '*':
        b = stack.pop()
        a = stack.pop()
        stack.push(a*b)
    else:
        stack.push(int(formula[i]))

print(stack.pop())

Solution (Python):
from collections import deque


def main():
    sequence = [e for e in input().split(' ')]
    stack = deque()
    for e in sequence:
        if '+' == e:
            a = stack.pop()
            b = stack.pop()
            stack.append(a + b)
        elif '-' == e:
            a = stack.pop()
            b = stack.pop()
            stack.append(b - a)
        elif '*' == e:
            a = stack.pop()
            b = stack.pop()
            stack.append(a * b)
        else:
            stack.append(int(e))
    print(stack.pop())


if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque
from sys import stdin
L = stdin.readline().rstrip().split()
d = deque()
for s in L:
    if s.isdigit():
        d.append(int(s))
    else:
        a = d.pop()
        b = d.pop()
        if s == '+':
            d.append(b+a)
        elif s == '-':
            d.append(b-a)
        elif s == '*':
            d.append(b*a)
print(d[0])

Solution (Python):
eq=list(map(str,input().split()))
n=len(eq)
ans=[]
for a in range(0,n):
    if eq[a]!="+" and eq[a]!="-" and eq[a]!="*":
        ans.append(int(eq[a]))
    elif eq[a]=="+":
        ans[-2]+=ans[-1]
        ans.pop()
    elif eq[a]=="-":
        ans[-2]=ans[-2]-ans[-1]
        ans.pop()
    elif eq[a]=="*":
        ans[-2]*=ans[-1]
        ans.pop()
print(ans[0])

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

Solution (Python):
class Stack:
    def __init__(self, n):
        self.top = 0
        self.A = [0 for i in range(n)]
        self.n = n

    def init(self):
        self.top = 0

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

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

    def push(self, x):
        if not self.is_full():
            self.top += 1
            self.A[self.top] = x

    def pop(self):
        if not self.is_empty():
            x = self.A[self.top]
            self.top -= 1
            return x


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

Solution (Python):
"""


 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())


 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  


a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    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])

Solution (Python):
from collections import deque
s=input().split()
q=deque([])
for i in range(len(s)):
    if s[i]=="+":
        a=q.pop()
        b=q.pop()
        calc=b+"+"+a
        q.append(str(eval(calc)))
    elif s[i]=='-':
        a=q.pop()
        b=q.pop()
        calc=b+"-"+a
        q.append(str(eval(calc)))
    elif s[i]=='*':
        a=q.pop()
        b=q.pop()
        calc=b+"*"+a
        q.append(str(eval(calc)))
    else:
        q.append(s[i])
print(*q)

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

S = []
 
for tmp_ch in line:
 
    if tmp_ch in ['+','-','*']:
        b = int(S.pop())
        a = int(S.pop())
 
        if tmp_ch == '+':
            S.append(a+b)
        elif tmp_ch == '-':
            S.append(a-b)
        else:
            S.append(a*b)
    else:
        S.append(tmp_ch)
 
print("%d"%(S[0]))

Solution (Python):
class Cell:
    def __init__(self, value):
        self.value = value
        self.next = None


class Stack:
    def __init__(self):
        self.top = None

    def push(self, d):
        new = Cell(d)
        new.next = self.top
        self.top = new

    def pop(self):
        if self.top is None:
            print('Stack Under Flow!!')
            return
        else:
            t = self.top.value
            p = self.top
            self.top = self.top.next
            del(p)
            return t

l = list(input().split())
st = Stack()
for i in l:
    if i == '-':
        t1 = st.pop()
        t2= st.pop()
        st.push(t2-t1)
    elif i=='*':
        t1 = st.pop()
        t2= st.pop()
        st.push(t1*t2)
    elif i == '+':
        t1 = st.pop()
        t2 = st.pop()
        st.push(t1 + t2)
    else:
        st.push(int(i))
print(st.pop())

Solution (Python):
st = []
for c in input().split():
    if c in "+-*":
        v2 = st.pop()
        v1 = st.pop()
        st.append(str(eval(v1 + c + v2)))
    else:
        st.append(c)
print(st[0])

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

while len(S)>1:
    for s in S:
        if s=="+":
            s1=stack.pop(-1)
            s2=stack.pop(-1)
            stack.append(s1+s2)
        elif s=="-":
            s1=stack.pop(-1)
            s2=stack.pop(-1)
            stack.append(s2-s1)
        elif s=="*":
            s1=stack.pop(-1)
            s2=stack.pop(-1)
            stack.append(s1*s2)
        else:
            stack.append(int(s))
    S=stack
print(S[0])

Solution (Python):
from collections import deque
S = input().split()
stack = deque([])
for s in S:
    if s == "+":
        s1 = stack.pop()
        s2 = stack.pop()
        stack.append(s1+s2)
    elif s == "-":
        s1 = stack.pop()
        s2 = stack.pop()
        stack.append(s2-s1)
    elif s == "*":
        s1 = stack.pop()
        s2 = stack.pop()
        stack.append(s1*s2)
    elif s == "/":
        s1 = stack.pop()
        s2 = stack.pop()
        stack.append(s1/s2)
    else:
        stack.append(int(s))
print(stack[0])