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):

NArray = []
operator = []
operand = []
for x in raw_input().split():
  if  x == '+':
    a1 = operand[len(operand)-1]
    operand.pop()
    a2 = operand[len(operand)-1]
    operand.pop()
    operand.append(a2 + a1)
  elif  x == '-':
    a1 = operand[len(operand)-1]
    operand.pop()
    a2 = operand[len(operand)-1]
    operand.pop()
    operand.append(a2 - a1)
  elif  x == '*':
    a1 = operand[len(operand)-1]
    operand.pop()
    a2 = operand[len(operand)-1]
    operand.pop()
    operand.append(a2 * a1)
  else:
    operand.append(int(x))

print operand[0]

Solution (Python):


cal = {
       "+": lambda a, b: b+a,
       "-": lambda a, b: b-a,
       "*": lambda a, b: b*a
       }

stack = []

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

print(stack[-1])

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

Solution (Python):

operand = []
for x in raw_input().split():
  if  x == '+' :
    a1 = operand[len(operand)-1]
    operand.pop()
    a2 = operand[len(operand)-1]
    operand.pop()
    operand.append(a2 + a1)
  elif  x == '-':
    a1 = operand[len(operand)-1]
    operand.pop()
    a2 = operand[len(operand)-1]
    operand.pop()
    operand.append(a2 - a1)
  elif  x == '*':
    a1 = operand[len(operand)-1]
    operand.pop()
    a2 = operand[len(operand)-1]
    operand.pop()
    operand.append(a2 * a1)
  else:
    operand.append(int(x))

print operand[0]

Solution (Python):

operand = []
for x in raw_input().split():
  if x.isdigit():
    operand.append(int(x))
  else:
    a1 = operand[len(operand)-1]
    operand.pop()
    a2 = operand[len(operand)-1]
    operand.pop()
    if  x == '+' :
      operand.append(a2 + a1)
    elif  x == '-':
      operand.append(a2 - a1)
    elif  x == '*':
      operand.append(a2 * a1)


print operand[0]

Solution (Python):
operand = []
for x in raw_input().split():
  if x.isdigit():
    operand.append(int(x))
  else:
    a1 = operand[len(operand)-1]
    operand.pop()
    a2 = operand[len(operand)-1]
    operand.pop()
    if  x == '+' :
      operand.append(a2 + a1)
    elif  x == '-':
      operand.append(a2 - a1)
    elif  x == '*':
      operand.append(a2 * a1)

print operand[0]

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

stack = []
for op in s:
	if op.isdigit():
		stack.append(op)
	else:
		b = int(stack.pop())
		a = int(stack.pop())
		ret = 0
		if op == "+":
			ret = a + b
		elif op == "-":
			ret = a - b
		elif op == "*":
			ret = a * b
		stack.append(str(ret))
print stack.pop()

Solution (Python):
operand = []
for x in raw_input().split():
  if x.isdigit():
    operand.append(int(x))
  else:
    a1 = operand.pop()
    a2 = operand.pop()
    if  x == '+' :
      operand.append(a2 + a1)
    elif  x == '-':
      operand.append(a2 - a1)
    elif  x == '*':
      operand.append(a2 * a1)

print operand.pop()

Solution (Python):
input_ = input()
operators = input_.split(' ')

stack = []

def operate(b, a, op):
    return {
        '+': a+b,
        '-': a-b,
        '*': a*b,
    }.get(op)

for op in operators:
    if op in ('+','-','*'):
        stack.append(operate(stack.pop(), stack.pop(), op))
    else:
        stack.append(int(op))

print(stack.pop())

Solution (Python):
ops = [op for op in input().split(" ")]
stack = []
for op in ops:
    if op == "+":
        stack = stack[:-2]+[stack[-2]+stack[-1]]
    elif op == "-":
        stack = stack[:-2]+[stack[-2]-stack[-1]]
    elif op == "*":
        stack = stack[:-2]+[stack[-2]*stack[-1]]
    else:
        stack.append(int(op))
print(stack[0])

Solution (Python):

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

stack = [0] * 1000
stackIndex = -1

for ele in a:
    if ele != '+' and ele != '-' and ele != '*':
        stackIndex += 1
        stack[stackIndex] = ele
    else:
        num2 = int(stack[stackIndex])
        stackIndex -= 1
        num1 = int(stack[stackIndex])
        stackIndex -= 1
        
        calcVal = 0
        if ele == '+':
            calcVal = num1 + num2
        elif ele == '-':
            calcVal = num1 - num2
        elif ele == '*':
            calcVal = num1 * num2
        
        stackIndex += 1
        stack[stackIndex] = calcVal

print(stack[stackIndex])

Solution (Python):
def Cal(sym,n1,n2):
    n1 = int(n1)
    n2 = int(n2)
    if sym == '+':
        ans = n1 + n2
    elif sym == '-':
        ans = n1 - n2
    else:
        ans = n1 * n2
        
    return ans

stack = []

for item in raw_input().split():
    if item.isdigit():
        stack.append(item)
    else:
        n2 = stack.pop()
        n1 = stack.pop()
        sym = item
        ans = Cal(sym,n1,n2)
        stack.append(ans)

Ans = stack.pop()

print Ans

Solution (Python):
def min(a,b,c):
    if a<b and a<c:
        return a
    elif b<c:
        return b
    else:
        return c


def calc(x):
    try:
        a=x.index("+")
    except:
        a=300
    try:
        b=x.index("-")
    except:
        b=300
    try:
        c=x.index("*")
    except:
        c=300

    ind=min(a,b,c)

    if ind==300:
        return x[0]
    
    if x[ind]=="+":
        x.insert(ind-2,int(x[ind-2])+int(x[ind-1]))
    elif x[ind]=="-":
        x.insert(ind-2,int(x[ind-2])-int(x[ind-1]))
    else:
        x.insert(ind-2,int(x[ind-2])*int(x[ind-1]))
    x.pop(ind-1)
    x.pop(ind-1)
    x.pop(ind-1)
    return calc(x)


operas=input().split(" ")
print (calc(operas))

Solution (Python):



a = [e for e in input().split()]


l = []


for x in a:

    if x not in ['+', '-', '*']:
        x = int(x)
        l.append(x)
    else:
        a = l.pop()
        b = l.pop()

        if x == '+':
            l.append(b + a)
        elif x == '-':
            l.append(b - a)
        elif x == '*':
            l.append(b * a)


print(sum(l))

Solution (Python):
def RPN(states):

        operator = {
           '+' :(lambda x, y: x + y),
           '-' :(lambda x, y: x - y),
           '*' :(lambda x, y: x * y),
           '/' :(lambda x, y: float(x)/y)
        }
        stack = []
        for index, z in enumerate(states):
                if z not in operator.keys ():
                        stack.append(int(z))
                        continue
                y = stack.pop()
                x = stack.pop()
                stack.append(operator[z](x,y))
        print (stack[0])
        return (stack[0])

if __name__ == '__main__':
        import sys
        RPN(input().split(" "))

Solution (Python):
"RPN using stack for AOJ ALDS1_3_A: Stack"




def rpn(exp):
    """
    rpn calculation
    >>> rpn(['1', '2', '+', '3', '4', '-', '*'])
    -3
    """

    stack = []
    for elem in exp:
        if elem == '+':
            stack.append(int(stack.pop()) + int(stack.pop()))
        elif elem == '-':
            stack.append(-int(stack.pop()) + int(stack.pop()))
        elif elem == '*':
            stack.append(int(stack.pop()) * int(stack.pop()))
        elif elem == '/':
            stack.append(int(stack.pop()) / int(stack.pop()))
        else:
            stack.append(elem)

    print(stack.pop())


def main():
    "main function"

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

if __name__ == '__main__':
    
    

    main()

Solution (Python):
def reverse_polish_notation(A):
	ops = {'+': lambda a, b: b + a,
	       '-': lambda a, b: b - a,
	       '*': lambda a, b: b * a}

	stack = []

	for i in A:
		if i in ops:
			stack.append(ops[i](stack.pop(), stack.pop()))
		else:
			stack.append(int(i))

	return stack[0]

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

Solution (Python):
box = []
elem = input().split()
for i in elem:
    if i == '+' or i == '-' or i =='*':
        v = '{0} {1} {2}'.format(box[-2],i,box[-1])
        box.pop()
        box.pop()
        box.append(eval(v))
    else:
        box.append(i)
print (box[0])

Solution (Python):

A=input().split()
while(len(A)>1):
    for i in range(len(A)):
        if(A[i]=="+"):
            A[i]=int(A[i-2])+int(A[i-1])
            A=A[:i-2]+A[i:]
            break
        elif(A[i]=="-"):
            A[i]=int(A[i-2])-int(A[i-1])
            A=A[:i-2]+A[i:]
            break
        elif(A[i]=="*"):
            A[i]=int(A[i-2])*int(A[i-1])
            A=A[:i-2]+A[i:]
            break
print(A[0])

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

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

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

Solution (Python):
top = 0
def push(x):
    global top
    L.append(x)
    top += 1
def pop():
    global top
    x = L.pop(top)
    top -= 1
    return x

L = [0]
S = input().split()
for i in S:
    if i == "+":
        a = pop()
        b = pop()
        push(a + b)
    elif i == "-":
        a = pop()
        b = pop()
        push(b - a)
    elif i == "*":
        a = pop()
        b = pop()
        push(a * b)
    else:
        push(int(i))

print(str(pop()))

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])

Solution (Python):


if __name__ == '__main__':

    a = input().split(' ')
    b = []
    for i in a:
        if i == '+':
            tmp = b.pop(-1) + b.pop(-1)
            b.append(tmp)
        elif i == '-':
            p = b.pop(-1)
            tmp = b.pop(-1) - p
            b.append(tmp)
        elif i == '*':
            tmp = b.pop(-1) * b.pop(-1)
            b.append(tmp)
        else:
            b.append( int(i) )
    print(b[0])

Solution (Python):

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

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

print(stack[0])

Solution (Python):
calcs = ["+", "-", "*", "/"]




lst = raw_input().split()

st=[]

def calc(e):

    tot=0
    tmp=0
    first=True

    b = st.pop()
    a = st.pop()

    if e   == "+":
        tot = a + b
    elif e == "-":
         tot = a- b
    elif e == "*":
         tot = a * b
    elif e == "/":
         tot = a / b

    st.append(tot)

for x in lst:
    if x in calcs:
       calc(x)
    else:
       st.append(int(x))

print st.pop()

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

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

Solution (Python):
def push(x, top, S):
      S.append(x)
      top = top + 1

def pop(top):
      del S[top-1]
      top = top - 1

if __name__ == "__main__":
      stdin = input()
      stdin = stdin.split()
      n = len(stdin)
      S = []
      top = len(S)
      for i in range(0, n):
            if stdin[i] == '+':
                  
                  b = S[top-1]
                  a = S[top-2]
                  pop(top)
                  S[top-1] = a + b
            elif stdin[i] == '-':
                  
                  b = S[top-1]
                  a = S[top-2]
                  pop(top)
                  S[top-1] = a - b
            elif stdin[i] == '*':
                  
                  b = S[top-1]
                  a = S[top-2]
                  pop(top)
                  S[top-1] = a * b
            else:
                  push(int(stdin[i]), top, S)
                  
      print(S[top])

Solution (Python):
def push(x, top, S):
      S.append(x)
      top = top + 1

def pop(top):
      del S[top-1]
      top = top - 1

if __name__ == "__main__":
      stdin = input()
      stdin = stdin.split()
      n = len(stdin)
      S = []
      top = len(S)
      for i in range(0, n):
            if stdin[i] == '+':
                  b = S[top-1]
                  a = S[top-2]
                  pop(top)
                  S[top-1] = a + b
            elif stdin[i] == '-':
                  b = S[top-1]
                  a = S[top-2]
                  pop(top)
                  S[top-1] = a - b
            elif stdin[i] == '*':
                  b = S[top-1]
                  a = S[top-2]
                  pop(top)
                  S[top-1] = a * b
            else:
                  push(int(stdin[i]), top, S)
      print(S[top])

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

s = []
tmp = 0

for x in exp:
	if x == '+':
		tmp = int(s.pop()) + int(s.pop())
		s.append(tmp)
	elif x == '-':
		tmp = -1 * (int(s.pop()) - int(s.pop()))
		s.append(tmp)
	elif x == '*':
		tmp = int(s.pop()) * int(s.pop())
		s.append(tmp)
	else:
		s.append(int(x))

print(tmp)

Solution (Python):
import operator
def poland(A):
    l = []
    ops = { "+": operator.add, "-": operator.sub, '*' : operator.mul }
    for i in range(len(A)):
        item = A.pop(0)
        if item in ops:
            l.append(ops[item](l.pop(-2),l.pop()))
        else:
            l.append(int(item))
    return l.pop()
    

if __name__ == '__main__':
    A = input().split()
    print (poland(A[:]))

Solution (Python):
class Stack:
    def __init__(self, stack = None):
        if type(stack) is type([]):
            self.stack = stack
            self.top = len(stack)
        else:
            self.stack = []
            self.top = 0
            
    def isEmpty(self):
        return self.top == 0
    
    def isFull(self):
        return self.top >= MAX - 1
            
    def push(self, e):
        if len(self.stack) != (self.top):
            self.stack[self.top] = e
        else:
            self.stack.append(e)
        self.top += 1
           
    def pop(self):
        self.top -= 1
        return self.stack[self.top]

S = input().split(" ")

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


stack = Stack()
for s in S:
    if s in operators:
        a = stack.pop()
        b = stack.pop()

        result = eval("%d %s %d"%(b, s, a))
        stack.push(result)
    else:
        stack.push(int(s))
print (stack.pop())

Solution (Python):
import sys

stack = []

array = sys.stdin.readline().strip().split(" ")

for op in array:
    if op.isdigit():
        stack.append(int(op))
    else:
        tmp1 = stack.pop()
        tmp2 = stack.pop()
        if op == "+":
            stack.append(tmp1 + tmp2)
        elif op == "-":
            stack.append(tmp2 - tmp1)
        elif op == "*":
            stack.append(tmp1 * tmp2)
        elif op == "/":
            stack.append(float(tmp2) / tmp1)
res = stack.pop()
print str(int(res))

Solution (Python):
def push(S, top, x):
      S.append(x)
      top = top + 1

def pop(S, top):
      t = int(S[top-1])
      del S[top-1]
      top = top -1
      return t

if __name__ == "__main__":
      top = 0
      inpt = (input()).split()
      n = len(inpt)
      S = []
      for i in range(0,n):
            if inpt[i] == "+":
                  b = pop(S, top)
                  a = pop(S, top)
                  c = a + b
                  push(S, top, c)
            elif inpt[i] == "-":
                  b = pop(S, top)
                  a = pop(S, top)
                  c = a - b
                  push(S, top, c)
            elif inpt[i] == "*":
                  b = pop(S, top)
                  a = pop(S, top)
                  c = a * b
                  push(S, top, c)
            else :
                  push(S, top, int(inpt[i]))
      print(S[top-1])

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

Solution (Python):
rp = [ele for ele in input().split()]
op = ['+','-','*']
stack = []
for ele in rp:
	if ele not in op:
		
		stack.append(eval(ele))
	else:
		
		num_2 = stack.pop()
		num_1 = stack.pop()
		if ele == '+':
			stack.append(num_1 + num_2)
		elif ele == '-':
			stack.append(num_1 - num_2)
		else:
			
			stack.append(num_1 * num_2)
print(stack[0])

Solution (Python):


"""
????????????
???????????????????¨???????????????????????????????????????????????¨???°????????°??????????????°??????????¨???°???????¨??????§??????
????????°????????¬?????????????¨??????§?¨???°???????????°??? (1+2)*(5+4) ??????
???????????????????¨??????§??? 1 2 + 5 4 + * ??¨?¨???°???????????????
???????????????????¨??????§?????????????¨??????§????????¨????????¬??§???????????§???????????¨????????????????????????????????????

???????????????????¨??????§?????????????????°???????¨????????????????????????????????????????

"""


INP = list(input().strip().split())
TMP = []
res = 0
for i in INP:
    if i == "+":
        b = TMP.pop()
        a = TMP.pop()
        TMP.append(a + b)

    elif i == "-":
        b = TMP.pop()
        a = TMP.pop()
        TMP.append(a - b)

    elif i == "*":
        b = TMP.pop()
        a = TMP.pop()
        TMP.append(a * b)

    else:
        TMP.append(int(i))

print(TMP.pop())

Solution (Python):
p = lambda x,y:x+y
m = lambda x,y:x-y
t = lambda x,y:x*y
ope = {'+':p, '-':m, '*':t}

data = [int(s) if s.isdigit() else s for s in input().split()]
while len(data) > 1:
	isope = [isinstance(d,str) for d in data]
	ope_idx = isope.index(True)
	xy = data[ope_idx-2:ope_idx]
	ans = ope[data[ope_idx]](*xy)
	data = data[:ope_idx-2] + [ans] + data[ope_idx+1:]

print(data[0])

Solution (Python):

def add(Stack):
    tmp = Stack[-1] + Stack[-2]
    Stack.pop(-1)
    Stack.pop(-1)
    Stack.append(tmp)
    return Stack

def subtract(Stack):
    tmp = Stack[-2] - Stack[-1]
    Stack.pop(-1)
    Stack.pop(-1)
    Stack.append(tmp)
    return Stack

def multiple(Stack):
    tmp = Stack[-1] * Stack[-2]
    Stack.pop(-1)
    Stack.pop(-1)
    Stack.append(tmp)
    return Stack

A = input().split()
Stack = []

for i in range(len(A)):
    if A[i] == '+':
        add(Stack)
    elif A[i] == '-':
        subtract(Stack)
    elif A[i] == '*':
        multiple(Stack)
    else:
        Stack.append(int(A[i]))

print(str(Stack[0]))

Solution (Python):
def r_poland(s):
    stack=[]
    
    for d in s:
        if d.isdigit():
            stack.append(int(d))
        elif d=="+":
            stack[-1]+=stack.pop(-2)
        elif d=="-":
            stack[-1]=stack.pop(-2)-stack[-1]
        elif d=="*":
            stack[-1]*=stack.pop(-2)

    return stack
   
s=list(input().split())

print(*r_poland(s))

Solution (Python):

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

stack=[]

for i in data:
    if i == "+":
        x1 = int(stack.pop())
        x2 = int(stack.pop())
        stack.append(x1+x2)
    elif i == "-":
        x2 = int(stack.pop())
        x1 = int(stack.pop())
        stack.append(x1-x2)
    elif i == "*":
        x2 = int(stack.pop())
        x1 = int(stack.pop())
        stack.append(x1*x2)
    elif i == "/":
        x2 = int(stack.pop())
        x1 = int(stack.pop())
        stack.append(x1-x2)
    else:
        stack.append(int(i))
print(stack[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):
i = [i for i in input().split()]


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

for j in i:
    if j in op:
        r = stack.pop()
        l = stack.pop()
        stack.append(str(eval(l + j + r)))
    else:
        stack.append(j)
print (stack[0])

Solution (Python):
class Stack():
    def __init__(self):
        self.el = []
        
    def add(self, el):
        self.el.append(el)
        
    def pop(self):
        return self.el.pop()

    def isEmpty(self):
        if len(self.el) == 0:
            return True
        else:
            return False

        
a = raw_input().split()

st = Stack()

for index in range(len(a)):
    
    if a[index] in ['+', '-', '*']:
        num1 = st.pop()
        num2 = st.pop()
        if a[index] == '+':
            st.add(int(num1) + int(num2))
        elif a[index] == '-':
            st.add(int(num2) - int(num1))
        else:
            st.add(int(num1) * int(num2))
    else:
        st.add(a[index])
    

ans = st.pop()
print ans

Solution (Python):
from collections import deque

S = input().split()
dq = deque()

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

print(dq[0])

Solution (Python):


numbers = list("1234567890")
querry = [n for n in input().split()]

stack = []

for q in querry:
    if q == "+":
        stack.append(stack.pop() + stack.pop())
    elif q == "-":
        stack.append(-stack.pop() + stack.pop())
    elif q == "*":
        stack.append(stack.pop() * stack.pop())
    else:
        stack.append(int(q))

print(stack.pop())

Solution (Python):


def nu(x):
    if x=="+" or x=="-" or x=="*":
        return 0
    else:
        return 1
def c(a,b,l):
    if l=="+":
        d=a+b
    elif l=="-":
        d=a-b
    else:
        d=a*b
    return d
F=[i for i in input().split()]
i=0
S=[]
while i<len(F):
    if nu(F[i])==0:
        S[-2]=c(S[-2],S[-1],F[i])
        S.pop(-1)
    else:
        S.append(int(F[i]))
    i+=1
print(S[0])

Solution (Python):


import sys, math, os


PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


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

print(stack[0])

Solution (Python):
class Stack:
    def __init__(self):
        self.values = []
        self.n = 0

    def pop(self):
        if self.n == 0:
            raise Exception("stack underflow")
        else:
            v = self.values[-1]
            del self.values[-1]
            self.n -= 1
            return v

    def push(self,x):
        self.values.append(x)
        self.n += 1


operators = set(['+', '-', '*'])
stack = Stack()

for op in raw_input().split(' '):
    if op in operators:
        b = stack.pop()
        a = stack.pop()
        if op == '+':
            stack.push(a+b)
        elif op == '-':
            stack.push(a-b)
        elif op == '*':
            stack.push(a*b)
        else:
            raise Exception("Unkown operator")
    else:
        stack.push(int(op))

print stack.pop()

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

answer=[]
for i in range(len(x)):
    if x[i].isdigit():
        answer.append(int(x[i]))
    elif x[i]=="+":
        t=answer.pop()+answer.pop()
        answer.append(t)
    elif x[i]=="-":
        t=-1*(answer.pop()-answer.pop())
        answer.append(t)
    elif x[i]=="*":
        t=answer.pop()*answer.pop()
        answer.append(t)

print(*answer)

Solution (Python):
S = []
A = raw_input().split()

for i in A:
    if i == '+':
        S.append(int(S.pop()) + int(S.pop()))
    elif i == '-':
        S.append(-int(S.pop()) + int(S.pop()))
    elif i == '*':
        S.append(int(S.pop()) * int(S.pop()))
    else:
        S.append(i)

print S[0]

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

for i in A:
    if i.isdigit():
        N.append(i)
    elif str(i) == '+':
        t1 = N.pop()
        t2 = N.pop()
        t3 = int(t2) + int(t1)
        N.append(t3)
    elif str(i) == '*':
        t1 = N.pop()
        t2 = N.pop()
        t3 = int(t2) * int(t1)
        N.append(t3)
    else:
        t1 = N.pop()
        t2 = N.pop()
        t3 = int(t2) - int(t1)
        N.append(t3)

print(N.pop())

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

Solution (Python):
from collections import deque

if __name__ == '__main__':
    x = [(int)(x) if x.isdigit() else x for x in input().split()]
    
    y = deque()

    for tmp in x:
        if tmp == '+':
            a = y.pop()
            b = y.pop()
            y.append(a+b)
        elif tmp == '-':
            a = y.pop()
            b = y.pop()
            y.append(b-a)
        elif tmp == '*':
            a = y.pop()
            b = y.pop()
            y.append(a*b)
        elif tmp == '/':
            a = y.pop()
            b = y.pop()
            y.append(b//a)
        else:
            y.append(tmp)

    print(y.pop())

Solution (Python):
from collections import deque

if __name__ == '__main__':
    x = [(int)(x) if x.isdigit() else x for x in input().split()]
    
    y = deque()

    for tmp in x:
        if tmp == '+':
            a = y.pop()
            b = y.pop()
            y.append(a+b)
        elif tmp == '-':
            a = y.pop()
            b = y.pop()
            y.append(b-a)
        elif tmp == '*':
            a = y.pop()
            b = y.pop()
            y.append(a*b)
        else:
            y.append(tmp)

    print(y.pop())

Solution (Python):


s = input().split()

stack = []

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

print(stack[0])

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

stack = []
for inp in a:
    if inp == "+":
        x = stack.pop()
        y = stack.pop()
        stack.append(x+y)
    elif inp == "-":
        x = stack.pop()
        y = stack.pop()
        stack.append(y-x)
    elif inp == "*":
        x = stack.pop()
        y = stack.pop()
        stack.append(x*y)
    else:
        stack.append(int(inp))

print(*stack)

Solution (Python):
fig = input()
symbol = fig.split(' ')
stack = []

for i in symbol:
    try:
        stack.append(int(i))
    except ValueError:
       if i == "+": stack.append(stack.pop()+stack.pop())
       elif i == "-": stack.append(-(stack.pop()-stack.pop()))
       elif i == "*": stack.append(stack.pop()*stack.pop())

print(stack[0])

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

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

stack = []

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

print(stack[0])

Solution (Python):
lst = raw_input().split()
lst2 = []
for v in lst:
    if v == "+":
        lst2[len(lst2)-2] += lst2.pop()
    elif v == "-":
        lst2[len(lst2)-2] -= lst2.pop()
    elif v == "*":
        lst2[len(lst2)-2] *= lst2.pop()
    elif v == "/":
        lst2[len(lst2)-2] /= lst2.pop()
    else:
        lst2.append(int(v))
print lst2[0]

Solution (Python):
def ALDS1_3A():
  stk, RPexp = [], list(input().split())
  for v in RPexp:
      if v in '+-*':
          n2, n1 = stk.pop(), stk.pop()
          stk.append(str(eval(n1+v+n2)))
      else:
          stk.append(v)
  print(stk.pop())

if __name__ == '__main__':
    ALDS1_3A()

Solution (Python):
A = list(map(str,input().split()))
Stack = []
for e in A:
    if e.isdigit():
        Stack.append(int(e))
    else:
        right = Stack.pop()
        left = Stack.pop()
        if e == "+":
            Stack.append(left+right)
        elif e == "-":
            Stack.append(left-right)
        elif e == "*":
            Stack.append(left*right)
        else:
            if right != 0:
                Stack.append(left//right)
            else:
                print("0?????????")
                exit()

print(Stack.pop())