Problem:
Reverse Polish notation is a notation where every operator follows all of its operands. For example, an expression (1+2)*(5+4) in the conventional Polish notation can be represented as 1 2 + 5 4 + * in the Reverse Polish notation. One of advantages of the Reverse Polish notation is that it is parenthesis-free. Write a program which reads an expression in the Reverse Polish notation and prints the computational result. An expression in the Reverse Polish notation is calculated using a stack. To evaluate the expression, the program should read symbols in order. If the symbol is an operand, the corresponding value should be pushed into the stack. On the other hand, if the symbols is an operator, the program should pop two elements from the stack, perform the corresponding operations, then push the result in to the stack. The program should repeat this operations. Input An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character. You can assume that +, - and * are given as the operator and an operand is a positive integer less than 10 6  Output Print the computational result in a line. Constraints 2 ≤ the number of operands in the expression ≤ 100 1 ≤ the number of operators in the expression ≤ 99 -1 × 10 9 ≤ values in the stack ≤ 10 9  Sample Input 1 1 2 + Sample Output 1 3 Sample Input 2 1 2 + 3 4 - * Sample Output 2 -3 Notes Template in C

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

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque
import copy

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = sl()
    stack = []
    operation = {
        '+': lambda a, b: b + a,
        '-': lambda a, b: b - a,
        '*': lambda a, b: b * a,
    }

    for s in S:
        if s.isdecimal():
            stack.append(s)
        else:
            stack.append(operation[s](int(stack.pop()), int(stack.pop())))
    print(*stack)


if __name__ == '__main__':
    main()

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

Solution (Python):
from collections import deque
d = deque()
S = input().split()
for s in S:
    if s == "+":
        a = d.pop()
        b = d.pop()
        d.append(a+b)
    elif s == "-":
        a = d.pop()
        b = d.pop()
        d.append(b-a)
    elif s == "*":
        a = d.pop()
        b = d.pop()
        d.append(a*b)
    else:
        d.append(int(s))

print(d[0])

Solution (Python):
import re

tokens = list(input().split())
stack = []

for token in tokens:
   if  re.match('\d', token):
       stack.append(int(token))
   else:
        rval = stack.pop(-1)
        lval = stack.pop(-1)
        if token == '+':
            result = lval + rval
        elif token == '-':
            result = lval - rval
        elif token == '*':
            result = lval * rval
        stack.append(result)

print(stack.pop(-1))

Solution (Python):


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

    def push(self, d):
        self.data.append(d)

    def pop(self):
        if not self.data:
            return None
        else:
            return self.data.pop()

    def print(self):
        print(self.data)

s = Stack()

input_data = input()




for d in input_data.split(' '):
    if d == "+":
        s.push(s.pop() + s.pop())
    elif d == "-":
        tmp1 = s.pop()
        tmp2 = s.pop()
        s.push(tmp2 - tmp1)
    elif d == "*":
        tmp1 = s.pop()
        tmp2 = s.pop()
        s.push(tmp2 * tmp1)
    else:
        s.push(int(d))

print(s.pop())

Solution (Python):


def main():
    formula=[]
    formula = list(input().split())
    stack=[]
    value1=0
    value2=0
    for value in formula:
        if "+" in value or "-" in value or "*" in value:
            value2=stack.pop()
            value1=stack.pop()
            stack.append(str(eval(value1 + value + value2)))
        else:
            stack.append(value)
    print(stack[0])

if __name__=="__main__":
    main()

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


class Node:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.parent = None


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

    def push(self, node: Node):
        if self.top == self.head:
            self.head.next = node
            node.parent = self.head
            self.top = node
        else:
            self.top.next = node
            node.parent = self.top
            self.top = node

    def pop(self):
        if self.top == self.head:
            return None
        else:
            _tmp = self.top
            self.top = self.top.parent
            self.top.next = None
            return _tmp


ops = input().strip().split()

stack = Stack()

for op in ops:
    if op == "+":
        _a = stack.pop().val
        _b = stack.pop().val
        stack.push(Node(_a + _b))
    elif op == "-":
        _a = stack.pop().val
        _b = stack.pop().val
        stack.push(Node(_b - _a))
    elif op == "*":
        _a = stack.pop().val
        _b = stack.pop().val
        stack.push(Node(_a * _b))
    else:
        stack.push(Node(int(op)))

print(stack.pop().val)

Solution (Python):
import math

stack=[]
s=raw_input().split()

for i in s:
  if i=='+' or i=='-' or i=='*' or i=='/':
    x=stack.pop()
    y=stack.pop()
    stack.append(str(eval(y+i+x)))

  else:
    stack.append(i)

print stack[0]

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

stack = []
for index in range(len(codes)):
    num_or_operator = codes[index]
    if num_or_operator.isdigit():
        stack.append(int(num_or_operator))
    else:
        rhs = stack.pop()
        lhs = stack.pop()
        if num_or_operator == "+":
            stack.append(lhs + rhs)
        elif num_or_operator == "-":
            stack.append(lhs - rhs)
        else:
            stack.append(lhs * rhs)

print(stack.pop())

Solution (Python):
exp = input().split()
op = '+ - *'.split()
stack = []

for e in exp:
    if e == '+':
        ope1 = stack.pop()
        ope2 = stack.pop()
        stack.append(ope2 + ope1)
    elif e == '-':
        ope1 = stack.pop()
        ope2 = stack.pop()
        stack.append(ope2 - ope1)
    elif e == '*':
        ope1 = stack.pop()
        ope2 = stack.pop()
        stack.append(ope2 * ope1)
    else:
        stack.append(int(e))

print(stack[0])

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

Solution (Python):
def calc(a):
    b = []
    for i in a:
        v = 0
        if i.isnumeric():
            b.append(int(i))
        else:
            if i == '+':
                for _ in range(2):
                    v += b.pop()
                b.append(v)
            elif i == '-':
                for _ in range(2):
                    if _ == 0:
                        v -= b.pop()
                    else:
                        v += b.pop()
                b.append(v)
            elif i == '*':
                for _ in range(2):
                    if _ == 0:
                        v += b.pop()
                    else:
                        v *= b.pop()
                b.append(v)
    return b


if __name__ == '__main__':
    l = input().split()
    print(calc(l)[0])

Solution (Python):
def main():
    r_p_formula = list(input().split())
    
    stack = []
    res = 0
    for element in r_p_formula:
        try:
            num = int(element)
            stack.append(num)
            
        except ValueError:
            last_num = stack.pop()
            sec_last_num = stack.pop()
            stack.append(calc(sec_last_num, last_num, element))
            
    print(stack.pop())

def calc(num1, num2, ope):
    if ope == "+":
        return num1 + num2
    elif ope == "-":
        return num1 - num2
    elif ope == "*":
        return num1 * num2
    else:
        return 0

if __name__ == '__main__':
    main()

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

stack=[]


for i in range(0,len(num_list)):
    if num_list[i]=="+":
        ans=0
        tmp1=int(stack.pop())
        tmp2=int(stack.pop())
        ans=tmp2+tmp1
        stack.append(ans) 
    elif num_list[i]=="*":
        ans=0
        tmp1=int(stack.pop())
        tmp2=int(stack.pop())
        ans=tmp2*tmp1
        stack.append(ans) 
    elif num_list[i]=="-":
        ans=0
        tmp1=int(stack.pop())
        tmp2=int(stack.pop())
        ans=tmp2-tmp1
        stack.append(ans) 
    elif num_list[i]=="/":
        ans=0
        tmp1=int(stack.pop())
        tmp2=int(stack.pop())
        ans=tmp2/tmp1
        stack.append(ans) 
    else:
        stack.append(num_list[i])
print(stack[0])

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

for s in lst:
    if s == "+":
        stack += [stack.pop() + stack.pop()]
    elif s == "-":
        stack += [-stack.pop() + stack.pop()]
    elif s == "*":
        stack += [stack.pop() * stack.pop()]
    else:
        stack += [int(s)]

print(stack.pop())

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

for i in F:
    try:
        stack.append(int(i))
    except ValueError:
        exec(
            f"temp = stack[-2] {i} stack[-1];"
            "stack.pop();"
            "stack.pop();"
            "stack.append(temp);"
            )

print(stack[0])

Solution (Python):
input_list = input().rstrip().split(" ")

stack = []
for i in input_list:
    if i in ["+", "-", "*"]:
        num_1 = stack.pop()
        num_2 = stack.pop()
        stack.append(str(eval(num_2 + i + num_1)))
    else:
        stack.append(i)
answer = stack.pop()
print(answer)

Solution (Python):
from collections import deque

s = input().split()
l = deque()

for i in s:
    if i in ['+', '-', '*', '/']:
        a = l.pop()
        b = l.pop()
        l.append(str(eval(b+i+a)))
    else:
        l.append(i)
print(l[0])

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

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

for j in l:
    print(j)

Solution (Python):
import sys
from collections import deque

input = sys.stdin.readline


def main():
    S = input().split()

    stack = deque()
    for s in S:
        if s in ["+", "-", "*"]:
            b = stack.pop()
            a = stack.pop()
            c = str(eval(a + s + b))
            stack.append(c)
        else:
            stack.append(s)
    ans = stack.pop()
    print(ans)


if __name__ == "__main__":
    main()

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

def push(x):
    global stack
    global top

    top += 1
    stack[top] = x

def pop():
    global top
    global stack

    top -= 1
    return(stack[ top + 1 ])

def main():
    global stack
    global top
    a = 0
    b = 0

    A = list(input().split())

    for i in range(len(A)):
        if A[i] not in ['+','-','*']:
            push(int(A[i]))
        elif A[i] == '+':
            a = pop()
            b = pop()
            push(b+a)
        elif A[i] == '-':
            a = pop()
            b = pop()
            push(b-a)
        elif A[i] == '*':
            a = pop()
            b = pop()
            push(b*a)

    return stack[1]

print(main())

Solution (Python):
def cal(x,y,o):
    x,y=int(x),int(y)
    if o=="+":
        return x+y
    if o=="-":
        return x-y
    if o=="*":
        return x*y
    if o=="/":
        return x/y

def RPN(shiki):
    stack=[]
    operator=["+","-","*","/"]
    for x in shiki:
        if x not in operator:
            stack.append(int(x))
        else:
            s=stack.pop()
            f=stack.pop()
            stack.append(cal(f,s,x))
    return stack[-1]

shiki=list(input().split())
print(RPN(shiki))

Solution (Python):


S = raw_input().split()

lst = []

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

print lst[0]

Solution (Python):
S=input().split()
operand=[]
cnt=0



for s in S:
  if s in '+-*':
    a=operand.pop()
    b=operand.pop()
    x=eval(b+s+a)
    
    
    
    operand.append(str(x))
  else:
    operand.append(s)

print(operand.pop())

Solution (Python):
class Stack:
    def __init__(self):
        self.top = 1
        self.array = [None]*1000

    def push(self, x):
        if not self.isFull():
            self.array[self.top] = x
            self.top += 1
        else:
            raise ValueError()

    def pop(self):
        if not self.isEmpty():
            self.top -= 1
            val = self.array[self.top]
            return val
        else:
            raise ValueError()

    def isEmpty(self):
        if self.top == 1:
            return True
        else:
            return False

    def isFull(self):
        if self.top >= 999:
            return True
        else:
            return False


def main():
    S = input().split()
    stack = Stack()
    operands = ["+", "-", "*"]
    for s in S:
        if s not in operands:
            stack.push(int(s))

        else:
            val1 = stack.pop()
            val2 = stack.pop()
            if s == "+":
                val = val1 + val2
                stack.push(val)
            elif s == "-":
                val = val2 - val1
                stack.push(val)
            else:
                val = val1 * val2
                stack.push(val)
    ans = stack.pop()
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

from sys import stdin

inp = stdin.readline().rstrip().split()
stack = []

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

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

l = []
for n in A:
    ans = 0
    if n.isnumeric():
        l.append(int(n))
    elif n == '+':
        ans = l[-2] + l[-1]
        l[-2] = ans
        l.pop()
    elif n == '-':
        ans = l[-2] - l[-1]
        l[-2] = ans
        l.pop()
    elif n == '*':
        ans = l[-2] * l[-1]
        l[-2] = ans
        l.pop()
        
print(l[0])

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


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

Solution (Python):
def resolve():
    from collections import deque
    A = [i for i in input().split()]
    que = deque()
    for s in A:
        if s in "+-*":
            b = que.pop()
            a = que.pop()
            tmp = str(eval(a + s + b))
            que.append(tmp)
        else:
            que.append(s)
    print(que.popleft())


resolve()

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

Solution (Python):
a= list(input().split())
for i in range(len(a)):
    if a[i] !="+" and a[i] !="-"and a[i] !="*":
        a[i]=int(a[i])
i= 0
while len(a)>1:
    if a[i] =="+":
        temp= a[i-2]+ a[i-1]
        a.pop(i-2)
        a.pop(i-2)
        a[i-2]= temp
        i= i- 1
    elif a[i] =="-":
        temp= a[i-2]- a[i-1]
        a.pop(i-2)
        a.pop(i-2)
        a[i-2]= temp
        i= i- 1
    elif a[i] =="*":
        temp= a[i-2]* a[i-1]
        a.pop(i-2)
        a.pop(i-2)
        a[i-2]= temp
        i= i- 1
    else:
        i= i+ 1
print(a[0])

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

Solution (Python):
a = str(input()).split(' ')
calc = []
for i in range(len(a)):
    if a[i] == '+':
        p = calc.pop()
        q = calc.pop()
        calc.append(p + q)
    elif a[i] == '-':
        p = calc.pop()
        q = calc.pop()
        calc.append(q - p)
    elif a[i] == '*':
        p = calc.pop()
        q = calc.pop()
        calc.append(p * q)
    else:
        calc.append(int(a[i]))
print(calc[0])

Solution (Python):
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    S = input().split()
    stack = []
    for st in S:
        if st == '+':
            b = stack.pop()
            a = stack.pop()
            stack.append(a + b)
        elif st == '-':
            b = stack.pop()
            a = stack.pop()
            stack.append(a - b)
        elif st == '*':
            b = stack.pop()
            a = stack.pop()
            stack.append(a*b)
        else:
            stack.append(int(st))
    ans = stack[0]
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    f = input().split()
    stack = list()
    for i in f:
        if i.isdigit():
            stack.append(i)
        else:
            se = stack.pop()
            fi = stack.pop()
            tmp = eval(fi+i+se)
            stack.append(str(tmp))
    print(stack.pop())
    
if __name__ == '__main__':
    main()

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

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


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

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

    def pop(self):
        if len(self.stack) == 0:
            return None
        return self.stack.pop()


stack = Stack()
for s in ls:
    if s in ['+', '-', '*']:
        v2 = stack.pop()
        v1 = stack.pop()
        stack.push(str(eval(v1+s+v2)))
    else:
        stack.push(s)
print(stack.stack[0])

Solution (Python):
args = input().split(' ')
stack = []
for arg in args:
    if arg.isdecimal():
        stack.append(int(arg))
    elif arg == '+':
        a = stack.pop()
        b = stack.pop()
        stack.append(a + b)
    elif arg == '-':
        a = stack.pop()
        b = stack.pop()
        stack.append(b - a)
    elif arg == '*':
        a = stack.pop()
        b = stack.pop()
        stack.append(a * b)
print(stack.pop())

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

for x in s:
    if x.isdigit():
        stack.append(x)
    else:
        right = stack.pop()
        left = stack.pop()
        res = eval(left + x + right)
        stack.append(str(res))
print(int(stack.pop()))

Solution (Python):
from collections import deque

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

S=deque([])

for i in range(len(D)):
    if str.isnumeric(D[i])==True:
        S.append(int(D[i]))
    else:
        A=S.pop()
        B=S.pop()
        if D[i]=="+":
            S.append(A+B)
        elif D[i]=="-":
            S.append(B-A)
        else:
            S.append(A*B)
    
print(S[0])

Solution (Python):


from collections import deque


top=0
S=deque()
array=input().split(" ")

for i in range(len(array)):
  s=array[i]
  if s=="+":
    a=S.pop()
    b=S.pop()
    S.append(a+b)
  elif s=="-":
    a=S.pop()
    b=S.pop()
    S.append(b-a)
  elif s=="*":
    a=S.pop()
    b=S.pop()
    S.append(a*b)
  else:
    S.append(int(s))
print(S.pop())

Solution (Python):
por_list = list(input().split(' '))

stack = []


for i in por_list:
    try:
        stack.append(int(i))
    except ValueError:
        x = stack.pop()
        y = stack.pop()
        if i == '+':
            stack.append(x+y)
        elif i == '-':
            stack.append(y-x)
        elif i == '*':
            stack.append(x*y)
print(stack.pop())

Solution (Python):
if __name__ == '__main__':
    A = input().split()
    stack = []
    for s in A:
        stack.append(s)
        if s == "+":
            stack.pop()
            a = int(stack.pop())
            b = int(stack.pop())
            stack.append(a + b)
        elif s == "-":
            stack.pop()
            a = int(stack.pop())
            b = int(stack.pop())
            stack.append(b - a)
        elif s == "*":
            stack.pop()
            a = int(stack.pop())
            b = int(stack.pop())
            stack.append(a * b)

    print(stack[0])

Solution (Python):
A = input().split()
S = []
for a in A:
    if a in ['+', '-', '*']:
        s = eval(S[-2] + a + S[-1])
        S = S[:-2]
        S.append(str(s))
    else:
        S.append(a)
print(*S)

Solution (Python):
class stack:

    data = []

    def push(self, a):
        self.data.append(a)

    def pop(self):
        if len(self.data) > 0:
            top = self.data[-1]
            self.data = self.data[:-1]
            return top
        else:
            raise Exception('stack has no data.')

buf = stack()
op = ['+', '*', '-']

a = list(input().split())
for i in a:
    if i in op:
        op2 = int(buf.pop())
        op1 = int(buf.pop())
        if i == '+':
            buf.push(op1+op2)
        elif i == '*':
            buf.push(op1*op2)
        else:
            buf.push(op1-op2)
    else:
        buf.push(i)
result = buf.pop()
print(result)

Solution (Python):
num_str_list = list(input().split())
answer_list = []

for i in num_str_list:
    if i in "+-*":
        v1 = answer_list.pop()
        v2 = answer_list.pop()
        if i == "+":
            v3 = int(v2) + int(v1)
            answer_list.append(v3)
        if i == "-":
            v3 = int(v2) - int(v1)
            answer_list.append(v3)
        if i == "*":
            v3 = int(v2) * int(v1)
            answer_list.append(v3)
    else:
        answer_list.append(i)
        
print(answer_list[0])

Solution (Python):
a=list(input().split())
def reverse_porand(r):
    s=[]
    for i in range(len(r)):
        if r[i]=="+":
            a=s.pop(-1)
            b=s.pop(-1)
            s.append(a+b)
        elif r[i]=="-":
            a=s.pop(-1)
            b=s.pop(-1)
            s.append(b-a)
        elif r[i]=="*":
            a=s.pop(-1)
            b=s.pop(-1)
            s.append(a*b)
        else:
            s.append(int(r[i]))
    print(s[-1])

reverse_porand(a)

Solution (Python):

from collections import deque as stack
S = input().split()
q = stack([])

for i in S:
    
    if i == "+":
        b = int(q.pop())
        a = int(q.pop())
        q.append(a+b)
        
    elif i == "-":
        b = int(q.pop())
        a = int(q.pop())
        q.append(a-b)
        
    elif i == "*":
        b = int(q.pop())
        a = int(q.pop())
        
        q.append(a*b)
    else:
        q.append(int(i))
print(q.pop())

Solution (Python):
n = input()
v = [n.lower() for n in n.split()]

stack = []
idx = 0
loop_cnt = 0

for num in v:
    try:
        if int(num):
            stack.append(num)
    except:
        if num == "+":
            calc = int(stack[idx - 2]) + int(stack[idx - 1])
        elif num == "-":
            calc = int(stack[idx - 2]) - int(stack[idx - 1])
        elif num == "*":
            calc = int(stack[idx - 2]) * int(stack[idx - 1])

        for i in range(0,2):
            stack.pop(idx - 1)
        stack.append(calc)
        idx = 0
        loop_cnt = 0

print(stack[0])

Solution (Python):
from typing import List, Union


class Stack():
    def __init__(self):
        self.top = 0
        self.max = 200
        self.lst = [None] * self.max

    def is_empty(self) -> bool:
        if self.top == 0:
            return True
        else:
            return False

    def is_full(self) -> bool:
        if self.top >= self.max - 1:
            return True
        else:
            return False

    def push(self, x: int) -> bool:
        if self.is_full() == True:
            print("ERROR: OVERFLOW")
            return False
        self.top += 1
        self.lst[self.top] = x
        return True

    def pop(self) -> Union[bool, int]:
        if self.is_empty() == True:
            print("ERROR: UNDERFLOW")
            return False
        self.top -= 1
        return self.lst[self.top + 1]


def main():
    lst: List = list(input().split())
    S = Stack()

    for char in lst:
        if char == "+":
            b = S.pop()
            a = S.pop()
            S.push(a + b)
        elif char == "-":
            b = S.pop()
            a = S.pop()
            S.push(a - b)
        elif char == "*":
            b = S.pop()
            a = S.pop()
            S.push(a * b)
        else:
            S.push(int(char))

    print(S.lst[S.top])


if __name__ == "__main__":
    main()

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

for i in input:
    if i.isdigit():
        stack.append(i)
    else:
        s = stack.pop()
        f = stack.pop()
        stack.append(str(eval(f+i+s)))

print(int(stack.pop()))

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

for item in formula:
    if item == '+' or item == '-' or item == '*':
        a = stack.pop()
        b = stack.pop()
        if item == '+':
            c = a + b
        elif item == '-':
            c = b - a
        else:
            c = a * b
        stack.append(c)
    else:
        stack.append(int(item))
print(stack.pop())

Solution (Python):
from collections import deque

def calc(b,a,s):
    if s == '+':
        return a + b
    if s == '-':
        return a - b
    if s == '*':
        return a * b

L = input().split()
S = deque()
for c in L:
    if c in ['+','-','*']:
        S.append(calc(int(S.pop()), int(S.pop()), c))
    else:
        S.append(c)
print(S[0])

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = LSS()
    stk = []
    for i in S:
        if i in ['+', '-', '*']:
            a = stk.pop()
            b = stk.pop()
            if i=='+':
                stk.append(b+a)
            elif i=='-':
                stk.append(b-a)
            elif i=='*':
                stk.append(b*a)
        else:
            stk.append(int(i))

    print(stk[0])

if __name__ == '__main__':
    resolve()

Solution (Python):
stack = []

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

ans = stack.pop()
print(ans)

Solution (Python):
def cal(n1, n2, o):
    if o == "+":
        return str(n1 + n2)
    elif o == "-":
        return str(n1 - n2)
    elif o == "*":
        return str(n1 * n2)

S = input().split()
i = 0
while len(S) > i:
    if S[i] == "+" or S[i] == "-" or S[i] == "*":
        r = cal(int(S[i-2]), int(S[i-1]), S[i])
        del S[i-2:i+1]
        S.insert(i-2, r)
        i = 0
    else:
        i += 1

print(S[0])

Solution (Python):
class Stack:
    """Stack"""
    def __init__(self):
        self.Clear()

    def Clear(self):
        self.Stack = []

    def push(self, dat):
        self.Stack.append(dat)
        return self.Stack

    def pop(self):
        if len(self.Stack) == 0:
            return None
        return self.Stack.pop()

s = [i for i in input().split()]
stack = Stack()
for i in range(len(s)):
    if s[i] == '+':
        s_1 = stack.pop()
        s_2 = stack.pop()
        stack.push(s_1 + s_2)
    elif s[i] == '-':
        s_3 = stack.pop()
        s_4 = stack.pop()
        stack.push(s_4 - s_3)
    elif s[i] == '*':
        s_5 = stack.pop()
        s_6 = stack.pop()
        stack.push(s_5 * s_6)
    else:
        stack.push(int(s[i]))
    
        
print(stack.pop())

Solution (Python):
from collections import deque
D = deque([])
for i in map(str,input().split()):
    if i.isdecimal():
        D.append(i)
    else:
        i1 = D.pop()
        i2 = D.pop()
        D.append(str(eval(i2+i+i1)))
else:
    print(D.pop())

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

Solution (Python):
S = []

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

Solution (Python):
f = input().strip().split()
q = []
for e in f:
    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])