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):
rows = input().split()


ans = []
for i in rows:
    if i == "+":
        a = ans.pop()
        b = ans.pop()
        ans.append(a + b)
    elif i == "-":
        a = ans.pop()
        b = ans.pop()
        ans.append(b - a)
    elif i == "*":
        a = ans.pop()
        b = ans.pop()
        ans.append(a * b)
    else:
        ans.append(int(i))

print(' '.join(map(str, ans)))

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

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

print(q[0])

Solution (Python):
import sys

class Stack:
    def __init__(self, max):
        self.max = max
        self.stack = list(range(max))
        self.top = 0

    def push(self, value):
        if self.top == self.max:
            raise IndexError('?????????????????????????????????')

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

    def pop(self):
        if self.top == 0:
            raise IndexError('??????????????????????????¨??????')

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

def main():
    expr = sys.stdin.readline().strip().split(' ')
    stack = Stack(100)
    
    for i in expr:
        if i == '*' or i == '+' or i == '-':
            n1 = stack.pop()
            n2 = stack.pop()
            ans = eval(n2 + i + n1)
            stack.push(str(ans))
        else:
            stack.push(i)

    print(stack.pop())
    
if __name__ == '__main__':
    main()

Solution (Python):
import sys

def main():
    expr = sys.stdin.readline().strip().split(' ')
    stack = []
    
    for i in expr:
        if i == '*' or i == '+' or i == '-':
            n1 = stack.pop()
            n2 = stack.pop()
            ans = eval(n2 + i + n1)
            stack.append(str(ans))
        else:
            stack.append(i)

    print(stack.pop())
    
if __name__ == '__main__':
    main()

Solution (Python):
ri = raw_input().split()
stack = []
for i in xrange(len(ri)):
  if ri[i] == "+":
    b = stack.pop()
    a = stack.pop()
    stack.append(str(int(a)+int(b)))
  elif ri[i] == "-":
    b = stack.pop()
    a = stack.pop()
    stack.append(str(int(a)-int(b)))
  elif ri[i] == "*":
    b = stack.pop()
    a = stack.pop()
    stack.append(str(int(a)*int(b)))
  else:
    stack.append(ri[i])
print stack.pop()

Solution (Python):



input_list = input().split()
stack = list()
for i in input_list:
    if i.isdigit():
        stack.append(int(i))
    else:
        b = stack.pop()
        a = stack.pop()
        if i == '+':
            stack.append(a + b)
        elif i == '-':
            stack.append(a - b)
        elif i == '*':
            stack.append(a * b)
print(stack.pop())

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

Solution (Python):
import re

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

for c in _l:
    if re.match(r"(\+|\-|\/|\*)", c):
        f = stack.pop()
        z = stack.pop()
        stack.append(eval("{}{}{}".format(z, c, f)))
    else:
        stack += [c]

print(stack[0])

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

array = []

for word in arguments:
    if word == '-':
        s1 = array.pop()
        s2 = array.pop()
        array.append(s2-s1)
    elif word == '*':
        s1 =array.pop()
        s2 = array.pop()
        array.append(s1*s2)
    elif word == '+':
        s1 = array.pop()
        s2 = array.pop()
        array.append(s1+s2)
    else:
        array.append(int(word))


print(array.pop())

Solution (Python):

def Stack(A):
    p=[]
    symbol=["+","-","*"]
    for i in range(len(A)):
        if A[i] in symbol:
            if A[i]=="+":
                p.append(p.pop()+p.pop())
            elif A[i]=="-":
                p.append(-p.pop()+p.pop())
            else:
                p.append(p.pop()*p.pop())
        else:
            p.append(int(A[i]))
    
    print(p[0])
  
if __name__=="__main__":
    a=input()
    A=a.split(" ")
    Stack(A)

Solution (Python):
command = raw_input().split(" ")
stack = []

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

print(stack.pop())

Solution (Python):
data = list(input().split(" "))
stack = []
for d in data:
    if d == '+':
        stack.append(stack.pop() + stack.pop())
    elif d == '-':
        stack.append(- stack.pop() + stack.pop())
    elif d == '*':
        stack.append(stack.pop() * stack.pop())
    else:
        stack.append(int(d))
print(stack[0])

Solution (Python):
x = input().split()
A = []
for i in x:
    try:
        A.append(int(i))
    except:
        b = A.pop()
        a = A.pop()
        if i == '+':
            A.append(a + b)
        if i == '-':
            A.append(a - b)
        if i == '*':
            A.append(a * b)
print(A.pop())

Solution (Python):




class Solution:
    @staticmethod
    def stack_polish_calc():
        
        
        calc_func = ('+', '-', '*')
        array = [str(x) for x in input().split()]
        
        result = []
        for i in range(len(array)):
            if array[i] not in calc_func:
                result.append(str(array[i]))
            else:
                calc = array[i]
                arg_2 = result.pop()
                arg_1 = result.pop()
                result.append(str(eval(''.join((str(arg_1), calc, str(arg_2))))))

        print(*result)


if __name__ == '__main__':
    solution = Solution()
    solution.stack_polish_calc()

Solution (Python):




class Solution:
    @staticmethod
    def stack_polish_calc():
        
        
        calc_func = ('+', '-', '*')
        array = [str(x) for x in input().split()]
        
        result = []
        for i in range(len(array)):
            if array[i] not in calc_func:
                result.append(str(array[i]))
            else:
                calc = array[i]
                arg_2 = result.pop()
                arg_1 = result.pop()
                result.append(str(eval(str(arg_1) + calc + str(arg_2))))

        print(*result)


if __name__ == '__main__':
    solution = Solution()
    solution.stack_polish_calc()

Solution (Python):



def calc(n,m,ope):
	n = int(n)
	m = int(m)
	rslt = 0
	if ope == "+":
		rslt = n + m
	elif ope == "-":
		rslt = n - m
	elif ope == "*":
		rslt = n * m
	else:
		try:
			raise ValueError("invalid operator!")
		except ValueError as e:
			print(e)
	return rslt
		
def main():
	formula = raw_input().split()
	stack = []
	for f in formula:
		if f == '+' or f == '-' or f == '*':
			pop1 = stack.pop()
			pop2 = stack.pop()
			rslt = calc(pop2, pop1,f)
			stack.append(rslt)
		else:
			stack.append(f)
		
	print stack.pop()






if __name__ == '__main__':
	main()

Solution (Python):





def rpn(formula):
    stack = Stack()
    
    for d in formula:
        if d == "+":
            stack.push(stack.pop() + stack.pop())
        elif d == "-":
            stack.push(-stack.pop() + stack.pop())
        elif d == "*":
            stack.push(stack.pop() * stack.pop())
        else:
            stack.push(int(d))
            
    return stack.pop()

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

    def push(self, d):
        
        self.data.append(d)
        
    def pop(self):
        
        r = self.data[-1]
        self.data = self.data[:-1]
        return r
    
def main():
    formula = input().split()
    print(rpn(formula))
    
if __name__ == "__main__":
    main()

Solution (Python):

def solve(tokens):
    stack = []

    for token in tokens:
        if token == "+":
            t1 = stack.pop()
            t2 = stack.pop()
            stack.append(t1 + t2)
        elif token == "-":
            t1 = stack.pop()
            t2 = stack.pop()
            stack.append(t2 - t1)
        elif token == "*":
            t1 = stack.pop()
            t2 = stack.pop()
            stack.append(t1 * t2)
        else:
            stack.append(int(token))

    return stack.pop()


def main():
    print solve(raw_input().split())


if __name__ == "__main__":
    main()

Solution (Python):

def solve(tokens):
    stack = []

    for token in tokens:
        if token == "+":
            t1 = stack.pop()
            t2 = stack.pop()
            stack.append(t1 + t2)
        elif token == "-":
            t1 = stack.pop()
            t2 = stack.pop()
            stack.append(t2 - t1)
        elif token == "*":
            t1 = stack.pop()
            t2 = stack.pop()
            stack.append(t1 * t2)
        else:
            stack.append(int(token))

    return stack.pop()


def main():
    print solve(raw_input().split())


if __name__ == "__main__":
    main()

Solution (Python):
class MyStack(object):
    """stack class

    Attributes:
        stack: stack
    """

    def __init__(self):
        self.stack = []

    def pop(self):
        """pop method

        Returns:
            popped object
        """
        return self.stack.pop()

    def push(self, value):
        """ push method
        Args:
            value: value to be pushed
        """
        self.stack.append(value)


sequence = raw_input().split()
operators = {"*": "*", "+": "+", "-": "-"}
stack = MyStack()
for s in sequence:
    if s in operators:
        value2 = stack.pop()
        value1 = stack.pop()
        stack.push(str(eval(value1 + operators[s] + value2)))
    else:
        stack.push(s)

print(stack.pop())

Solution (Python):
class MyStack(object):
    """stack class

    Attributes:
        stack: stack
    """

    def __init__(self):
        self.stack = []

    def pop(self):
        """pop method

        Returns:
            popped object
        """
        return self.stack.pop()

    def push(self, value):
        """ push method
        Args:
            value: value to be pushed
        """
        self.stack.append(value)


sequence = raw_input().split()
operators = {"*": "*", "+": "+", "-": "-"}
stack = MyStack()
for s in sequence:
    if s in operators:
        value2 = stack.pop()
        value1 = stack.pop()
        stack.push(str(eval(value1 + operators[s] + value2)))
    else:
        stack.push(s)

print(stack.pop())

Solution (Python):
class MyStack(object):
    """stack class

    Attributes:
        stack: stack
    """

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

    def pop(self):
        """pop method

        Returns:
            popped object
        """
        if self.top - 1 < 0:
            print("Stack Underflow")
        else:
            value = self.stack[self.top]
            self.stack[self.top] = 0
            self.top -= 1
            return value

    def push(self, value):
        """ push method
        Args:
            value: value to be pushed
        """
        if self.top + 1 >= len(self.stack):
            print("Stack Overflow")
        else:
            self.top += 1
            self.stack[self.top] = value

sequence = raw_input().split()
operators = {"*": "*", "+": "+", "-": "-"}
stack = MyStack()
for s in sequence:
    if s in operators:
        value2 = stack.pop()
        value1 = stack.pop()
        stack.push(str(eval(value1 + operators[s] + value2)))
    else:
        stack.push(s)

print(stack.pop())

Solution (Python):


A=raw_input().split()
B=[]
for i in A:
	if i.isdigit():
		B.append(i)
	else:
		if i=="+":
			B[-1]=str(int(B[-1])+int(B[-2]))
			del B[-2]
		elif i=="-":
			B[-1]=str(int(B[-2])-int(B[-1]))
			del B[-2]
		elif i=="*":
			B[-1]=str(int(B[-1])*int(B[-2]))
			del B[-2]
print B[0]

Solution (Python):
def do_calc(data):
    from collections import deque
    s = deque()  
    while data:
        elem = data[0]
        data = data[1:]
        if elem == '+' or elem == '-' or elem == '*':
            a = s.pop()
            b = s.pop()
            if elem == '+':
                s.append(b + a)
            elif elem == '-':
                s.append(b - a)
            elif elem == '*':
                s.append(b * a)
        else:
            s.append(int(elem))
    return s.pop()


if __name__ == '__main__':
    
    data = [x for x in input().split(' ')]
    

    
    result = do_calc(data)

    
    print(result)

Solution (Python):
def do_calc(data):
    from collections import deque
    s = deque()  
    while data:
        elem = data[0]  

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

        
        data = data[1:]
    return s.pop()


if __name__ == '__main__':
    
    data = [x for x in input().split(' ')]
    

    
    result = do_calc(data)

    
    print(result)

Solution (Python):



''' ???????????? '''





operators = {"+": lambda x, y: x + y,
             "-": lambda x, y: x - y,
             "*": lambda x, y: x * y,
             "/": lambda x, y: x / y}


def compute(A):
    stack = []

    for i in range(len(A)):
        
        if isinstance(A[i], str):
            op_right = stack.pop()
            op_left = stack.pop()
            
            stack.append(operators[A[i]](op_left, op_right))

        
        if isinstance(A[i], int):
            stack.append(A[i])

    return stack[-1]

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

    for i in range(len(A)):
        if not A[i] in ['+', '-', '*', '/']:
            A[i] = int(A[i])

    print(compute(A))

Solution (Python):
class MyStack:
    def __init__(self, size):
        self.stack = [0 for i in range(size)]
        self.size = size
        self.top = 0

    def initialize(self):
        self.top = 0

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

    def pop(self):
        ret = self.stack[self.top]
        self.stack[self.top] = 0
        self.top -= 1
        return ret

    def is_empth(self):
        if not self.is_full():
            return True
        return False

    def is_full(self):
        if self.size-1 is self.top:
            return True
        return False


def main(expr):
    stack = MyStack(1000)
    for i, elm in enumerate(expr):
        if expr[i] is '+':
            a = stack.pop()
            b = stack.pop()
            stack.push(int(a) + int(b))
        elif expr[i] is '-':
            a = stack.pop()
            b = stack.pop()
            stack.push(int(b) - int(a))
        elif expr[i] is '*':
            a = stack.pop()
            b = stack.pop()
            stack.push(int(a) * int(b))
        else:
            stack.push(elm)
    return stack.pop()


if __name__ == '__main__':
    expr = [str(s) for s in input().split()]
    print(main(expr))

Solution (Python):


stack = list()

def deal_expression(x):
    if x.isdigit():
        stack.append(int(x))
    else:
        a = stack.pop()
        b = stack.pop()
        if x == '+':
            stack.append(b + a)
        elif x == '-':
            stack.append(b - a)
        elif x == '*':
            stack.append(b * a)
        elif x == '/':
            stack.append(b / a)

for x in input().split():
    deal_expression(x)
print(stack[0])

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

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

for i in input().split():
    if i in ope:
        stack.append(ope[i](stack.pop(),stack.pop()))
    else:
        stack.append(int(i))

print(stack[0])

Solution (Python):
operators = ['+', '-', '*', '/']
stack = list(input().split())



def calc(ope):
    c = stack.pop()
    a = c if c not in operators else calc(c)
    c = stack.pop()
    b = c if c not in operators else calc(c)
    return str(eval(b+ope+a))

print(calc(stack.pop()))

Solution (Python):

def revPoland(expr):
    stack = []

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

    return stack.pop()

expr = input().split()

print(revPoland(expr))

Solution (Python):
operand = input().split()
stack = []
for op in operand:
    if op.isdigit():
        stack.append(op)
    else:
        val1 = stack.pop()
        val2 = stack.pop()
        stack.append(str(eval("("+val2+")" + op + "("+val1+")")))
print (stack[0])

Solution (Python):
operand = input().split()
stack = []
for op in operand:
    if op.isdigit():
        stack.append(op)
    else:
        val1 = stack.pop()
        val2 = stack.pop()
        stack.append(str(eval(val2 + op + val1)))
print (stack[0])

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

stack = []

for c in A:
    if c == '+':
        rhs = stack.pop()
        lhs = stack.pop()
        stack.append(lhs + rhs)
    elif c == '-':
        rhs = stack.pop()
        lhs = stack.pop()
        stack.append(lhs - rhs)
    elif c == '*':
        rhs = stack.pop()
        lhs = stack.pop()
        stack.append(lhs * rhs)
    else:
        stack.append(int(c))


print(stack.pop())

Solution (Python):
def solve(l):
    e = l.pop()
    if e == '*':
        return solve(l) * solve(l)
    elif e == '+':
        return solve(l) + solve(l)
    elif e == '-':
        return - solve(l) + solve(l)
    else:
        return int(e)

formula = input().split()
print(solve(formula))

Solution (Python):
def main():
    A = input().split()
    l = []
    operator = None
    for character in A:
        if character in ["+", "-", "*"]:
            if character == "+":
                l.append(l.pop()+l.pop())
            elif character == "-":
                l.append(-l.pop()+l.pop())
            else:
                l.append(l.pop()*l.pop())
        else:
            l.append(int(character))
    print(l[0])




if __name__ == "__main__":
    import os
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main()

Solution (Python):
rp = input().split()
n = len(rp)-1
i = 1
while n:
    if rp[i] in ('+', '-', '*'):
        i -= 1
        rp[i], rp[i+1] = rp[i+1], rp[i]
        rp[i-1] = str(eval(''.join(rp[i-1:i+2])))
        del rp[i:i+2]
        n -= 2
    else:
        i += 1
print(*rp)

Solution (Python):
s = []
for e in input().split():
    s.append(e if e.isdigit() else str(eval(s.pop(-2)+e+s.pop())))
print(*s)

Solution (Python):
s=[]
p=s.pop
for e in input().split():
 s+=[e if e.isdigit() else str(eval(p(-2)+e+p()))]
print(*s)

Solution (Python):
s=[]
p=s.pop
for e in input().split():
 s+=[str(eval(p(-2)+e+p()))if e in'*+-'else e]
print(*s)

Solution (Python):
print((lambda s:[s.append(str(eval(s.pop(-2)+c+s.pop())) if c in "+-*" else c)or s[-1]for c in input().split()][-1])([0]))

Solution (Python):
print((lambda s:[s.append(str(eval(s.pop(-2)+c+s.pop()))if c in"+-*"else c)or s[-1]for c in input().split()][-1])([]))

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

Solution (Python):
def stack():
    A = list(input().split())
    lst = []
    
    def add(a, b):
        return b + a
    
    def sub(a, b):
        return b - a
        
    def mul(a, b):
        return b * a
    
    def div(a, b):
        return b / a
        
    def calc(lst, f):
        return lst.append(f(lst.pop(), lst.pop()))
    
    for i in A:
        if i == '+':
            calc(lst, add)
        elif i == '-':
            calc(lst, sub)
        elif i == '*':
            calc(lst, mul)
        elif i == '/':
            calc(lst, div)
        else: 
            lst.append(int(i))
    
    print(*lst)
    
stack()

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):
data = input().split()
data.reverse()
stk = []

for i in range(len(data)):
    tmp = data.pop()
    if tmp == '+':
        tmp1 = stk.pop()
        tmp2 = stk.pop()
        stk.append(int(tmp2)+int(tmp1))
    elif tmp == '-':
        tmp1 = stk.pop()
        tmp2 = stk.pop()
        stk.append(int(tmp2)-int(tmp1))
    elif tmp == '*':
        tmp1 = stk.pop()
        tmp2 = stk.pop()
        stk.append(int(tmp2) * int(tmp1))
    else:
        stk.append(tmp)

print(stk.pop())

Solution (Python):

class stack(object):
    def __init__(self):
        self.container = [] 
        self.topIndex = -1
    def push(self, elem):
        self.container.append(elem)
        self.topIndex += 1
    def pop(self):
        if self.topIndex > -1:
            elem = self.container[self.topIndex]
            del self.container[self.topIndex]
            self.topIndex -= 1
            return elem
        else:
            return None

def calc(ins):
    stk = stack()
    try:
        for sin in ins:
            if sin == '+':
                stk.push(stk.pop() + stk.pop())
            elif sin == '-':
                a, b = stk.pop(), stk.pop()
                stk.push(b - a)
            elif sin == '*':
                stk.push(stk.pop() * stk.pop())
            elif sin == '/':
                a, b = stk.pop(), stk.pop()
                stk.push(b / a)
            else:
                stk.push(int(sin))
        return stk.pop()
    except:
        print 'Bad Expr'

print calc(raw_input().split(' '))

Solution (Python):
n = input().split()
stack = []
for i in range(len(n)):
    if n[i] not in ("+","-","*","/"):
        stack.append(int(n[i]))
    else:
        if n[i] == "+":
            stack.append(stack.pop()+stack.pop()) 
        elif n[i] == "-":
            a = stack.pop()
            stack.append( stack.pop() - a) 
        elif n[i] == "*":
            stack.append(stack.pop()*stack.pop()) 
        elif n[i] == "/":
            a = stack.pop()
            stack.append( stack.pop() / a) 
print(stack[0])

Solution (Python):
def calc(formura):
    if formura[-1] == '+':
        return int(formura[-3]) + int(formura[-2])
    elif formura[-1] == '-':
        return int(formura[-3]) - int(formura[-2])
    elif formura[-1] == '*':
        return int(formura[-3]) * int(formura[-2])
    elif formura[len(formura)-1] == '/':
        return int(formura[-3]) / int(formura[-2])


formura = [i for i in input().split()]
stack = []

for i in range(len(formura)):
    if formura[i] == '+' or formura[i] == '-' or formura[i] == '*' or formura[i] == '-':
        stack.append(formura[i])
        result = calc(stack)
        for j in range(3):
            stack.pop(-1)
        stack.append(result)
    else:
        stack.append(formura[i])

print(stack[0])

Solution (Python):
if __name__ == "__main__":
    stack =[]
    ope = {"+": lambda a, b: b + a, "-": lambda a, b: b - a, "*": lambda a, b: b * a}
    for x in input().split():
        if x in ope:
            stack.append(ope[x](stack.pop(),stack.pop()))
        else:
            stack.append(int(x))
    print(stack[-1])

Solution (Python):

o = list()
top = -1
for s in input().split():
    if s.isdigit():
        o.append(int(s))
        top += 1
    else:
        if s is "+":
            n = o[top]+o[top-1]
            o.pop(top)
            top-=1
            o.pop(top)
            top-=1
            o.append(n)
            top+=1
        if s is "-":
            n = o[top-1] - o[top]
            o.pop(top)
            top -= 1
            o.pop(top)
            top -= 1
            o.append(n)
            top+=1
        if s is "*":
            n = o[top]*o[top-1]
            o.pop(top)
            top -= 1
            o.pop(top)
            top -= 1
            o.append(n)
            top+=1


print(o[0])

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

print(s[0])

Solution (Python):
data = input().split()
stack = []
for i in data:
    try:
        stack.append(int(i))
    except:
        b = stack.pop()
        a = stack.pop()
        if i == "+":
            stack.append(a+b)
        if i == "-":
            stack.append(a-b)
        if i == "*":
            stack.append(a*b)
print(stack[0])

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):
line = input().split()
stack = []
for i in range(len(line)):
    obj = line[i]
    if obj.isnumeric():
        stack.append(obj)
    else:
        b = int(stack.pop(-1))
        a = int(stack.pop(-1))
        if obj == '+':
            stack.append(a+b)
        elif obj == '-':
            stack.append(a-b)
        else:
            stack.append(a*b)
print(stack[0])

Solution (Python):
A = input().split()
G = []
j = 0
G.append(int(A[0]))

for i in range(1, len(A)):
	if A[i] == "+":
		G[j-1] += G[j]
		G.pop()
		j -= 1
	elif A[i] == "-":
		G[j-1] -= G[j]
		G.pop()
		j -= 1
	elif A[i] == "*":
		G[j-1] *= G[j]
		G.pop()
		j -= 1
	else:
		j += 1
		G.append(int(A[i]))

print(G[0])

Solution (Python):
calc = input().split(" ")

nums = []
subTotal = 0

for i in range(len(calc)):
    if calc[i].isdigit():
        nums.append(int(calc[i]))
    else:
        b = nums.pop()
        a = nums.pop()

        if calc[i] == "+":
            subTotal = a + b
        elif calc[i] == "-":
            subTotal = a - b
        elif calc[i] == "*":
            subTotal = a * b
        
        nums.append(subTotal)

print(" ".join(map(str,nums)))

Solution (Python):
ops={"+": lambda a, b: b + a,
        "-": lambda a, b: b - a,
        "*": lambda a, b: b * a,
        "/": lambda a, b: flaot(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):


import functools
N = input().split()
stack=[]

for i in N:
    if i.isdigit():
        stack.append(int(i))
        
    else:
        key=0
        if i=="+":
            p2=stack.pop()
            p1=stack.pop()
            stack.append(p1+p2)
        elif i=="-":
            p2=stack.pop()
            p1=stack.pop()
            stack.append(p1-p2)
        elif i=="*":
            p2=stack.pop()
            p1=stack.pop()
            stack.append(p1*p2)
print(stack[0])

Solution (Python):
operand = ["+", "-", "*"]
src = [x if x in operand else int(x) for x in  input().split(" ")]
stack = []

for s in src:
    if isinstance(s, int):
        stack.append(s)
    elif s == "+":
       b, a = stack.pop(), stack.pop()
       stack.append(a+b)

    elif s == "-":
        b, a = stack.pop(), stack.pop()
        stack.append(a-b)
    elif s == "*":
        b, a = stack.pop(), stack.pop()
        stack.append(a*b)

print(stack[0])

Solution (Python):
operand = ["+", "-", "*"]
src = [x if x in operand else int(x) for x in  input().split(" ")]
stack = []

for s in src:
    if isinstance(s, int):
        stack.append(s)
        continue

    b, a = stack.pop(), stack.pop()

    if s == "+":
       stack.append(a+b)
    elif s == "-":
        stack.append(a-b)
    elif s == "*":
        stack.append(a*b)

print(stack[0])

Solution (Python):


import sys
import os


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

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

Solution (Python):
Sum = input().split()
cou = 1
while len(Sum) != 1 :
    cou += 1
    if Sum[cou] == '+' :
        del Sum[cou]
        Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) + int(Sum.pop(cou - 2)))
        cou -= 2
    elif Sum[cou] == '-' :
        del Sum[cou]
        Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) - int(Sum.pop(cou - 2)))
        cou -= 2
    elif Sum[cou] == '*' :
        del Sum[cou]
        Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) * int(Sum.pop(cou - 2)))
        cou -= 2

print(Sum[0])