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):
if __name__ == "__main__":
    exp = input().split()

    operator = None
    stack = []
    for e in exp:
        if e == '+':
            r = int(stack.pop())
            l = int(stack.pop())
            stack.append(l+r)
        elif e == '-':
            r = int(stack.pop())
            l = int(stack.pop())
            stack.append(l-r)
        elif e == '*':
            r = int(stack.pop())
            l = int(stack.pop())
            stack.append(l*r)
        else:
            stack.append(int(e))
        

    print(stack.pop())

Solution (Python):


lst = input().split()

stack = []
for arg in lst:

    if arg == "+":
        tmp = int(stack.pop())
        stack.append(int(stack.pop()) + tmp)
    elif arg == "-":
        tmp = int(stack.pop())
        stack.append(int(stack.pop()) - tmp)
    elif arg == "*":
        tmp = int(stack.pop())
        stack.append(int(stack.pop()) * tmp)
    else:
        stack.append(int(arg))

print(stack[0])

Solution (Python):
s = input().split()
l = []
for i in range(len(s)):
    p = ""
    if s[i].isdecimal() == False:
        x = l.pop()
        y = l.pop()
        p += y + s[i] + x
        l.append(str(eval(p)))
    else:
        l.append(s[i])
print(l[0])

Solution (Python):
from collections import deque
lst = list(input().split())
stack = deque()

for i in lst:
    if (i.isdigit()):
        stack.append(i)
    else:
        a = stack.pop()
        b = stack.pop()
        c = eval(b+i+a)
        stack.append(str(c))
print(int(stack.pop()))

Solution (Python):
import collections
d = collections.deque([])
dat = input().split()
for i in range(len(dat)):
    if dat[i] == "+":
        d.append(int(d.pop()) + int(d.pop()))
    elif dat[i] == "-":
        d.append(-int(d.pop()) + int(d.pop()))
    elif dat[i] == "*":
        d.append(int(d.pop()) * int(d.pop()))
    else:
        d.append(int(dat[i]))
print(d.pop())

Solution (Python):
import re

def main():
    stack = []
    input_str = list(map(str,input().split()))
    for i in range(len(input_str)):
        ch = input_str[i]
        if ch == "+":
            stack[-2] = stack[-2] + stack[-1]
            stack.pop() 
        elif ch == "-":
            stack[-2] = stack[-2] - stack[-1]
            stack.pop() 
        elif ch == "*":
            stack[-2] = stack[-2] * stack[-1]
            stack.pop()
        
        else:
            stack.append(int(ch))
    print(stack[0])


    
if __name__ == '__main__':
    main()

Solution (Python):
S = list(input().split())
stack = []
for s in S:
    if s.isnumeric():
        stack.append(int(s))
    else:
        n2 = stack.pop(len(stack) - 1)
        n1 = stack.pop(len(stack) - 1)
        if s == '+':
            stack.append(n1 + n2)
        elif s == '-':
            stack.append(n1 - n2)
        elif s == '*':
            stack.append(n1 * n2)
print(stack[0])

Solution (Python):
import operator
operator = {"+": operator.add, "-": operator.sub, "*": operator.mul}

def initialize():
    top = 0

def empty_or_not():
    return top == 0

def full_or_not():
    return top >= len(s) - 1

def push(x):
    global top
    if full_or_not():
        raise ValueError("Error: stack is full!")
    top += 1
    s[top] = x

def pop():
    global top
    if empty_or_not():
        raise ValueError("Error: stack is empty!")
    top -= 1
    return s[top+1]



s = [None] * 10**3
top = 0

rpn = list(input().split())

for i in range(len(rpn)):
    if rpn[i] == "+" or rpn[i] == "-" or rpn[i] == "*":
        b = int(pop())
        a = int(pop())
        
        a_ops_b = operator[rpn[i]](a, b)
        
        push(a_ops_b)
        
        
    else:
        
        push(rpn[i])
        
        
        
print(s[top])

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

Solution (Python):
stack = []
for x in input().split():
	if x=="+":
		stack.append(str(int(stack.pop()) + int(stack.pop())))
	elif x=="-":
		stack.append(str(- int(stack.pop()) + int(stack.pop())))
	elif x=="*":
		stack.append(str(int(stack.pop()) * int(stack.pop())))
	else:
		stack.append(x)
print(stack.pop())

Solution (Python):

a = [str(i) for i in input().split()]

class Stack:
  def __init__(self, length):
    self.stack = [0]*length
    self.top = 0
  def push(self, x):
    self.top +=1
    self.stack[self.top] = x
  def pop(self):
    self.top -=1 
    return self.stack[self.top+1]

s = Stack(1000)

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

print(s.stack[s.top],end='\n')

Solution (Python):
def reverse_polish_notation(x):
    operands = ["+", "-", "*"]
    number_stack = []
    for i in x:
        if i in operands:
            num2 = number_stack.pop()
            num1 = number_stack.pop()
            ans = eval("{}{}{}".format(num1, i, num2))
            number_stack.append(ans)
        else:
            number_stack.append(i)
    return ans
            
if __name__ == "__main__":
    x = input().split()
    print(reverse_polish_notation(x))

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

for elem in equation_list:
    if elem.isnumeric():
        stack.append(int(elem))
    else:
        number2 = stack.pop()
        number1 = stack.pop()
        answer = eval('number1' + elem + 'number2')
        stack.append(answer)

print(f'{stack[0]}')

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

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

print(stack.pop())

Solution (Python):
l = list(map(str, input().split()))
m = []
for i in range(len(l)):
    m.append(l[i])
    x = l[i]
    if x == "+":
        m.pop()
        tmp = int(m.pop()) + int(m.pop())
        m.append(tmp)
    if x == "-":
        m.pop()
        tmp = -int(m.pop()) + int(m.pop())
        m.append(tmp)
    if x == "*":
        m.pop()
        tmp = int(m.pop()) * int(m.pop())
        m.append(tmp)
    
print(int(m.pop()))

Solution (Python):
inputs = input().split(' ')

class Stack:
    def __init__(self, N):
        self.stack_size = N
        self.stack = []
    def push(self, x):
        if x in ['+', '-', '*']:
            term2 = '{}({})'.format(x, self.pop())
            calc_str = '({}){}'.format(self.pop(), term2)
            self.stack.append(str(eval(calc_str)))
        else:
            self.stack.append(x)
    def pop(self):
        return self.stack.pop(-1)
    def isEmpty(self):
        return len(self.stack) == 0
    def isFull(self):
        return len(self.stack) == self.stack_size

stack = Stack(200)
for A in inputs:
    stack.push(A)
print(stack.pop())

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

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

print(stack.pop())

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

Solution (Python):

class Stack:
    def __init__(self, Max=50000):
        self.top = 0
        self.Max = Max
        self.S = []

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

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

    def push(self, x):
        if self.isFull():
            assert ValueError('max')
        self.top += 1
        self.S.append(x) 

    def pop(self):
        if self.isEmpty():
            assert ValueError('Empty')
        self.top -= 1
        
        return self.S.pop()


formula = list(map(str, input().split()))
S = Stack()

for f in formula:
    
    if f == '+':
        a = int(S.pop())
        b = int(S.pop())
        S.push(a + b)

    elif f == '-':
        a = int(S.pop())
        b = int(S.pop())
        S.push(b - a)

    elif f == '*':
        a = int(S.pop())
        b = int(S.pop())
        S.push(a * b)
    else:
        S.push(int(f))
        
print(S.pop())

Solution (Python):

stack = []

for i in input().split():
    
    if i in '+-*':
        val0 = stack.pop()
        val1 = stack.pop()
        stack.append(str(eval(val1 + i + val0)))
    else:
        stack.append(i)

print(stack[0])

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

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

    def pop(self):
        result = self.stack[-1]
        del self.stack[-1]
        return result
    
def main():
    formula = input().split()
    stack = Stack()
    operator_list = ["+", "-", "*"] 
    a = 0 
    b = 0 

    for i in range(len(formula)):
        if formula[i] in operator_list:
            a = stack.pop()
            b = stack.pop()
            ans = eval(str(b) + str(formula[i]) + str(a))
            stack.push(ans)
        else:
            stack.push(formula[i])

    print(stack.pop())
        


if __name__ == "__main__":
    main()

Solution (Python):
def push(x):
    global top
    top += 1
    stack[top] = x
    
def pop():
    global top
    top -= 1
    return stack[top + 1]

input_list = input().split()
len_input_list = len(input_list)
stack = [0] * 105
top = 0

for i in range(len_input_list):
    if input_list[i] == '+':
        a = pop()
        b = pop()
        push(a + b)
    elif input_list[i] == '-':
        a = pop()
        b = pop()
        push(b - a)
    elif input_list[i] == '*':
        a = pop()
        b = pop()
        push(a * b)
    else:
        push(int(input_list[i]))
        
res = pop()

print(res)

Solution (Python):
op = {"+": lambda a,b: b + a, "-": lambda a,b: b - a, "*": lambda a,b: b * a}
stack = []

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

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

for i in range(0, len(a)):
    if a[i].isdigit():
        stack.append(int(a[i]))
    else:
        b = stack.pop()
        c = stack.pop()
        if a[i] == '+':
            stack.append(c+b)
        elif a[i] == '-':
            stack.append(c-b)
        elif a[i] == '*':
            stack.append(c*b)

print(stack.pop())

Solution (Python):
formula = input().split(' ')
stack = []
for target in formula:
    if target == '+':
        operand1 = stack.pop()
        operand2 = stack.pop()
        result = int(operand2) + int(operand1)
        stack.append(result)
    elif target == '-':
        operand1 = stack.pop()
        operand2 = stack.pop()
        result = int(operand2) - int(operand1)
        stack.append(result)
    elif target == '*':
        operand1 = stack.pop()
        operand2 = stack.pop()
        result = int(operand2) * int(operand1)
        stack.append(result)
    else:
        stack.append(target)
print(stack[0])

Solution (Python):
from collections import deque


def main():
    elements = deque(input().split())
    operands = deque()
    operators = {"+", "-", "*"}
    while elements:
        element = elements.popleft()
        if element in operators:
            operand2 = operands.pop()
            operand1 = operands.pop()
            result = eval(operand1 + element + operand2)
            operands.append(str(result))
        else:
            operands.append(element)
    print(int(operands.pop()))


if __name__ == "__main__":
    main()

Solution (Python):
from collections import deque

l = input().split()

st = deque()
for k in l:
    if k in "+*-":
        n2 = st.pop()
        n1 = st.pop()
        st.append(str(eval(n1 + k + n2)))
    else:
        st.append(k)

print(st[0])

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

calc = []
c = int(0)

ans = int(0)

for i in nlist:
	
	if i == '+':
		for j in range(len(calc)-1,len(calc)-3,-1):
			ans += calc.pop(j)
		calc.append(int(ans))

	elif i == '-':
		ans -= calc.pop(len(calc)-1)
		ans += calc.pop(len(calc)-1)
		calc.append(int(ans))
	elif i == '*':
		ans = calc.pop(len(calc)-2) * calc.pop(len(calc)-1)
		calc.append(int(ans))

	else:
		calc.append(int(i))

	ans = 0
print(calc[0])

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

stack = []

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

print(stack.pop())

Solution (Python):
stack = []
operator = {
        '+': (lambda x, y: x + y),
        '-': (lambda x, y: x - y),
        '*': (lambda x, y: x * y),
        '/': (lambda x, y: float(x) / y)
    }
for i in input().split():
    if i .isdecimal() == True:
        stack.append(int(i))
    elif i in operator.keys():
        y = stack.pop()
        x = stack.pop()
        c = operator[i](x,y)
        stack.append(c)
print(stack[0])

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

stack = [0] * 200
top = 0

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

def push(x):
    global top
    top += 1
    stack[top] = x

for i in s:
    if i == '+':
        a = int(pop())
        b = int(pop())
        push(a+b)
    elif i == '-':
        a = int(pop())
        b = int(pop())
        push(b-a)
    elif i == '*':
        a = int(pop())
        b = int(pop())
        push(a*b)
    else:
        push(int(i))

print(pop())

Solution (Python):
A = input().split() 
B = [] 
for s in A:
    if s in ['+', '-', '*']:
        b, a = str(B.pop()), str(B.pop())
        B.append(int(eval(a + s + b)))
    else:
        B.append(int(s))

print(B[0])

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

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

for i in range(len(ls)):
    if str.isdecimal(ls[i]):
        stack.append(ls[i])
    elif ls[i] == "+":
        f2 = int(stack.pop(-1))
        f1 = int(stack.pop(-1))
        stack.append(f1 + f2)
    elif ls[i] == "-":
        f2 = int(stack.pop(-1))                                                          
        f1 = int(stack.pop(-1))
        stack.append(f1 - f2) 
    elif ls[i] == "*":
        f2 = int(stack.pop(-1))                                                          
        f1 = int(stack.pop(-1))
        stack.append(f1 * f2)
    else:
        print("エラー ls[i]:",ls[i],"\nスタック:",stack)

print(stack[0])

Solution (Python):
def remove(ary, num):
    ary.pop(-1)
    ary.pop(-1)
    ary.append(num)

line = input().split()
stack = []
for letters in line:
    if letters == "+":
        remove(stack, stack[-2]+stack[-1])
    elif letters == "-":
        remove(stack, stack[-2]-stack[-1])
    elif letters == "*":
        remove(stack, stack[-2]*stack[-1])
    elif letters == "/":
        remove(stack, stack[-2]/stack[-1])
    else:
        stack.append(int(letters))

print(stack[0])

Solution (Python):
class UnderflowError(Exception):
    pass


class Mystack:

    def __init__(self, _max):
        self.S = [None for _ in range(_max)]
        self.top = 0
        self.max = _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 OverflowError
        self.top += 1
        self.S[self.top] = x

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


stack = Mystack(200)

for n in input().split():
    try:
        n = int(n)
    except ValueError:
        pass
    else:
        stack.push(n)
        continue
    if n == '+':
        stack.push(stack.pop() + stack.pop())
    elif n == '-':
        stack.push(- stack.pop() + stack.pop())
    elif n == '*':
        stack.push(stack.pop() * stack.pop())

print(stack.pop())

Solution (Python):
init_list = list(map(lambda x: int(x) if x.isdigit() else x, input().split()))

num1 = 0
num2 = 0

def calc(n1, n2, a):
    if a == '+':
        return n1 + n2
    elif a == '-':
        return n1 - n2
    elif a == '*':
        return n1 * n2

list = []

for l in init_list:
    if l == '+' or l == '-' or l == '*':
        a = list.pop(-1)
        b = list.pop(-1)
        list.append(calc(b, a, l))

    else:
        list.append(l)

print(list[0])

Solution (Python):
input_str = list(map(str,input().split()))
operand_list = ['+', '-', '*', '/']
stack = []
for str in input_str:
    if str in operand_list:
        top = stack.pop()
        top1 = stack.pop()
        if str == '+':
            stack.append(top + top1)
        elif str == '-':
            stack.append(top1 - top)
        elif str == '*':
            stack.append(top1 * top)
        elif str == '/':
            stack.append(top1 / top)
    else:
        stack.append(int(str))


print(stack[0])

Solution (Python):
formula = input().split()
stack = []
for f in formula:
    if f in ["+", "-", "*"]:
        if f == "+":
            s = stack[-2] + stack[-1]
        elif f == "-":
            s = stack[-2] - stack[-1]
        else:
            s = stack[-2] * stack[-1]
        stack.pop(-1)
        stack.pop(-1)
        stack.append(s)
    else:
        stack.append(int(f))

print(stack[0])

Solution (Python):
class MyStack():
    def __init__(self):
        self.stack = []
    def push(self, item):
        self.stack.append(item)
    def pop(self):
        if len(self.stack) == 0:
            return None
        result = self.stack[-1]
        del self.stack[-1]
        return result

s = list(input().split())
n = len(s)

mystack = MyStack()
for i in range(n):
    if s[i] == "+" or s[i] == "-" or s[i] == "*":
        x = mystack.pop()
        y = mystack.pop()
        if s[i] == "+":
            r = y + x
        elif s[i] == "-":
            r = y - x
        elif s[i] == "*":
            r = y * x
        mystack.push(r)
        if (i + 1) == n:
            print(mystack.pop())
    else:
        mystack.push(int(s[i]))

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

stack = []
operand = ['+', '-', '*']

for i in range(len(inputList)):
  if (inputList[i] in operand):
    arg1 = int(stack.pop())
    arg2 = int(stack.pop())
    if (inputList[i] == '+') :
      temp = arg2 + arg1
    elif (inputList[i] == '-') :
      temp = arg2 - arg1
    elif (inputList[i] == '*') :
      temp = arg2 * arg1
    stack.append(temp)
  else :
    stack.append(inputList[i])
print (stack.pop())

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

m = [0]

n = len(l)

for i in range(n):
  if l[i].isdigit() == True:
    m.append(l[i])
  else:
    a = int(m.pop())
    b = int(m.pop())
    if l[i] == "+":
      c = a+b
      m.append(c)
    elif l[i] == "-":
      c = b-a
      m.append(c)
    else:
      c = a*b
      m.append(c)
print(m[1])

Solution (Python):
from collections import deque
import re

gp = deque(input().split())
que = deque([])
ans = 0


while len(gp) > 0:
    e = gp.popleft()
    if re.match('\d', e): 
        que.append(int(e))
    else: 
        r = que.pop() 
        l = que.pop()
        if   e == '+':
            que.append(l + r)
        elif e == '-':
            que.append(l - r)
        elif e == '*':
            que.append(l * r)
        elif e == '/':
            que.append(l / r)
print(que.pop())

Solution (Python):

A = list(input().split())
S = []*100
def push(i):
    S.append(i)
def pop(S):
    n = S.pop()
    return(n)

cnt = len(A)

for i in range(cnt):
    if A[i] == "+" :
        a = int(pop(S))
        b = int(pop(S))
        out = a + b

        push(out)

    elif A[i] == "-" :
        a = int(pop(S))
        b = int(pop(S))
        out = b - a
        push(out)


    elif A[i] == "*" :
        a = int(pop(S))
        b = int(pop(S))
        out = a * b
        push(out)
 
    else:
        push(int(A[i]))


print(pop(S))

Solution (Python):
class Stack:

    def __init__(self):
        self.top = 0
        self.stack = [0] * 1000

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

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

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


def main():
    A = input().split(' ')
    S = Stack()

    for a in A:

        if a == '+':
            y = S.pop()
            x = S.pop()
            S.push(x + y)
        elif a == '-':
            y = S.pop()
            x = S.pop()
            S.push(x - y)
        elif a == '*':
            y = S.pop()
            x = S.pop()
            S.push(x * y)
        else:
            S.push(int(a))

    print(S.pop())


if __name__ == "__main__":
    main()

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

Solution (Python):
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    data = sc.strarr()
    stack = []
    for d in data:
        if d == '+':
            stack.append(stack.pop() + stack.pop())
        elif d == '-':
            stack.append(((-1) * stack.pop()) + stack.pop())
        elif d == '*':
            stack.append(stack.pop() * stack.pop())
        else:
            stack.append(int(d))
    print(stack[0])


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


main()

Solution (Python):
S = input().split()
L = []
for s in S:
    try:
        f = int(s)
        L.append(s)
    except ValueError:
        p = L.pop()
        q = L.pop()
        L.append(eval(str(q) + s + str(p)))
print(L[0])

Solution (Python):

class Stack:
    def __init__(self):
        self.top = 0
        self.length = 0
        self.S = []
        
    def initialize(self):
        self.top = 0
        
    def isEmpty(self):
        return self.top == 0
        
    def push(self, x):

        
        
        
        if self.length > self.top:
            self.S[self.top] = x
        else:
            self.S.append(x)
        self.top += 1      
        self.length = len(self.S)     
            
    def pop(self):
        if self.isEmpty():
            print("error")
            return
        self.top -= 1
        return self.S[self.top] 
        
        
        
"""
stack = Stack()
stack.push(1)
stack.push(2)
stack.push(3)
result = stack.pop()
"""

result = 0
a = 0
b = 0
stack = Stack()
A = list(input().split())
N = len(A)
for i in range(N):
    if A[i] == "+": 
        a = stack.pop()
        b = stack.pop()
        stack.push(a + b)
        
    elif A[i] == "-": 
        a = stack.pop()
        b = stack.pop()
        stack.push(-a + b)
        
    elif A[i] == "*": 
        a = stack.pop()
        b = stack.pop()
        stack.push(a * b)
    
    else:
        stack.push(int(A[i]))
    
    

print(stack.S[stack.top-1])

Solution (Python):
S = input().split(' ')

num_stack = []
for char in S:
    if char == '+':
        num2 = num_stack.pop(-1)
        num1 = num_stack.pop(-1)
        num_stack.append(num1+num2)
    elif char == '-':
        num2 = num_stack.pop(-1)
        num1 = num_stack.pop(-1)
        num_stack.append(num1-num2)
    elif char == '*':
        num2 = num_stack.pop(-1)
        num1 = num_stack.pop(-1)
        num_stack.append(num1*num2)
    else:
        num_stack.append(int(char))
print(num_stack[0])

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

    def isEmpty(self):
        return len(self.stack) == 0
    
    def push(self, item):
        self.stack.append(item)
    
    def pop(self):
        if len(self.stack) != 0:
            return self.stack.pop()

operand = Stack()
ope = input().split()
for i in range(0, len(ope)):
    if ope[i] == "+":
        a = operand.pop()
        b = operand.pop()
        operand.push(a+b)
    elif ope[i] == "-":
        a = operand.pop()
        b = operand.pop()
        operand.push(b-a)
    elif ope[i] == "*":
        a = operand.pop()
        b = operand.pop()
        operand.push(a*b)
    else:
        operand.push(int(ope[i]))

print(operand.pop())

Solution (Python):

temp=input().split(" ")
stack=[]
for item in temp:
  if item.isdecimal():
    stack.append(item)
  else:
    a=stack.pop()
    b=stack.pop()
    c=str(eval(b+item+a))
    stack.append(c)

print(stack[0])

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

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

    def pop(self):
        return self.l.pop(-1)



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

print(stack.pop())

Solution (Python):
import re
A = input()
B = []
c,A = A.split(" ",1)
while(1):
    if c == "+":
        temp1 = int(B.pop())
        temp2 = int(B.pop())
        B.append(temp1+temp2)
    elif c == "-":
        temp1 = int(B.pop())
        temp2 = int(B.pop())
        B.append(temp2-temp1)
    elif c == "*":
        temp1 = int(B.pop())
        temp2 = int(B.pop())
        B.append(temp1*temp2)
    else:
        B.append(c)
    if len(A) ==1 :
        c = A
        A = ""
    elif len(A) == 0:
        break
    else:
        c,A = A.split(" ",1)
print(*B)

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

Solution (Python):
array = input().split()
stack = []
for e in array:
    if e in '+-*':
        ope2 = stack.pop()
        ope1 = stack.pop()
        if e == '+':
            stack.append(ope1 + ope2)
        if e == '-':
            stack.append(ope1 - ope2)
        if e == '*':
            stack.append(ope1 * ope2)
    else:
        stack.append(int(e))
print(stack[0])

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    ww=input().split()
    stack=[]
    for w in ww:
        if w.isdecimal():
            stack.append(w)
        else:
            b=stack.pop()
            a=stack.pop()
            stack.append(str(eval(a+w+b)))
    print(stack[0])

    

main()

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

for a in A:
    if a in ["+", "-", "*"]:
        y = B.pop()
        x = B.pop()
        
        if a == "+":
            B.append(x + y)
        elif a == "-":
            B.append(x - y)
        else:
            B.append(x * y)         
    else:
        B.append(int(a))
        
print(B[0])

Solution (Python):
stack = []
for i in input().split():
    if i.isdecimal():
        stack.append(i)
    elif i in ('+', '-', '*'):
        y, x = stack.pop(), stack.pop()
        res = eval(x+i+y)
        stack.append(str(res))

print(stack[0])

Solution (Python):
def isInt(n):
    try:
        int(n)
    except:
        return False
    return True

S = input().split()
stack = []
for s in S:
    if isInt(s):
        stack.append(int(s))
    else:
        if s == "+":
            stack.append(stack.pop(-2) + stack.pop(-1))
        elif s == "-":
            stack.append(stack.pop(-2) - stack.pop(-1))
        elif s == "*":
            stack.append(stack.pop(-2) * stack.pop(-1))
print(stack.pop(-1))

Solution (Python):

from collections import deque
a=deque([])

for i in input().split() :
    if i == "+":
        x=a.pop()
        y=a.pop()
        a.append(x+y)
    elif i == "-":
        x=a.pop()
        y=a.pop()
        a.append(y-x)
    elif i == "*":
        x=a.pop()
        y=a.pop()
        a.append(x*y)
    else:
        a.append(int(i))

print(a[0])

Solution (Python):
def operator( arg1, arg2, op):
    if op=='+': return arg1+arg2
    elif op=='-': return arg1-arg2
    elif op=='*': return arg1*arg2
    else: return arg1/arg2

    
def main():
    description=list(input().split())
    stack=[]
    for st in description:
        if st.isdigit():
            stack.append(st)

        else:
            op=st
            arg2=int(stack.pop())
            arg1=int(stack.pop())
            ans=operator( arg1, arg2, op)
            stack.append(ans)

    print(stack.pop())

if __name__=='__main__':
    main()