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):
n = list(map(str,input().split()))
stack = []
for i in n:
    if i.isnumeric():
        stack.append(i)
    else:
        x_1 = stack.pop()
        x_2 = stack.pop()
        tmp = eval(x_2 + i + x_1)
        stack.append(str(tmp))
else:
    print(stack.pop())

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

Solution (Python):
from collections import deque





stack = deque()

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

Solution (Python):
def cal(operand,a,b):
  if operand == "+":
    return int(a)+int(b)

  elif operand == "-":
    return int(a)-int(b)

  elif operand == "*":
    return int(a)*int(b)

por=[]

por = list(input().split())

stk=[]

for i in por:
  if i.isdigit() == True:
    stk.append(int(i))

  else:
    b=stk.pop()
    a=stk.pop()
    stk.append(cal(i,a,b))

print(stk[0])

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

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

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

Solution (Python):
stack = []

for s in input().split():
  if s in '+-*':
    res = 0
    b = stack.pop(-1)
    a = stack.pop(-1)
  
    if s == '+': 
      res = a + b
    elif s == '-':
      res = a - b
    elif s == '*':
      res = a * b
  
    stack.append(res)
  else:
    stack.append(int(s))

print(stack[0])

Solution (Python):
class Stack():
    def __init__(self):
        self.top=0
        self.S=[None]*1000
    def isEmpty(self):
        return self.top==0
    def push(self,fig):

        if fig.isdigit():
            self.top += 1
            self.S.insert(self.top,fig)
        else:
            before,after = self.pop(),self.pop()
            result = eval(str(after)+fig+str(before))
            self.top += 1
            self.S.insert(self.top, result)
    def pop(self):
        self.top-=1
        vari=self.S[self.top + 1]
        self.S[self.top + 1]=None
        return vari

Stck=Stack()


[Stck.push(x) for x in input().split()]
print(Stck.S[1])

Solution (Python):
x = input()
y = x.split()
for i in range(len(y)):
    op = y[i]
    if op == '+' or op == '-' or op == '*':
        k = i-1
        for j in range(2):
            while 1:
                tmp = y[k]
                if tmp != '' and tmp != '+' and tmp != '-' and tmp != '*':
                    if j == 0:
                        nop_2 = int(y[k])
                        y[k] = ""
                        break
                    else:
                        nop_1 = int(y[k])
                        y[k] = ""
                        break
                k -= 1
                
        if op == '+':
            xRst = nop_1 + nop_2
        elif op == '-':
            xRst = nop_1 - nop_2
        else:
            xRst = nop_1 * nop_2
        y[i] = xRst
print(xRst)

Solution (Python):
class Stack():
    def __init__(self, size):
        self.A = [None for i in range(size)]
        self.i = -1  
        self.size = size
    
    def push(self, x):
        self.A[self.i+1] = x
        self.i += 1
    
    def pop(self):
        ret = self.A[self.i]
        self.A[self.i] = None
        self.i -= 1
        return ret
    
    def isEmpty(self):
        return self.i == -1
    
    def isFull(self):
        return self.i == size - 1

S = Stack(100)
for i in input().split():
    if i == '+':
        s1, s2= S.pop(), S.pop()
        S.push(s2 + s1)
    elif i == '-':
        s1, s2= S.pop(), S.pop()
        S.push(s2 - s1)
    elif i == '*':
        s1, s2= S.pop(), S.pop()
        S.push(s2 * s1)
    else:
        S.push(int(i))
print(S.pop())

Solution (Python):
from collections import deque

*S, = input().split()
operater = '+-*'

stack = deque()

for s in S:
    if s in '+-*':
        b = stack.pop()
        a = stack.pop()

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

print(stack.pop())

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

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

if __name__ == "__main__":
    stack = [0]*1000
    top = [0]
    for s in input().split():
        if s not in ("+","-","*"):
            push(int(s))
            continue
        a = pop()
        b = pop()
        if s == "+":
            push(b+a)
        elif s == "-":
            push(b-a)
        else:
            push(b*a)
    print(pop())

Solution (Python):
class Stack:
    def __init__(self,arg_size):
        self.size = arg_size
        self.stack = [None] * self.size
        self.head = 0
        self.tail = 0

    def is_empty(self):
        return self.tail == self.head

    def push(self,arg_object):
        self.stack[self.tail] = arg_object
        self.tail += 1

    def pop(self):
        self.tail -= 1
        return self.stack[self.tail]

    def top(self):
        return self.stack[self.head]

SIZE = 105
NUM = Stack(SIZE)

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

for i in range(len(input_str)):
    ch = input_str[i]
    if ch in ['+','-','*']:
        num_2 = NUM.pop()
        num_1 = NUM.pop()
        num = 0
        if ch =='+':
            num =num_1+num_2
        elif ch =='-':
            num = num_1 - num_2
        else:
            num = num_1 * num_2
        NUM.push(num)
    else:
        NUM.push(int(ch))
print(NUM.top())

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

for x in formula:
    if x.isdigit():
        stack.append(x)
    else:
        second_num = stack.pop()
        first_num = stack.pop()
        tmp = eval(first_num + x + second_num)
        stack.append(str(tmp))

print(int(stack.pop()))

Solution (Python):

class Stack:
    def __init__(self, size):
        self.size = size
        self.stack = [None] * self.size
        self.tail = 0

    def push(self, new):
        self.stack[self.tail] = new
        self.tail += 1

    def pop(self):
        self.tail -= 1
        return self.stack[self.tail]


max_size = 105

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

N = len(li)
stack = Stack(max_size)

for i in range(N):
    ch = li[i]
    if ch in ['+', '-', '*']:
        num_2 = stack.pop()
        num_1 = stack.pop()
        if ch == '+':
            stack.push(num_1 + num_2)
        elif ch == '-':
            stack.push(num_1 - num_2)
        else:
            stack.push(num_1 * num_2)
    else:
        stack.push(int(ch))

print('{}'.format(stack.stack[0]))

Solution (Python):


S = input().split()
s = []
for i in S:
    if i not in ['+', '-', '*']:
        s.append(int(i))
    else:
        s1 = s.pop()
        s2 = s.pop()
        if i == '+':
            s.append(s1 + s2)
        elif i == '-':
            s.append(s2 - s1)
        elif i == '*':
            s.append(s1 * s2)
print(s[0])

Solution (Python):
s = map(str, raw_input().split())

stack = []

for op in s:
  if op == '+':
    y = stack.pop()
    x = stack.pop()
    stack += [int(x) + int(y)]
  elif op == '-':
    y = stack.pop()
    x = stack.pop()
    stack += [int(x) - int(y)]
  elif op == '*':
    y = stack.pop()
    x = stack.pop()
    stack += [int(x) * int(y)]
  else:
    stack += [int(op)]
print stack[0]

Solution (Python):
def calc_formula(formula_list: list):
    operator = formula_list.pop()
    if formula_list[-1] in ['+', '-', '*']:
        back = calc_formula(formula_list)
    else:
        back = int(formula_list.pop())

    if formula_list[-1] in ['+', '-', '*']:
        front = calc_formula(formula_list)
    else:
        front = int(formula_list.pop())
    
    if operator == '+':
        return front + back

    if operator == '-':
        return front - back

    if operator == '*':
        return front * back

formula = input().split(' ')

res = calc_formula(formula)
print(res)

Solution (Python):
from collections import deque

L=input().split()

d = deque()

for l in L:
    if l in '+':
        a=d.pop()
        b=d.pop()
        d.append(a+b)
    elif l in '-':
        a=d.pop()
        b=d.pop()
        d.append(b-a)
    elif l in '*':
        a=d.pop()
        b=d.pop()
        d.append(a*b)
    elif l in '/':
        a=d.pop()
        b=d.pop()
        d.append(b/a)
    else:
        d.append(int(l))
        
print_num = d.pop()
print(print_num)

Solution (Python):


class Stack(object):
    def __init__(self, num):
        self.list = []
        self.num = num
    
    def push(self, x):
        self.list.append(x)

    def pop(self):
        return self.list.pop(-1)
    
    def isEmpty(self):
        return len(self.list) == 0
    
    def isFull(self):
        return self.num <= len(self.list)



def main():
    li = list(input().split(' '))

    stack = Stack(999999)
    OPERANDS = ['+', '-', '*']
    
    for x in li:
        if not (x in OPERANDS):
            stack.push(int(x))
        else:
            b = stack.pop()
            a = stack.pop()

            if x == '+':
                stack.push(a + b)
            elif x == '-':
                stack.push(a - b)
            elif x == '*':
                stack.push(a * b)
        

    ans = stack.pop()
    print(ans)


        

main()

Solution (Python):
formula = input().split()
operand = ['+', '-', '*', '/']
stuck = []

for c in formula:
    if c in operand:
        b = str(stuck.pop())
        a = str(stuck.pop())
        stuck.append(eval(''.join([a, c, b])))
    else:
        stuck.append(c)

print(stuck.pop())

Solution (Python):
def onp(dzialanie):
    stos = []
    kolejka = dzialanie.split(" ")

    while len(kolejka) > 0:
        item = kolejka.pop(0)
        if item == "+":
            stos.append(stos.pop() + stos.pop())
        elif item == "-":
            odjemnik = stos.pop()
            stos.append(stos.pop() - odjemnik)
        elif item == "*":
            stos.append(stos.pop() * stos.pop())
        elif item == "/":
            dzielnik = stos.pop()
            stos.append(stos.pop() / dzielnik)
        else:
            try:
                stos.append(float(item))
            except ValueError:
                return "ERROR: Niedozwolony element: "+item

    return str(int(stos.pop()))

print(onp(input()))

Solution (Python):
a = input().split()
ret = 0
s = []
for e in a:
    if e in ["+","-","*"]:
        if e == "+":
            s.append(s.pop()+s.pop())
        elif e == "-":
            t = s.pop()
            s.append(s.pop()-t)
        else:
            s.append(s.pop()*s.pop())
    else:
        s.append(int(e))
print(s[0])

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

for x in In:

    if x.isdigit():
        stack.append(x)

    else:
        second = stack.pop()
        first = stack.pop()
        tmp = eval(first + x + second)
        stack.append(str(tmp))

print(int(stack.pop()))

Solution (Python):
s = list(map(str, input().split()))
l = []
for i in range(len(s)):
    n = s[i]
    if n == "-":
        t = l.pop(-2) - l.pop(-1)
        l.append(t)
    elif n == "+":
        t = l.pop(-2) + l.pop(-1)
        l.append(t)
    elif n == "*":
        t = l.pop(-2) * l.pop(-1)
        l.append(t)
    else:
        l.append(int(n))

print(*l)

Solution (Python):
from collections import deque

tokens = input().split()
dq = deque()
operators = "+-*"
for token in tokens:
    if token in operators:
        a = dq.pop()
        b = dq.pop()
        if token == "+":
            dq.append(b + a)
        elif token == "-":
            dq.append(b - a)
        else:
            dq.append(b * a)
    else:
        dq.append(int(token))
print(dq.pop())

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

Solution (Python):
def ope(a, x, y):
    if a == '+':
        return x+y
    if a == '-':
        return x-y
    if a == '*':
        return x*y


*A, = input().split()
stack = []
for a in A:
    try:
        a = int(a)
        stack.append(a)
    except:
        tmp = stack.pop()
        tmp = ope(a, stack.pop(), tmp)
        stack.append(tmp)
print(stack.pop())

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

Solution (Python):
import collections 
S = list(input().split())
d = collections.deque()

for x in S:
    if x.isdecimal():
        d.append(x)
    else:
        second = d.pop()
        first = d.pop()
        d.append(str(eval(first + x + second)))
print(*d)

Solution (Python):
from collections import deque

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

l = input().split()

d = deque()
while l:
    x = l.pop(0)
    if x in ope:
        n1 = d.pop()
        n2 = d.pop()
        val = str(n2)+x+str(n1)
        d.append(eval(val))
    else:
        d.append(x)
    
print(d.pop())

Solution (Python):
from collections import deque

d=deque()

A=input().split()

for n in range(len(A)):
    if A[n]=='+':
        a=int(d.pop())
        b=int(d.pop())
        d.append(str(b+a))
    elif A[n]=='-':
        a=int(d.pop())
        b=int(d.pop())
        d.append(str(b-a))
    elif A[n]=='*':
        a=int(d.pop())
        b=int(d.pop())
        d.append(str(b*a))
    else:
        d.append(int(A[n]))
        
print(int(d.pop()))

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

stack=[]

for token in rpn:
    if token in ("+", "-", "*", "/"):
        right=stack.pop()
        left=stack.pop()
        stack.append(str(eval(left+token+right)))
    else :
        stack.append(token)

print(stack.pop())

Solution (Python):
import sys
import math
import copy
from typing import Tuple, List
input = sys.stdin.readline

expressions = ["+", "-", "*"]
def calc_reverse_polish(formula: List) -> int:
    stack = []
    for icon in formula:
        if icon in expressions:
            v2 = stack.pop()
            v1 = stack.pop()
            stack.append(str(eval(v1 + icon + v2)))
        else:
            stack.append(icon)
    return stack

if __name__ == "__main__":
    A = input().split()
    stack = calc_reverse_polish(A)
    print(stack[0])

Solution (Python):

A = input().split(" ")
stack=[]
operator = ["+","-","*"]
for a in A:
    if a not in operator:
        stack.append(int(a))
    else:
        tmp=""
        if a=="+":
            tmp = stack[-2]+stack[-1]
        elif a=="-":
            tmp = stack[-2]-stack[-1]
        else:
            tmp = stack[-2]*stack[-1]
        stack = stack[:-2] + [tmp]
print(stack[0])

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

stack = list()

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

print(stack[-1])

Solution (Python):
class MyStack:
    def __init__(self, MAX):
        self.top = 0
        self.stack = [0] * MAX
        self.MAX = MAX
        
    def is_empty(self):
        return self.top <= 0
    
    def is_full(self):
        return self.top >= self.MAX - 1
    
    def push(self, entry):
        if self.is_full():
            raise ValueError()
        self.top += 1
        self.stack[self.top] = entry
    
    def pop(self):
        if self.is_empty():
            raise ValueError()
        self.top -= 1
        return self.stack[self.top + 1]
    
    
stack = MyStack(110)
ope = input().split()

for o in ope:
    if o == '+':
        rh = stack.pop()
        lh = stack.pop()
        stack.push(lh + rh)
        
    elif o == '-':
        rh = stack.pop()
        lh = stack.pop()
        stack.push(lh - rh)
        
    elif o == '*':
        rh = stack.pop()
        lh = stack.pop()
        
        stack.push(lh * rh)
        
    else:
        stack.push(int(o))

result = stack.pop()
print(result)

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

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

print(S[0])

Solution (Python):
import collections

letter = input().split(' ')
stack = collections.deque(letter.pop())


def calc_chk(num1, num2, op):
    if op in ['+', '-', '*'] and num1 not in ['+', '-', '*'] and num2 not in ['+', '-', '*']:
        return True
    else:
        return False

while letter:
    temp = letter.pop()
    stack.append(temp)

    is_calc = True
    while is_calc:
        
        if len(stack) >=3:
            if calc_chk(stack[-1], stack[-2], stack[-3]):
                num1 = stack.pop()
                num2 = stack.pop()
                op = stack.pop()
                val = str(eval(num1 + op + num2))
                stack.append(val)
    
            else:
                is_calc = False
        else:
            is_calc = False
print(*stack)

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

for i in range(len(inputs)):
    if inputs[i] in ('+', '-', '*'):
        ope = inputs[i]
        if ope == '+':
            stack.append(stack.pop() + stack.pop())
        elif ope == '-':
            stack.append(-stack.pop() + stack.pop())
        elif ope == '*':
            stack.append(stack.pop() * stack.pop())
    else:
        stack.append(int(inputs[i]))

print(stack.pop())

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

Solution (Python):
def push(s,x):
    s.append(x)
    return(s)

def pop(s):
    ind = len(s)
    a = s[ind-1]
    del s[ind-1]
    return(s, a)



A = input().split()
n = len(A)

stack = []

for i in range(n):
    if (A[i] == '+') or (A[i] == '-') or (A[i] == '*'):
        stack, b = pop(stack)
        stack, a = pop(stack)
        if A[i] == '+':
            stack = push( stack, (int(a)+int(b)) )
        elif A[i] == '-':
            stack = push( stack, (int(a)-int(b)) )
        else:
            stack = push( stack, (int(a)*int(b)) )
    else:
        push(stack, A[i])

print(stack[0])

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

Solution (Python):
X = list(map(str, input().split()))
A = []
for x in X:
    if x.isnumeric():
        A.append(int(x))
    else:
        a = A.pop()
        b = A.pop()
        if x == '+':
            A.append(a+b)
        elif x == '-':
            A.append(b-a)
        else:
            A.append(a*b)
print(A[0])

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

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

Solution (Python):
from collections import deque


def main():
    S = [s for s in input().split()]
    ops = ['+', '-', '*']
    
    d = deque()
    for s in S:
        if s in ops:
            b, a = d.pop(), d.pop()
            eq = a + s + b
            v = eval(eq)
            d.append(str(v))
        else:
            d.append(s)
            
    print(v)
 
    
if __name__=="__main__":
    main()

Solution (Python):
a = list(map(str,input().split()))
S = []
top = -1
for i in range(len(a)):
    if a[i].isdigit()==True:
        top+=1
        
        S.append(int(a[i]))
        
    else:
        
        operand = a[i]
        b = S.pop()
        c = S.pop()
        if operand =='+':
            S.append(c + b)
        if operand =='-':
            S.append(c - b)
        if operand =='*':
            S.append(c * b)
        
        
print(*S)

Solution (Python):
class Stack:
    def __init__(self, max):
        self.max = max
        self.data = list(range(max))
        self.top = 0
    def initialize(self):
        self.top = 0
    def isEmpty(self):
        return self.top == 0
    def isFull(self):
        return self.top >= len(self.data)
    def push(self, x):
        
        self.top += 1
        self.data[self.top] = x
    def pop(self):
        
        self.top -= 1
        return self.data[self.top+1]

D = input().split()


s = Stack(300)

for i in range(len(D)):
    s.push(D[i])
    if D[i] == '+' or D[i] == '-' or D[i] == '*' or D[i] == '/':
        operator = s.pop()
        operand2 = s.pop()
        operand1 = s.pop()
        temp = eval(operand1 + operator + operand2)
        s.push(str(temp))
        
print(s.pop())

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

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

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

    def calc(self, ope):
        ans = 0
        num1 = self.pop()
        num2 = self.pop()
        if ope == '+':
            ans = num2 + num1
        elif ope == '-':
            ans = num2 - num1
        elif ope == '*':
            ans = num2 * num1
        self.push(ans)


stack = Stack()
input_list = input().split()
for i in input_list:
    if i.isdecimal():
        stack.push(int(i))
    else:
        stack.calc(i)
print(stack.pop())

Solution (Python):
def stack(data):
    s = []
    for i in data:
        if i in "+-*":
            a2 = s.pop()
            a1 = s.pop()
            s.append(str(eval(a1 + i + a2)))
        else:
            s.append(i)
    print(s[0])

if "__main__" == __name__:
    data = input().split()
    stack(data)

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

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

print(*stack)

Solution (Python):
from collections import deque

def main():
    stack = deque()

    for c in input().split(" "):

        if c.isdecimal():
            stack.append(int(c))
        
        elif c == "+" or c == "-" or c == "*":
            v1 = stack.pop()
            v2 = stack.pop()
            if c == "+":
                stack.append(v1 + v2)
            elif c == "-":
                stack.append(v2 - v1)
            elif c == "*":
                stack.append(v1 * v2)

    print(stack.pop())

main()

Solution (Python):
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001



class Stack:
    def __init__(self,arg_size):
        self.size = arg_size
        self.stack = [None] * self.size
        self.head = 0
        self.tail = 0

    def is_empty(self):
        return self.tail == self.head

    def push(self,arg_object):
        self.stack[self.tail] = arg_object
        self.tail += 1

    def pop(self):
        self.tail -= 1
        return self.stack[self.tail]

    def top(self):
        return self.stack[self.head]


SIZE = 105
NUM = Stack(SIZE)

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

for i in range(len(input_str)):
    ch = input_str[i]
    if ch in ['+','-','*']:
        num_2 = NUM.pop()
        num_1 = NUM.pop()
        num = 0
        if ch == '+':
            num = num_1+num_2
        elif ch == '-':
            num = num_1-num_2
        else:
            num = num_1*num_2
        NUM.push(num)
    else:
        NUM.push(int(ch))

print("%d"%(NUM.top()))

Solution (Python):
def stack():
    S = list(input().split())
    N = len(S)

    A = [0]

    for i in range(N):
        if S[i] == '+':
            A[-2] += A[-1]
            A.pop()
        elif S[i] == '-':
            A[-2] -= A[-1]
            A.pop()
        elif S[i] == '*':
            A[-2] *= A[-1] 
            A.pop()
        elif S[i] == '/':
            A[-2] /= A[-1]
            A.pop()
        else:
            A.append(int(S[i]))
    
    print(A[-1])

stack()

Solution (Python):
arr = [ i for i in input().split(" ")]


operands = ["+", "-", "*", "/"]

s = []

for i in arr:
  if i not in operands:
    s.append(i)
  
  if i in operands:
    val2 = s.pop()
    val1 = s.pop()

    s.append(eval("{0} {1} {2}".format(val1, i, val2)))

print(s[-1])

Solution (Python):

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

class Stack:
    def __init__(self):
        self.top = None
    
    def push(self,data):
        node = Node(data)
        if self.top==None:
            self.top = node
        else:
            node.next = self.top
            self.top = node
            
    def pop(self):
        if self.top==None:
            return
        else:
            out = self.top
            self.top = self.top.next
            return out

def calc_rpn(x):
    if x=="+" or x=="-" or x=="*":
        a = stack.pop().data
        b = stack.pop().data
        if x=="+":
            stack.push(b + a)
        elif x=="-":
            stack.push(b - a)
        elif x=="*":
            stack.push(b * a)
        
    else:
        stack.push(int(x))

inp = list(input().split())
stack = Stack()

for x in inp:
    calc_rpn(x)
print(stack.pop().data)

Solution (Python):
def main():
    stack = list(input().split(' '))
    stack_x = list()
    for s in stack:
        try:
            int(s)
            stack_x.append(s)
        except ValueError:
            y = stack_x.pop()
            x = stack_x.pop()
            stack_x.append(eval(str(f'{x}{s}{y}')))
    print(*stack_x)


if __name__ == '__main__':
    main()

Solution (Python):

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


i = 0
while len(input_list) > 1:
    if input_list[i] == "+":
        input_list.insert(i+1, int(input_list[i-2]) + int(input_list[i-1]))
        del input_list[i-2: i+1]
        i = 0
    elif input_list[i] == "-":
        input_list.insert(i+1, int(input_list[i-2]) - int(input_list[i-1]))
        del input_list[i-2: i+1]
        i = 0
    elif input_list[i] == "*":
        input_list.insert(i+1, int(input_list[i-2]) * int(input_list[i-1]))
        del input_list[i-2: i+1]
        i = 0
    i += 1


print(input_list[-1])

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

Solution (Python):






class Stack():
    def __init__(self, size):
        self.__top = 0
        self.__stack = [int] * (size+1)

    def isEmpty(self) -> bool:
        return self.__top == 0

    def isFull(self) -> bool:
        return self.__top >= len(self.__stack)-1

    def push(self, x):
        if self.isFull():
            print("Overflow!")
        
        self.__top += 1
        self.__stack[self.__top] = x

    def pop(self):
        if self.isEmpty():
            print("Underflow!")

        self.__top -= 1
        return self.__stack[self.__top+1]


def main():
    s = Stack(100)
    operation = input().split(" ")
    for o in operation:
        if o == '+':
            a, b = s.pop(), s.pop()
            s.push(a + b)
        elif o == '-':
            b, a = s.pop(), s.pop()
            s.push(a - b)
        elif o == '*':
            a, b = s.pop(), s.pop()
            s.push(a * b)
        else:
            s.push(int(o))

    print(s.pop())


if __name__ == "__main__":
    main()

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

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

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

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

print(pop())

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

operator = ['+', '-', '*']

for i in range(len(S)):
    if not(S[i] in operator):
        stack.append(int(S[i]))
    elif S[i] == operator[0]:
        a = stack.pop()
        b = stack.pop()
        stack.append(a + b)
    elif S[i] == operator[1]:
        a = stack.pop()
        b = stack.pop()
        stack.append(b - a)
    elif S[i] == operator[2]:
        a = stack.pop()
        b = stack.pop()
        stack.append(a * b)
print(stack[0])