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 106

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 &times; 109 ≤ values in the stack ≤ 109

Sample Input 1

1 2 +

Sample Output 1

3

Sample Input 2

1 2 + 3 4 - *

Sample Output 2

-3

Notes

Template in C



Sample input:
1 2 +


Sample output:
3

Submission status: Accepted

Solution code:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

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

Submission status: Accepted

Solution code:
from collections import deque
s=input().split()
q=deque([])
for i in range(len(s)):
    if s[i]=="+":
        a=q.pop()
        b=q.pop()
        calc=b+"+"+a
        q.append(str(eval(calc)))
    elif s[i]=='-':
        a=q.pop()
        b=q.pop()
        calc=b+"-"+a
        q.append(str(eval(calc)))
    elif s[i]=='*':
        a=q.pop()
        b=q.pop()
        calc=b+"*"+a
        q.append(str(eval(calc)))
    else:
        q.append(s[i])
print(*q)

Submission status: Accepted

Solution code:
line = list(map(str,input().split()))
 
#数字スタック
S = []
 
for tmp_ch in line:
 
    if tmp_ch in ['+','-','*']:
        b = int(S.pop())
        a = int(S.pop())
 
        if tmp_ch == '+':
            S.append(a+b)
        elif tmp_ch == '-':
            S.append(a-b)
        else:
            S.append(a*b)
    else:
        S.append(tmp_ch)
 
print("%d"%(S[0]))

Submission status: Accepted

Solution code:
class Cell:
    def __init__(self, value):
        self.value = value
        self.next = None


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

    def push(self, d):
        new = Cell(d)
        new.next = self.top
        self.top = new

    def pop(self):
        if self.top is None:
            print('Stack Under Flow!!')
            return
        else:
            t = self.top.value
            p = self.top
            self.top = self.top.next
            del(p)
            return t

l = list(input().split())
st = Stack()
for i in l:
    if i == '-':
        t1 = st.pop()
        t2= st.pop()
        st.push(t2-t1)
    elif i=='*':
        t1 = st.pop()
        t2= st.pop()
        st.push(t1*t2)
    elif i == '+':
        t1 = st.pop()
        t2 = st.pop()
        st.push(t1 + t2)
    else:
        st.push(int(i))
print(st.pop())

Submission status: Accepted

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

while len(S)>1:
    for s in S:
        if s=="+":
            s1=stack.pop(-1)
            s2=stack.pop(-1)
            stack.append(s1+s2)
        elif s=="-":
            s1=stack.pop(-1)
            s2=stack.pop(-1)
            stack.append(s2-s1)
        elif s=="*":
            s1=stack.pop(-1)
            s2=stack.pop(-1)
            stack.append(s1*s2)
        else:
            stack.append(int(s))
    S=stack
print(S[0])

Submission status: Accepted

Solution code:
from collections import deque
S = input().split()
stack = deque([])
for s in S:
    if s == "+":
        s1 = stack.pop()
        s2 = stack.pop()
        stack.append(s1+s2)
    elif s == "-":
        s1 = stack.pop()
        s2 = stack.pop()
        stack.append(s2-s1)
    elif s == "*":
        s1 = stack.pop()
        s2 = stack.pop()
        stack.append(s1*s2)
    elif s == "/":
        s1 = stack.pop()
        s2 = stack.pop()
        stack.append(s1/s2)
    else:
        stack.append(int(s))
print(stack[0])

Submission status: Accepted

Solution code:
if __name__ == '__main__':
	form = input().split()
	stack = []
	for i in range(len(form)):
		if form[i] == "+":
			y=stack.pop()
			x=stack.pop()
			stack.append(x+y)
		elif form[i] == "-":
			y=stack.pop()
			x=stack.pop()
			stack.append(x-y)
		elif form[i] == "*":
			y=stack.pop()
			x=stack.pop()
			stack.append(x*y)
		elif form[i] == "/":
			y=stack.pop()
			x=stack.pop()
			stack.append(x/y)
		elif form[i] == "%":
			y=stack.pop()
			x=stack.pop()
			stack.append(x%y)
		else:
			stack.append(int(form[i]))
	print(stack[0])

Submission status: Accepted

Solution code:
A = list(input().split())

S = []

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

print(int(S.pop()))

Submission status: Accepted

Solution code:
sikis = input().split()
cue = []

for ope in sikis:
    if ope == '+':
        cue[-2] = cue[-1] + cue[-2]
        cue.pop(-1)
    elif ope == '-':
        cue[-2] = cue[-2] - cue[-1]
        cue.pop(-1)
    elif ope == '*':
        cue[-2] = cue[-1] * cue[-2]
        cue.pop(-1)
    else:
        cue.append(int(ope))
        
print(cue[-1])

Submission status: Accepted

Solution code:
class Stack():
    def __init__(self):
        self.top = -1
        self.lists = []
    def push(self,x):
        self.top += 1
        self.lists.append(0)
        self.lists[self.top] = x
    def pop(self):
        if self.top >= 0:
            self.top -= 1
            return self.lists[self.top+1]
        else :
            print("Error")
def main():
    input_list = [i for i in input().split()]
    stack = Stack()
    for i in range(len(input_list)):
        if input_list[i] == '+':
            number_1 = stack.pop()
            number_2 = stack.pop()
            stack.push(number_2+number_1)
        elif input_list[i] == '-':
            number_1 = stack.pop()
            number_2 = stack.pop()
            stack.push(number_2-number_1)
        elif input_list[i] == '*':
            number_1 = stack.pop()
            number_2 = stack.pop()
            stack.push(number_2 * number_1)
        else:
            stack.push(int(input_list[i]))
    print(stack.lists[stack.top])
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# ALDS1_3_A

def calc(a, b, op):
    
    if op == "+":
        return b + a
    elif op == "-":
        return b - a
    elif op == "*":
        return b * a

operator_list = ("+", "-", "*")
list = input().split()
stack = []
for i in list:
    if i in operator_list:
        a = stack.pop()
        b = stack.pop()
        stack.append(calc(a, b, i))
    else:
        stack.append(int(i))

print(stack.pop())

Submission status: Accepted

Solution code:
class Stack():
    def __init__(self):
        self.items = []

    def is_empty(self):
        return self.items == []

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

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



if __name__ == "__main__":
    stack = Stack()
    a = input().split()
    ans = 0

    for x in a:
        if x == "+":
            stack.push(stack.pop() + stack.pop())
        elif x == "-":
            stack.push(-stack.pop() + stack.pop())
        elif x == "*":
            stack.push(stack.pop() * stack.pop())
        else:
            x = int(x)
            stack.push(x)
    print(stack.pop())

Submission status: Accepted

Solution code:
input_line = input()
stack = []
for s in input_line.split(' '):
    if s.isdecimal():
        stack.append(int(s))
    else:
        stack.append(eval("{2}{1}{0}".format(stack.pop(), s, stack.pop())) )
    # print(stack)
print(stack.pop())

Submission status: Accepted

Solution code:
strings = input().split()

stack = []

for string in strings:
    if string in ["+", "-", "*"]:
        y = stack.pop()
        x = stack.pop()
        z = eval(x + string + y)
        stack.append(str(z))
    else:
        stack.append(string)

print(stack.pop())

Submission status: Accepted

Solution code:
strings = input().split()

stack = []

for string in strings:
    if string in ["+", "-", "*"]:
        y = stack.pop()
        x = stack.pop()
        z = eval(x + string + y)
        stack.append(str(z))
    else:
        stack.append(string)

print(stack.pop())

Submission status: Accepted

Solution code:
a = list(input().split())
b = [0]
top = 0
for i in a:
  if i == '+':
    tmp = b[top] + b[top-1]
    del b[top]
    b[top-1] = tmp
    top -= 1
  elif i == '-':
    tmp = b[top-1] - b[top]
    del b[top]
    b[top-1] = tmp
    top -= 1
  elif i == '*':
    tmp = b[top] * b[top-1]
    del b[top]
    b[top-1] = tmp
    top -= 1
  else:
    b.append(int(i))
    top += 1
print(b[1])

Submission status: Accepted

Solution code:
operators = ['+', '-', '*']

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

for ope in ope_input:
    if ope not in operators:
        stack.append(ope)
    else:
        b = stack.pop()
        a = stack.pop()
        stack.append(str(eval(a + ope + b)))

print(stack.pop())

Submission status: Accepted

Solution code:
da=list(map(str,input().split()))
def ju(k):
    if k=='+' or k=='-' or k=='*':
        return False
    else:
        return True

def change(li):
    n=len(li)
    if n==1:
        return li[0]
    ret=[]
    i=0
    while(i<n-2):
        if ju(li[i]) and ju(li[i+1]) and (not ju(li[i+2])):
            x,y=int(li[i]),int(li[i+1])
            if li[i+2]=='+':
                ret.append(str(x+y))
            elif li[i+2]=='-':
                ret.append(str(x-y))
            else:
                ret.append(str(x*y))
            i+=3
        else:
            ret.append(li[i])
            i+=1
    while i<n:
        ret.append(li[i])
        i+=1
    return change(ret)

print(change(da))

Submission status: Accepted

Solution code:
L=input().split( )
l=len(L)
I=[0 for i in range(l)]
#構造体やクラスとしての実装を
for i in range(l):
    if str.isnumeric(L[i])==True:
        I[i]=int(L[i])
    else:
        I[i]=L[i]
S=["" for i in range(l)]

def push(M,x,top):
    top+=1
    M[top]=x
    return(M,top)


def pop(M,top):
    temp=M[top]
    M[top]=""
    top-=1
    return(M,top,temp)


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

top=-1
for i in range(l):
    if str.isdigit(L[i])==True:
        top=push(S,I[i],top)[1]
        #print(S,top)
    else:
        temp1=pop(S,top)[2]
        S=pop(S,top)[0]
        top=pop(S,top)[1]
        #print(top,temp1)
        temp2=pop(S,top)[2]
        S=pop(S,top)[0]
        top=pop(S,top)[1]
        #print(top,temp2)
        #print(temp2,temp1,I[i])
        top+=1
        S[top]=operator(temp2,temp1,I[i])
        #print(S,S[top],top)
print(S[0])

Submission status: Accepted

Solution code:
from functools import reduce

s = list(input().split())
#numA = None
#numB = None
temp = []
#ans = []
#ans = None

for i in range(len(s)):
    if s[i] == '+':
        temp.append(temp.pop() + temp.pop())
    elif s[i] == '-':
        temp.append(-(temp.pop() - temp.pop()))
    elif s[i] == '*':
        temp.append(temp.pop() * temp.pop())
    else:
        temp.append(int(s[i]))

#    print("\ns[i]: " + s[i])


print(temp.pop())

Submission status: Accepted

Solution code:
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

line = list(map(str,input().split()))
S=[]
for tmp_ch in line:
    if tmp_ch in ['+','-','*']:
        b=int(S.pop())
        a=int(S.pop())

        if tmp_ch == '+':
            S.append(a+b)
        elif tmp_ch =='-':
            S.append(a-b)
        else:
            S.append(a*b)
    else:
        S.append(tmp_ch)

print("%d"%(S[0]))

Submission status: Accepted

Solution code:
f = input().split()
stack = []
for v in f:
  if v == "+":
    stack.append(stack.pop()+stack.pop())
  elif v == "-":
    stack.append(-stack.pop()+stack.pop())
  elif v == "*":
    stack.append(stack.pop()*stack.pop())
  else:
    stack.append(int(v))
print(stack.pop())

Submission status: Accepted

Solution code:
def solve():
     siki = input().split()
     que = []
     for i in siki:
          if i =="+" or i =="-" or i =="*" or i =="/":
               a = que.pop()
               b = que.pop()
               if i == "+":
                    que.append(a+b)
               if i == "-":
                    que.append(b-a)
               if i == "*":
                    que.append(a*b)
               if i == "/":
                    que.append(b/a)
          else:
               que.append(int(i))
     print(que[-1])
solve()

Submission status: Accepted

Solution code:
def cal(ope,a,b):
    if ope=="+":
        return a+b
    if ope=="-":
        return a-b
    if ope=="*":
        return(a*b)

data=input().split()
ans=[]
for i in data:
    if i.isdecimal():
        ans.append(int(i))
    else:
        b=ans.pop()
        a=ans.pop()
        ans.append(cal(i,a,b))

print(ans[0])

Submission status: Accepted

Solution code:
inp = list(input().split())
s = list()

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

print(s[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
given = list(map(str,input().split()))
stack = []

for j in given:
    try:
        i = int(j)
    except ValueError:
        i = str(j)
    if type(i) == int:
        stack.append(int(i))
    else:
        r = stack.pop()
        l = stack.pop()
        if i=="+":
            stack.append(l+r)
        elif i=="-":
            stack.append(l-r)
        elif i== "*":
            stack.append(l*r)
print(stack[0])

Submission status: Accepted

Solution code:
L = list(input().split())
stack = []
ope = ['+','-','*']
for i in range(len(L)):
    if L[i] not in ope:
        stack.append(L[i])
    else:
        a = stack.pop()
        b = stack.pop()
        k = b+L[i]+a
        stack.append(str(eval(k)))
print(stack[0])

Submission status: Accepted

Solution code:
class Stock():
    def __init__(self, length):
        self.S = [None for _ in range(length)]
        self.top = 0

    def isEmpty(self):
        return self.top == 0

    def isFull(self):
        return self.top >= len(self.S) -1

    def push(self, x):
        if self.isFull():
            raise

        self.top += 1

        self.S[self.top] = x

    def pop(self):
        if self.isEmpty():
            raise

        self.top -= 1

        return self.S[self.top + 1]


class StockCalc(Stock):
    def calc(self, x):
        if x.isdigit():
            super().push(int(x))
            return

        b = super().pop()
        a = super().pop()

        if x == "+":
            y = a + b
        elif x == "-":
            y = a - b
        elif x == "*":
            y = a * b
        else:
            raise

        super().push(y)


list_input = list(input().split())

stock = StockCalc(len(list_input))


for x in list_input:
    stock.calc(x)

print(stock.pop())

Submission status: Accepted

Solution code:
input_string = list(input().split())

stack = []
for s in input_string:
  if s == "+":
    a = stack.pop()
    b = stack.pop()
    c = a + b
    stack.append(c)
  elif s == "-":
    a = stack.pop()
    b = stack.pop()
    c = b - a
    stack.append(c)
  elif s == "*":
    a = stack.pop()
    b = stack.pop()
    c = b * a
    stack.append(c)
  else:
    stack.append(float(s))

print(int(stack.pop()))

Submission status: Accepted

Solution code:
A = list(input().split())
stack = []
for i in A:
    if(i == '+'):
        ns = stack.pop()
        ms = stack.pop()
        s = ms+ns
        stack.append(s)
    elif(i == '-'):
        nd = stack.pop()
        md = stack.pop()
        d = md-nd
        stack.append(d)
    elif(i == '*'):
        np = stack.pop()
        mp = stack.pop()
        p = mp*np
        stack.append(p)
    else:
        n = int(i)
        stack.append(n)
print(stack[0])

Submission status: Accepted

Solution code:
S = list(input().split(" "))
tmp = []

for i in range(len(S)):
  if S[i] == "+":
    tmp.append(tmp.pop()+tmp.pop())
  elif S[i] == "-":
    tmp.append(tmp.pop(-2)-tmp.pop())
  elif S[i] == "*":
    tmp.append(tmp.pop()*tmp.pop())    
  else:
    tmp.append(int(S[i]))
print(int(tmp[0]))
#print(" ".join(map(str, S)))

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
a = list(input().split())
stack = list()

num = 0
for i in a:
    if i.isdigit():
        stack.append(i)
        num += 1
        continue
    elif i == '+':
        ans = int(stack[num-2]) + int(stack[num-1])
    elif i == '-':
        ans = int(stack[num-2]) - int(stack[num-1])
    elif i == '*':
        ans = int(stack[num-2]) * int(stack[num-1])
    elif i == '/':
        ans = int(stack[num-2]) / int(stack[num-1])
    stack.pop()
    stack.pop()
    stack.append(ans)
    num -= 1

print(stack[0])

Submission status: Accepted

Solution code:
#ALDS1_3_A
exp = input().split()
stack = []
for op in exp:
  if op not in ["+", "-", "*"]:
    stack.append(int(op))
  else:
    if op == "+":
      ans = stack[-2] + stack[-1]
    elif op == "-":
      ans = stack[-2] - stack[-1]
    elif op == "*":
      ans = stack[-2] * stack[-1]
    del stack[-2:]
    stack.append(ans)
print(ans)

Submission status: Accepted

Solution code:
input_num=input().split()
num=[]

for i in input_num:
	if i=='+' or i=='-' or i=='*' or i=='/':
		n1=int(num.pop())
		n2=int(num.pop())
		
		if i=='+':
			num.append(n2+n1)
		elif i=='-':
			num.append(n2-n1)
		elif i=='*':
			num.append(n2*n1)
		else:
			num.append(n2/n1)
	else:
		num.append(int(i))
print(num[0])

Submission status: Accepted

Solution code:
def push(x):
  S.append(x)

def pop():
  return int(S.pop())

list = list(input().split())
S = []

for i in range(len(list)):
  if list[i] == '+':
    a = pop()
    b = pop()
    push(a + b)
  elif list[i] == '-':
    b = pop()
    a = pop()
    push(a - b)
  elif list[i] == '*':
    a = pop()
    b = pop()
    push(a * b)
  else :
    push(list[i])

print(S.pop())

Submission status: Accepted

Solution code:
x = list(map(str, input().split()))
num = []
for v in x:
    try:
        num.append(int(v))
    except:
        if v == '+':
            num.append(num.pop(-2) + num.pop(-1))
        elif v == '*':
            num.append(num.pop(-2) * num.pop(-1))
        elif v == '-':
            num.append(num.pop(-2) - num.pop(-1))
print(num[0])

Submission status: Accepted

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

print(stack[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
line = list(map(str, input().split()))
S = []
for i in line:
    if i in ['+', '-', '*']:
        b = int(S.pop())
        a = int(S.pop())

        if i == '+':
            S.append(a+b)
        elif i == '-':
            S.append(a-b)
        else:
            S.append(a*b)
    else:
        S.append(i)

print(S[0])

Submission status: Accepted

Solution code:
N = list(input().split())
A = []
for i in range(len(N)):
    if N[i] == '+':
        num1 = A.pop()
        num2 = A.pop()
        A.append(num2 + num1)
        continue
    elif N[i] == '-':
        num1 = A.pop()
        num2 = A.pop()
        A.append(num2 - num1)
        continue
    elif N[i] == '*':
        num1 = A.pop()
        num2 = A.pop()
        A.append(num2 * num1)
        continue
    A.append(int(N[i]))  
    
print(A[0])

Submission status: Accepted

Solution code:
#import numpy as np
Input = str(input())
Input = Input.split(" ")
S = []
L = len(Input)
# S= np.zeros([100])
for i in range(100):
    S.append(0)

Look = 0
for i in range(L):
    if Input[i] == "+":
        S[Look - 2] = S[Look - 2] + S[Look - 1]
        Look -= 1
        
    elif Input[i] == "-":
        S[Look - 2] = S[Look - 2] - S[Look - 1]
        Look -= 1
    elif Input[i] == "*":
        S[Look - 2] = S[Look - 2] * S[Look - 1]
        Look -= 1
    else:
        S[Look] = int(Input[i])
        Look += 1
        
    Look%=100
print(int(S[Look-1]))

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

Solution code:
notation = input().split()
operators = ('+', '-', '*')
result = []
for n in notation:
    if n not in operators:
        result.append(n)
    else:
        b = result.pop()
        a = result.pop()
        result.append(str(eval(a+n+b)))
print(result[0])

Submission status: Accepted

Solution code:
a = input().split()
lst = []
N = len(a)

for _ in range(N):
    v = a.pop(0)
    if v.isdigit():
        lst.append(int(v))
       
    else:
        y = int(lst.pop(-1))
        x = int(lst.pop(-1))

        if v == '+':
            lst.append(x + y)
        elif v == '*':
            lst.append(x * y)
        elif v == '-':
            lst.append(x - y)
print(*lst)

Submission status: Accepted

Solution code:
char = list(map(str, input().split()))
stack = []
for s in char:
    if s not in {'+', '-', '*'}:
        stack.append(int(s))
    else:
        if s == '+':
            ans = stack.pop() + stack.pop()
            stack.append(ans)
        if s == '*':
            ans = stack.pop() * stack.pop()
            stack.append(ans)
        if s == '-':
            ans = -stack.pop() + stack.pop()
            stack.append(ans)
print(stack[0])

Submission status: Accepted

Solution code:
formula = input().split(" ")
n = len(formula)

stack = []

for i in range(n):
    if formula[i] == '+':
        operand1 = stack.pop()
        operand2 = stack.pop()
        stack.append(operand2 + operand1)
    elif formula[i] == '-':
        operand1 = stack.pop()
        operand2 = stack.pop()
        stack.append(operand2 - operand1)
    elif formula[i] == '*':
        operand1 = stack.pop()
        operand2 = stack.pop()
        stack.append(operand2 * operand1)
    else:
        stack.append(int(formula[i]))

print(stack.pop())

Submission status: Accepted

Solution code:
SS = input().split()


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

print(stack.pop())

Submission status: Accepted

Solution code:
s = list(input().split())
stack = []
for i in s:
    if i == '+' or i == '-' or i == '*':
        stack.insert(0, str(eval(stack.pop(1)+i+stack.pop(0))))
    else:
        stack.insert(0, i)
print(stack.pop())

Submission status: Accepted

Solution code:
ina = input().split(" ")
stack = []
for i in ina:
    if i.isdecimal():
        stack.append(int(i))
    else:
        if i == "+":
            stack.append(int(stack.pop() + stack.pop()))
        elif i == "*":
            stack.append(int(stack.pop() * stack.pop()))
        elif i == "-":
            a = int(stack.pop())
            b = int(stack.pop())
            stack.append(b-a)

print(str(stack.pop()))

Submission status: Accepted

Solution code:
S = input().split()
numbers =[]

for i in S:
    if i in ['+','-','*']:
        b = int(numbers.pop())
        a = int(numbers.pop())

        if i == '+':
            numbers.append(a+b)
        elif i == '-':
            numbers.append(a-b)
        else:
            numbers.append(a*b)
    else:
        numbers.append(i)
print(numbers[0])

Submission status: Accepted

Solution code:
a=input().split()
stack=[]
for i in a:
    if i not in "+-*":
        stack.append(i)
    else:
        x=eval(str(stack[-2])+i+str(stack[-1]))
        stack[-2:]=[x]
print(stack[0])

Submission status: Accepted

Solution code:
def func(s):
    try:
        return(int(s))
    except ValueError:
        return False

expression = input().split()
stack = []
for i in range(len(expression)):
    s = func(expression[i])
    if s:
        stack.append(expression[i])
    else:
        op1 = stack.pop()
        op2 = stack.pop()
        result = eval(op2+expression[i]+op1)
        stack.append(str(result))
print(stack[0])

Submission status: Accepted

Solution code:
l = input().split()
s = []
for v in l:
    if v in ["+", "-", "*"]:
        b = s.pop(-1)
        a = s.pop(-1)
        t = eval(a+v+b)
        s.append(str(t))
    else:
        s.append(v)

print(s.pop(0))

Submission status: Accepted

Solution code:
s = []

for i in input().split():
    if i == '+':
        a = s.pop()
        b = s.pop()
        s.append(a+b)
    elif i == '-':
        b = s.pop()
        a = 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.pop())

Submission status: Accepted

Solution code:
#stack
stuck = []
for val in input().split():
    if val in "+-*":
        stuck += [str(eval(stuck.pop(-2) + val + stuck.pop()))]
    else:
        stuck.append(val)
print(*stuck)

Submission status: Accepted

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