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):
class Stack(object):
    def __init__(self, _max):
        if type(_max) == int:
            self._array = [None for i in range(0, _max)]
            self._next = 0

    def push(self, value):
        if self.isFull():
            raise IndexError
        self._array[self._next] = value
        self._next += 1

    def pop(self):
        if self.isEmpty():
            raise IndexError
        self._next -= 1
        value = self._array[self._next]
        self._array[self._next] = None
        return value

    def isEmpty(self):
        return self._next <= 0

    def isFull(self):
        return self._next >= len(self._array)


def calculator(exp):
    stack = Stack(100)
    ope = ["+", "-", "*"]
    for item in exp:
        if item in ope:
            val1 = stack.pop()
            val2 = stack.pop()
            if item == "+":
                stack.push(val2 + val1)
            elif item == "-":
                stack.push(val2 - val1)
            elif item == "*":
                stack.push(val2 * val1)
            else:
                raise ValueError
        else:
            stack.push(int(item))
    return stack.pop()


if __name__ == "__main__":
    exp = input().split()
    print(calculator(exp))

Solution (Python):
expr = input().split()
my_stack = []
def push(stack, item):
    return stack.append(item)

def pop(stack):
    return stack[:-1], stack[-1]

for item in expr:
    if item.isdigit():
        push(my_stack, int(item))
    elif item == '+':
        my_stack, a = pop(my_stack)
        my_stack, b = pop(my_stack)
        push(my_stack, a + b)
    elif item == '-':
        
        my_stack, a = pop(my_stack)
        my_stack, b = pop(my_stack)
        push(my_stack, b - a)
    elif item == '*':
        my_stack, a = pop(my_stack)
        my_stack, b = pop(my_stack)
        push(my_stack, a * b)

print(my_stack[0])

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




n = 1000
S = [0 for i in range(n)]

def isEmpty():
    global top
    if (top == 0):
        return True
    else:
        return False

def isFull():
    global top, n
    return top > n-1

def push(S, x):
    global top
    if isFull():
        print('error: overflow')
        return False
    top += 1
    S[top] = x

def pop(S):
    global top
    if isEmpty():
        print('error: underflow')
        return False
    top -= 1
    return S[top+1]

top = 0

for e in data:


    if e.isdigit():
        push(S, e)
    else:
        a = int(pop(S))
        b = int(pop(S))

        if e == '+':
            push(S, b + a)
        elif e == '-':
            push(S, b - a)
        elif e == '*':
            push(S, b * a)
        else:
            print('error: operand')


print(S[top])

Solution (Python):
list = input().split()
stack = []
for i in list:
    if ( i.isdigit() ):
        stack.append(int(i))
    elif (i == '+'):
        stack.append(stack.pop() + stack.pop())
    elif (i == '*'):
        stack.append(stack.pop() * stack.pop())
    elif (i == '-'):
        stack.append( (-1)*stack.pop() + stack.pop())

print(stack.pop())

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

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

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


stack = []

for i in range(len(data)):
	if data[i] == "+":
		stack[-2] = stack[-2] + stack[-1]
		del stack[-1]
		
	elif data[i] == "-":
		stack[-2] = stack[-2] - stack[-1]
		del stack[-1]
		
	elif data[i] == "*":
		stack[-2] = stack[-2] * stack[-1]
		del stack[-1]
		
	else:
		stack.append(int(data[i]))
		

print stack[0]

Solution (Python):
s=input().split()
a=[]
for i in s:
    if i in ["+","-","*"]:
        a1=str(a.pop())
        a2=str(a.pop())
        t = eval(a2+i+a1)
        a.append(t)
    else:
        a.append(int(i))
print(a.pop())

Solution (Python):
a = list(input().split())
l = []
for c in a:
    if c == '+':
        l.append(l.pop() + l.pop())
    elif c == '-':
        l.append((l.pop() - l.pop()) * -1)
    elif c == '*':
        l.append(l.pop() * l.pop())
    else:
        l.append(int(c))
print(l.pop())

Solution (Python):
def main() :
    lst = input().split()
    stack = []
    for i in lst :
        if i == '+' :
            x = stack.pop()
            y = stack.pop()
            stack.append(x + y)

        elif i == '-':
            x = stack.pop()
            y = stack.pop()
            stack.append(y - x)

        elif i == '*' :
            x = stack.pop()
            y = stack.pop()
            stack.append(x * y)

        else :
            stack.append(int(i))

    print(stack.pop())

if __name__ == '__main__' :
    main()

Solution (Python):
def main() :
    lst = input().split()
    stack = []
    for i in lst :
        if i == "+" :
            x = stack.pop()
            y = stack.pop()
            stack.append(x + y)

        elif i == "-" :
            x = stack.pop()
            y = stack.pop()
            stack.append(y - x)

        elif i == "*" :
            x = stack.pop()
            y = stack.pop()
            stack.append(x * y)

        else :
            stack.append(int(i))

    print(stack.pop())


if __name__ == "__main__" :
    main()

Solution (Python):
stack = input().split()
temp  =  []
num=0
for loop in stack:
    a = loop
    if a is "+":
        num = temp.pop() + temp.pop()
        temp.append(num)
    elif a is "-":
        b=temp.pop()
        c=temp.pop()
        num = c-b
        temp.append(num)
    elif a is "*":
        num = temp.pop() * temp.pop()
        temp.append(num)
    else:
        temp .append(int(a))

print(temp[0])

Solution (Python):
stack = input().split()
temp  =  []
num=0
for loop in stack:
    a = loop
    if a is "+":
        num = temp.pop() + temp.pop()
        temp.append(num)
    elif a is "-":
        b=temp.pop()
        c=temp.pop()
        num = c-b
        temp.append(num)
    elif a is "*":
        num = temp.pop() * temp.pop()
        temp.append(num)
    else:
        temp .append(int(a))

print(temp[0])

Solution (Python):
import re

data = input().split(' ')
stack = []
for w in data:
    if re.match(r'[0-9]', w):
        stack.append(w)
        
    else:
        r = stack.pop()
        l = stack.pop()
        stack.append(eval(str(l) + w + str(r)))
        

print(stack[0])

Solution (Python):
import sys

ERROR_INPUT = 'input is invalid'
OPECODE = ['+', '-', '*']
STACK = []


def main():
    inp = get_input()
    print(calc_stack(li=inp))


def calc_stack(li):
    if li[0] in OPECODE:
        ans = calc(left=STACK[-2], right=STACK[-1], ope=li[0])

        del li[0]
        if not li:
            return ans

        STACK.pop()
        STACK.pop()
        STACK.append(ans)

        return calc_stack(li=li)

    else:
        STACK.append(int(li[0]))
        del li[0]
        return calc_stack(li=li)


def calc(left, right, ope):
    if ope == '+':
        return left + right
    elif ope == '-':
        return left - right
    elif ope == '*':
        return left * right


def get_input():
    inp = input().split(' ')
    opecode_count = 0
    operand_count = 0

    for i in inp:
        if i in OPECODE:
            opecode_count += 1
        elif int(i) < 0 or int(i) > 10**6:
            print(ERROR_INPUT)
            sys.exit(1)
        else:
            operand_count += 1

    if opecode_count < 1 or opecode_count > 100:
        print(ERROR_INPUT)
        sys.exit(1)

    if operand_count < 2 or operand_count > 100:
        print(ERROR_INPUT)
        sys.exit(1)

    return inp


main()

Solution (Python):
import sys

sys.setrecursionlimit(10000)

ERROR_INPUT = 'input is invalid'
OPECODE = ['+', '-', '*']
BUF = []


def main():
    stack = get_input()
    ans = calc_stack(stack=stack)
    print(ans)


def calc_stack(stack):
    if stack[-1] in OPECODE:
        BUF.append(stack[-1])
        stack.pop()
        return calc_stack(stack=stack)
    else:
        right_num = int(stack[-1])
        stack.pop()
        if stack[-1] in OPECODE:
            BUF.append(right_num)
            BUF.append(stack[-1])
            stack.pop()
            return calc_stack(stack=stack)
        else:
            left_num = int(stack[-1])
            stack.pop()
            stack.append(calc(left_num, right_num, BUF[-1]))
            BUF.pop()
            stack.extend(reversed(BUF))
            BUF.clear()

        if len(stack) == 1:
            return stack[0]
        else:
            return calc_stack(stack=stack)


def calc(left, right, ope):
    if ope == '+':
        return left + right
    elif ope == '-':
        return left - right
    elif ope == '*':
        return left * right


def get_input():
    inp = input().split(' ')
    opecode_count = 0
    OPECODE_count = 0

    for i in inp:
        if i in OPECODE:
            opecode_count += 1
        elif int(i) < 0 or int(i) > 10**6:
            print(ERROR_INPUT)
            sys.exit(1)
        else:
            OPECODE_count += 1

    if opecode_count < 1 or opecode_count > 100:
        print(ERROR_INPUT)
        sys.exit(1)

    if OPECODE_count < 2 or OPECODE_count > 100:
        print(ERROR_INPUT)
        sys.exit(1)

    return inp


main()

Solution (Python):
import sys

sys.setrecursionlimit(10000)

ERROR_INPUT = 'input is invalid'
OPECODE = ['+', '-', '*']
BUF = []


def main():
    stack = get_input()
    ans = calc_stack(stack=stack)
    print(ans)


def calc_stack(stack):
    if stack[-1] in OPECODE:
        BUF.append(stack[-1])
        stack.pop()
        return calc_stack(stack=stack)
    else:
        right_num = int(stack[-1])
        stack.pop()
        if stack[-1] in OPECODE:
            BUF.append(right_num)
            BUF.append(stack[-1])
            stack.pop()
            return calc_stack(stack=stack)
        else:
            left_num = int(stack[-1])
            stack.pop()
            stack.append(calc(left_num, right_num, BUF[-1]))
            BUF.pop()
            stack.extend(reversed(BUF))
            BUF.clear()

        if len(stack) == 1:
            return stack[0]
        else:
            return calc_stack(stack=stack)


def calc(left, right, ope):
    if ope == '+':
        return left + right
    elif ope == '-':
        return left - right
    elif ope == '*':
        return left * right


def get_input():
    inp = input().split(' ')
    opecode_count = 0
    OPECODE_count = 0

    for i in inp:
        if i in OPECODE:
            opecode_count += 1
        elif int(i) < 0 or int(i) > 10**6:
            print(ERROR_INPUT)
            sys.exit(1)
        else:
            OPECODE_count += 1

    if opecode_count < 1 or opecode_count > 100:
        print(ERROR_INPUT)
        sys.exit(1)

    if OPECODE_count < 2 or OPECODE_count > 100:
        print(ERROR_INPUT)
        sys.exit(1)

    return inp


main()

Solution (Python):
import sys

ERROR_INPUT = 'input is invalid'
OPECODE = ['+', '-', '*']
STACK = []


def main():
    inp = get_input()
    print(calc_stack(li=inp))


def calc_stack(li):
    if li[0] in OPECODE:
        ans = calc(left=STACK[-2], right=STACK[-1], ope=li[0])

        del li[0]
        if not li:
            return ans

        STACK.pop()
        STACK.pop()
        STACK.append(ans)

        return calc_stack(li=li)

    else:
        STACK.append(int(li[0]))
        del li[0]
        return calc_stack(li=li)


def calc(left, right, ope):
    if ope == '+':
        return left + right
    elif ope == '-':
        return left - right
    elif ope == '*':
        return left * right


def get_input():
    inp = input().split(' ')
    opecode_count = 0
    operand_count = 0

    for i in inp:
        if i in OPECODE:
            opecode_count += 1
        elif int(i) < 0 or int(i) > 10**6:
            print(ERROR_INPUT)
            sys.exit(1)
        else:
            operand_count += 1

    if opecode_count < 1 or opecode_count > 100:
        print(ERROR_INPUT)
        sys.exit(1)

    if operand_count < 2 or operand_count > 100:
        print(ERROR_INPUT)
        sys.exit(1)

    return inp


main()

Solution (Python):
import sys

ERROR_INPUT = 'input is invalid'
OPECODE = ['+', '-', '*']
STACK = []


def main():
    inp = get_input()
    print(calc_stack(li=inp))


def calc_stack(li):
    for l in li:
        if l in OPECODE:
            STACK.append(calc(right=STACK.pop(), left=STACK.pop(), ope=l))
        else:
            STACK.append(int(l))

    return STACK[0]


def calc(left, right, ope):
    if ope == '+':
        return left + right
    elif ope == '-':
        return left - right
    elif ope == '*':
        return left * right


def get_input():
    inp = input().split(' ')
    opecode_count = 0
    operand_count = 0

    for i in inp:
        if i in OPECODE:
            opecode_count += 1
        elif int(i) < 0 or int(i) > 10**6:
            print(ERROR_INPUT)
            sys.exit(1)
        else:
            operand_count += 1

    if opecode_count < 1 or opecode_count > 100:
        print(ERROR_INPUT)
        sys.exit(1)

    if operand_count < 2 or operand_count > 100:
        print(ERROR_INPUT)
        sys.exit(1)

    return inp


main()

Solution (Python):

class Stack():
    def __init__(self):
        self.l = []
    
    def push(self, e):
        self.l.append(e)
        
    def pop(self):
        return self.l.pop()








ope = {"+", "-", "*"}

s = Stack()
exp = input().strip().split()

for e in exp:
    if e in ope:
        if e == '+':
            s.push(s.pop() + s.pop())
        elif e == '-':
            tmp = s.pop()
            s.push(s.pop() - tmp)
        else:
            s.push(s.pop() * s.pop())
    else:
        s.push(int(e))
print(s.pop())

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

stack = []

left_num, right_num = 0, 0
for tmp_str in input_str:
    if tmp_str == '+':
        right_num = stack.pop()
        left_num = stack.pop()
        stack.append(left_num + right_num)

    elif tmp_str == '-':
        right_num = stack.pop()
        left_num = stack.pop()
        stack.append(left_num - right_num)

    elif tmp_str == '*':
        right_num = stack.pop()
        left_num = stack.pop()
        stack.append(left_num * right_num)

    elif tmp_str == '/':
        right_num = stack.pop()
        left_num = stack.pop()
        stack.append(left_num / right_num)

    else:
        stack.append(int(tmp_str))

print(stack.pop())

Solution (Python):
notation = input().split()
stack = []
for s in notation:
    try:
        stack.append(int(s))
    except:
        n = 0
        if s == '+':
            n = stack[-2] + stack[-1]
        elif s == '-':
            n = stack[-2] - stack[-1]
        elif s == '*':
            n = stack[-2] * stack[-1]
        elif s == '/':
            n = stack[-2] / stack[-1]

        stack = stack[:-2] + [n]

assert(len(stack) == 1)
print(stack[0])

Solution (Python):
if __name__ == '__main__':
	l = input().split()
	count = 0

	for i in range(len(l)):
		i -= count
		if l[i] == '+':
			l[i - 2] = str(int(l[i - 2])  + int(l[i - 1]))
			l.pop(i - 1)
			l.pop(i - 1)
			count += 2

		elif l[i] == '-':
			l[i - 2] = str(int(l[i - 2])  - int(l[i - 1]))
			l.pop(i - 1)
			l.pop(i - 1)
			count += 2

		elif l[i] == '*':
			l[i - 2] = str(int(l[i - 2])  * int(l[i - 1]))
			l.pop(i - 1)
			l.pop(i - 1)
			count += 2

		else:
			continue
	if len(l) > 1:
		print("Error")
	else:
		print(l[0])

Solution (Python):
x = input().split()
s = []
for i in x:
    try:
        i = int(i)
        s.append(i)
    except:
        s.append(eval('{b}{ope}{a}'.format(a=s.pop(), ope=i, b=s.pop())))
print(s[0])

Solution (Python):


if __name__ == '__main__':

    stack = []
    line = input().split(" ")
    for s in line:
        if s.isdigit():
            stack.append(s)
        else:
            v2 = stack.pop()
            v1 = stack.pop()
            stack.append(str(eval(v1 + s + v2)))

    print(stack.pop())

Solution (Python):
from operator import *
li = []
for s in input().split():
    if s.isdigit():
        li.append(int(s))
    else:
        b = li.pop()
        a = li.pop()
        li.append({"+":add, "-":sub, "*":mul}[s](a, b))
print(li[-1])

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

for c in e:
    if c in "+-*":
        a = s.pop()
        b = s.pop()
        s.append(str(eval(b + c + a)))
    else:
        s.append(c)

print(s[0])

Solution (Python):
s=[]
for i in input().split():
 n=len(s)-1
 if i=='+':s.append(s[n-1]+s[n]);s.pop(n-1);s.pop(n-1)
 elif i=='-':s.append(s[n-1]-s[n]);s.pop(n-1);s.pop(n-1)
 elif i=='*':s.append(s[n-1]*s[n]);s.pop(n-1);s.pop(n-1)
 elif i=='/':s.append(s[n-1]/s[n]);s.pop(n-1);s.pop(n-1)
 else:s.append(int(i))
print(*s)

Solution (Python):
s=[]
for i in input().split():
 n=len(s)-1
 if i=='+':s.append(s[n-1]+s[n]);s.pop(n-1);s.pop(n-1)
 elif i=='-':s.append(s[n-1]-s[n]);s.pop(n-1);s.pop(n-1)
 elif i=='*':s.append(s[n-1]*s[n]);s.pop(n-1);s.pop(n-1)
 else:s.append(int(i))
print(*s)

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

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

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

stack = []

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

print(stack[0])

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

class Stack():
	def __init__(self):
		self.S=[]
		self.top=-1
		
	def initialize(self):
		self.top=-1
	
	def isEmpty(self):
		if self.top==-1:
			return('Empty')
		else:
			return('Not Empty')
	
	def push(self,x):
		self.S.append(x)
		self.top+=1
	
	def pop(self):
		a=self.S[self.top]
		del self.S[self.top]
		self.top-=1
		return(a)
		
	
	
	
c=Stack()
for i in range(len(eq)):
	if eq[i].isdigit():
		c.push(eq[i])
	else:
		a=c.pop()
		b=c.pop()
		if eq[i]=='+':
			c.push(int(b)+int(a))
		elif eq[i]=='-':
			c.push(int(b)-int(a))
		else:
			c.push(int(b)*int(a))
			
print(c.pop())

Solution (Python):
data = input().split(" ");

def reverse_polish_notation(data):
    operands = [];
    for n in data:
        if n not in "*+-":
            operands.append(int(n));
        else:
            operand_second = operands.pop();
            operand_first = operands.pop();
            operands.append(calculate(n, operand_first, operand_second));
    return operands[0];

def calculate(operator, a, b):
    if operator == "*":
        return a * b;
    elif operator == "-":
        return a - b;
    elif operator == "+":
        return a + b;

print(reverse_polish_notation(data));

Solution (Python):
s=[i for i in input().split()]
k=[]

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

    else:
        k.append(s[i])

print(k[0])

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

stack = []
for i in s:
    if i.isdigit():
        stack.append(int(i))
    else:
        if i == "+":
            f = lambda x, y: x + y
        elif i == "-":
            f = lambda x, y: x - y
        elif i == "*":
            f = lambda x, y: x * y

        y = stack.pop()
        x = stack.pop()
        stack.append(f(x, y))

print(stack[0])

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

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

print(stack.pop())

Solution (Python):
import sys
str = ""
for line in sys.stdin:
	str = line

numbers = str.split()

answer = 0
stackList = []

for number in numbers :

    if number == '+' :
        answer = int(stackList.pop()) + int(stackList.pop())
        stackList.append(answer)
    elif number == '-' :
        x = int(stackList.pop())
        y = int(stackList.pop())
        answer = y - x
        stackList.append(answer)
    elif number == '*' :
        answer = int(stackList.pop()) * int(stackList.pop())
        stackList.append(answer)
    else :
        stackList.append(number)

print(answer)

Solution (Python):
import sys
str = ""
for line in sys.stdin:
	str = line

numbers = str.split()

answer = 0
stackList = []

for number in numbers :

    if number == '+' :
        answer = int(stackList.pop()) + int(stackList.pop())
        stackList.append(answer)
    elif number == '-' :
        x = int(stackList.pop())
        y = int(stackList.pop())
        answer = y - x
        stackList.append(answer)
    elif number == '*' :
        answer = int(stackList.pop()) * int(stackList.pop())
        stackList.append(answer)
    else :
        stackList.append(number)

print(answer)

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

OPERATOR = {
  '+': lambda a, b: a + b,
  '*': lambda a, b: a * b,
  '-': lambda a, b: a - b,
  '/': lambda a, b: a / b,
}

stack = []
for item in list:
  if item in OPERATOR:
    b = stack.pop()
    a = stack.pop()
    stack.append(OPERATOR[item](a, b))
  else:
    stack.append(int(item))

print(stack.pop())

Solution (Python):

from collections import deque
operators = {'+','*','-'}

def operate(L,R,C):
  if C == '+':
    return L + R
  elif C == '*':
    return L * R
  else: 
    return L - R

raw = input().split()
stack = deque()
for C in raw:
  if C in operators:
    R = stack.pop()
    L = stack.pop()
    stack.append(operate(L,R,C))
  else:
    stack.append(int(C))
print(stack.pop())

Solution (Python):
hoge = list()
for elem in (elem for elem in input().split()):
    if elem == '+':
        elem = int(hoge.pop()) + int(hoge.pop())
    elif elem == '*':
        elem = int(hoge.pop()) * int(hoge.pop())
    elif elem == '-':
        elem = -1*int(hoge.pop()) + int(hoge.pop())
    hoge.append(elem)
print (elem)

Solution (Python):
a = input().split()
b = []
for i in a:
    if i.isdigit():
        b.append(i)
    else:
        c = b.pop()
        d = b.pop()
        ans = eval(str(d)+i+str(c))
        b.append(ans)
print(b[0])

Solution (Python):



import sys

def calc(operator, stack):
    val_b = stack.pop()
    val_a = stack.pop()

    if operator == '+':
        stack.append(val_a + val_b)
    elif operator == '-':
        stack.append(val_a - val_b)
    elif operator == '*':
        stack.append(val_a * val_b)
    else:
        raise ValueError

stack = list()
inline = sys.stdin.readline().split()  
for val in inline:
    if val in '+-*':
        calc(val, stack)
    else:
        stack.append(int(val))

print(stack.pop())

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

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

print(b[0])

Solution (Python):
import re

def revPolish(f):
    f = re.sub(r'(\-?\d+\.?\d*?)\s(\-?\d+\.?\d*?)\s([\+\-\*/])(?!\d)',
        lambda m: str(eval(m.group(1) + m.group(3) + m.group(2))),
        f)
    if f[-1] in ('+','-','*','/'):
        return revPolish(f)
    else:
        return f

print(revPolish(input()))

Solution (Python):
import re

def revPolish(f):
    f = re.sub(r'(\-?\d+\.?\d*)\s(\-?\d+\.?\d*)\s([\+\-\*/])(?!\d)',
        lambda m: str(eval(m.group(1) + m.group(3) + m.group(2))),
        f)
    if f[-1] in ('+','-','*','/'):
        return revPolish(f)
    else:
        return f

print(revPolish(input()))

Solution (Python):
import re

def revPolish(f):
    f = re.sub(r'(\-?\d+\.?\d*)\s(\-?\d+\.?\d*)\s([\+\-\*/])(?!\d)',
        lambda m: str(eval(m.group(1) + m.group(3) + m.group(2))),
        f)
    if f[-1] in ('+','-','*','/'):
        return revPolish(f)
    else:
        return f

if __name__=='__main__':
    print(revPolish(input()))

Solution (Python):
import re
pat = re.compile(r'(\-?\d+\.?\d*)\s(\-?\d+\.?\d*)\s([\+\-\*/])(?!\d)')

def revPolish(f):
    global pat
    f = pat.sub(lambda m: str(eval(m.group(1) + m.group(3) + m.group(2))),f)
    if f[-1] in '+-*/':
        return revPolish(f)
    else:
        return f

print(revPolish(input()))

Solution (Python):
L = list(map(str, input().split(' ')))
que = []
while len(L) != 0:
    if L[0] not in ('+', '-', '*'):
        que.append(int(L.pop(0)))
    else:
        if L[0] == '+':
            a = que[-2] + que[-1]
        elif L[0] == '-':
            a = que[-2] - que[-1]
        elif L[0] == '*':
            a = que[-2] * que[-1]
        L.pop(0)
        que.pop(-1)
        que.pop(-1)
        que.append(a)
print(que[0])

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

for i in range(len(A)):
    if A[i]=='+':
        y=B.pop()
        x=B.pop()
        B.append(x+y)
    elif A[i]=='-':
        y=B.pop()
        x=B.pop()
        B.append(x-y)
    elif A[i]=='*':
        y=B.pop()
        x=B.pop()
        B.append(x*y)
    else:
        B.append(int(A[i]))

print(B[0])

Solution (Python):

from collections import deque

inputs = deque(raw_input().split())
q = deque()
while len(inputs):
    op = inputs.popleft()
    if op == '+':
        q.append(q.pop() + q.pop())
    elif op == '-':
        v1 = q.pop()
        v2 = q.pop()
        q.append(v2 - v1)
    elif op == '*':
        q.append(q.pop() * q.pop())
    else:
        q.append(int(op))

print q.pop()

Solution (Python):
l = []
o = ["+", "-", "*"]
for i in input().split():
  if i in o:
    t = eval("{0}{1}{2}".format(l[-2], i, l[-1]))
    l.pop(-1)
    l[-1] = t
  else: l += [int(i)]
print(*l)

Solution (Python):
A = input().split()
S, top = [0], 0


def push(x):
    global top, S
    top += 1
    if len(S) < top + 1:
        S.append(x)
    else:
        S[top] = x


def pop(x):
    global top, S
    top -= 2
    if x == "+":
        push(int(S[top + 1]) + int(S[top + 2]))
    elif x == "-":
        push(int(S[top + 1]) - int(S[top + 2]))
    elif x == "*":
        push(int(S[top + 1]) * int(S[top + 2]))


for i in range(len(A)):
    if str(A[i]).isdigit():
        push(int(A[i]))
    else:
        pop(A[i])
print(S[1])

Solution (Python):
def reverse_polish_calculator(s):
    """Calculate a reverse polish notation s.
    + - * operators can be used in s. Only positive integer is
    supported for operand.

    >>> reverse_polish_calculator("1 2 +")
    3
    >>> reverse_polish_calculator("1 2 + 3 4 - *")
    -3
    """
    def calc(val1, op, val2):
        if op == '+':
            return val1 + val2
        elif op == '-':
            return val1 - val2
        elif op == '*':
            return val1 * val2
        else:
            raise ValueError()

    stack = []
    for c in s.split():
        if c.isnumeric():
            stack.append(int(c))
        else:
            v2 = stack.pop()
            v1 = stack.pop()
            stack.append(calc(v1, c, v2))

    return stack.pop()


def run():
    s = input()
    print(reverse_polish_calculator(s))


if __name__ == '__main__':
    run()

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

stk = []
opr = ['+', '-', '*']

for e in seq:
    if e in opr:
        if e == '+':
            res = stk[-2] + stk[-1]
        elif e == '-':
            res = stk[-2] - stk[-1]
        elif e == '*':
            res = stk[-2] * stk[-1]
        stk = stk[:-2] + [res]
    else:
        stk.append(int(e))

print(stk[0])

Solution (Python):
def calculator(op, x, y):
    if op == '+':
        return x + y
    elif op == '-':
        return y - x
    else:
        return x * y


raw = [r for r in input().split()]
for i in range(len(raw)):
    try:
        raw[i] = int(raw[i])
    except:
        continue

arr = []
buff = 0
for i in range(len(raw)):
    if isinstance(raw[i], int):
        arr.append(raw[i])
    else:
        buff = calculator(raw[i], arr.pop(), arr.pop())
        arr.append(buff)

print(*arr)

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

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

Solution (Python):
from functools import reduce
rpn = lambda s: int(reduce(
    lambda x, y: (
        x[:-2] + [str(eval(x[-2]+y[0]+x[-1]))] if y in '+-*'
        else x + [y]
    ), s.split(), []
)[0])
print(rpn(input()))

Solution (Python):
print((lambda s: int(__import__('functools').reduce(
    lambda x, y: (
        x[:-2] + [str(eval(x[-2]+y[0]+x[-1]))] if y in '+-*'
        else x + [y]
    ), s.split(), []
)[0]))(input()))

Solution (Python):
s=list(input().split())
a=[]
for x in s:
    if x in ['+','-','*']:
        c,b=str(a.pop()),str(a.pop())
        b+=x+c
        a+=[int(eval(b))]
    else:a+=[int(x)]
print(a.pop())

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

operater=["+","*","-","/"]
cal=[]
k=0
for i in range(len(d)):
    if d[i] not in operater:
        cal.append(int(d[i]))
        k+=1
    else:
        j=operater.index(d[i])
        if j==0:
            x=cal[k-1]+cal[k-2]
        elif j==1:
            x=cal[k-1]*cal[k-2]
        elif j==2:
            x=cal[k-2]-cal[k-1]
        else:
            x=cal[k-2]/cal[k-1]
        cal.pop()
        cal.pop()
        cal.append(x)
        print
        k-=1
print(cal[0])