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: Runtime Error

Solution code:
import sys

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

Submission status: Runtime Error

Solution code:
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 li[0] in OPECODE:
            STACK.append(calc(right=STACK.pop(), left=STACK.pop(), ope=li[0]))

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

Submission status: Runtime Error

Solution code:
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(c)
print(*s)

Submission status: Runtime Error

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

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

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

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

    def peek(self):
        return self.items[len(self.items)-1]

    def size(self):
        return len(self.items)

s=Stack()
x = []
while next(x,None):
    x = input().split( )
    for index in range(len(x)):
        
        if x[index]=='+':
            second = int(s.pop())
            first = int(s.pop())
            sum = first + second
            s.push(sum)
            

        elif x[index]=='-':
            second = int(s.pop())
            first = int(s.pop())
            sum = first - second
            s.push(sum)
            

        elif x[index]=='*':
            second = int(s.pop())
            first = int(s.pop())
            sum = first * second
            s.push(sum)
            

        elif x[index]=='/':
            second = int(s.pop())
            first = int(s.pop())
            sum = first / second
            s.push(sum)
            

        else:
            s.push(x[index])
        
    print(s.peek())

Submission status: Runtime Error

Solution code:
import re

def revPolish(f):
    f = re.sub(r'(\-?\d+\.?\d*?)\s(\-?\d+\.?\d*?)\s([\+\-\*/])',
        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(revPlish(input()))

Submission status: Runtime Error

Solution code:
import re

def revPolish(f):
    f = re.sub(r'(\-?\d+\.?\d*?)\s(\-?\d+\.?\d*?)\s([\+\-\*/])',
        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(revPlish(input()))

Submission status: Runtime Error

Solution code:
import re

def revPolish(f):
    f = re.sub(r'(\-?\d+\.?\d*?)\s(\-?\d+\.?\d*?)\s([\+\-\*/])',
        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()))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input().split()
stk = []
for i in s:
	if i >= '0' and i <= '9':
		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())

Submission status: Runtime Error

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


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

print(S[0])

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <stack>
#include <string>
#include <sstream>

inline int Seisu(std::string s) {
    int v;
    std::istringstream sin(s);
    sin >> v;
    return v;
}
 
int main () {
  std::string s;
  std::stack<int> st;
  while (std::cin >> s) {
        if (s[0]>='0' and s[0]<='9') {
            st.push(Seisu(s));
        }
        else {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            switch(s[0]) {
            case '+':
                st.push(a + b);
                break;
            case '-':
                st.push(b - a);
                break;
            case '*':
                st.push(a * b);
                break;
            }
        }
    }
  std::cout<<st.top()<<'\n';
    return 0;
}

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <cstdlib>
using namespace std;
 
static string tasu = "+";
static string hiku = "-";
static string kakeru = "*";
 
int top = 0;
int S[200];
 
void push(int x) {
    S[++top] = x;
}
 
int usiro() {
    return S[top--];
}
 
int main () {
    string s;
    while (cin >> s) {
        if (s == tasu) {
            int a = usiro();
            int b = usiro();
            push(a + b);
        } else if (s == hiku) {
            int a = usiro();
            int b = usiro();
            push(b - a);
        } else if (s == kakeru) {
            int a = usiro();
            int b = usiro();
            push(a * b);
        } else {
            push(atoi(s.c_str()));
        }
    }
    cout << usiro() << endl;
 
    return 0;

Submission status: Runtime Error

Solution code:
#16D8101023J 久保田凌弥 kubotarouxxx python3


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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
list=[]
for i in input.split():
    if i=='+':
        list[len(list)-1]=list[len(list)-1]+list[len(list)]
        list.pop()
    elif i=='-':
        list[len(list)-1]=[len(list)-1]-list[len(list)]
        list.pop()
    elif i=='*':
        list[len(list)-1]=[len(list)-1]*list[len(list)]
        list.pop()
    else:
        list.append()
print(list[0])

Submission status: Runtime Error

Solution code:
l=[]
c=0
s=input().split()
for i in s:
	if i=="+":
		l[c-2]=l[c-2]+l[c-1]
		c=c-1
	elif i=="-":
		l[c-2]=l[c-2]-l[c-1]
		c=c-1
	elif i=="*":
		l[c-2]=l[c-2]*l[c-1]
		c=c-1
	else:
		l[c]=int(i)
		c=c+1
printl[0]

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<stack>

int main() {
    stack<int> S;
    for (string s; cin >> s&&s != "$";) {
        int a, b;
        switch (s[0]) {
        case '+':
            b = S.top(); S.pop();
            a = S.top(); S.pop();
            S.push(a + b);
            break;
        case '-':
            b = S.top(); S.pop();
            a = S.top(); S.pop();
            S.push(a - b);
            break;
        case '*':
            b = S.top(); S.pop();
            a = S.top(); S.pop();
            S.push(a * b);
            break;
        default:
            S.push(atoi(s.c_str()));
            break;
        }
    }
 
    cout << S.top() << endl;
 
    return 0;
}

Submission status: Runtime Error

Solution code:
lis = list(map(int,input().split()))
st = []
for i in lis:
  if i == "+":
    x = st.pop()
    y = st.pop()
    st.append(x+y)
  elif i == "-":
    x = st.pop()
    y = st.pop()
    st.append(y-x)
  elif i == "*":
    x = st.pop()
    y = st.pop()
    st.append(x*y)
  else:
    st.append(i)
print(st[0])

Submission status: Runtime Error

Solution code:
import numpy as np
A=input().split()

stack=[]
for i in range(len(A)):
    n=len(stack)
    if A[i]=='*':
        y=stack.pop(n-1)
        x=stack.pop(n-2)
        stack.append(int(x*y))
    elif A[i]=='/':
        y=stack.pop(n-1)
        x=stack.pop(n-2)
        stack.append(int(x/y))
    elif A[i]=='+':
        y=stack.pop(n-1)
        x=stack.pop(n-2)
        stack.append(int(x+y))
    elif A[i]=='-':
        y=stack.pop(n-1)
        x=stack.pop(n-2)
        stack.append(int(x-y))
    else:
        stack.append(int(A[i]))
print(stack[0])

Submission status: Runtime Error

Solution code:
def RPN(a,b,c,stk):
    if len(stk) == 0:
        stk.append(cul(int(a),int(b),c))
    else:
        if a.isdigit():
            if b.isdigit():
                stk.append(cul(int(a),int(b),c))
            else:
                stk = [stk[0],(cul(int(stk[1]),int(a),b))]
        else:
            stk = [(cul(int(stk[0]),int(stk[1]),a))]
    return stk
    

def cul(a,b,operand):
    if operand == "+":
        return a+b
    elif operand == "-":
        return a-b
    elif operand == "*":
        return a*b
    elif operand == "/":
        return a*1.0/b

i = 0
stk = []
li = list(input().split(' '))
while i < len(li)-3:
    temp = len(stk)
    stk = RPN(li[i],li[i+1],li[i+2],stk)
    if len(stk) == temp + 1:
        i = i + 3
    else:
        i = i + 2
if len(stk) == 2:
    stk[0] = cul(stk[0],stk[1],li[len(li)-1])
if len(li) == 3:
    print(cul(int(li[0]),int(li[1]),li[2]))
else:
    print(int(stk[0]))

Submission status: Runtime Error

Solution code:
def plus(number_list):
    return sum([int(num) for num in number_list])


def minus(number_list):
    numbers = [int(num) for num in number_list]
    
    return numbers[0] - sum(numbers[1:])


def multiply(number_list):
    
    numbers = [int(num) for num in number_list]
    
    def recrusive(repeat_num, list_):
    
        if repeat_num == 0:
            return list_[0]
        else:
            return recrusive(repeat_num -1,list_)*list_[repeat_num]
    
    return [recrusive(i,number_list) for i in range(len(number_list))][-1]


def divide(number_list):
    
    numbers = [int(num) for num in number_list]
    
    def recrusive(repeat_num, list_):
    
        if repeat_num == 0:
            return list_[0]
        else:
            return recrusive(repeat_num -1,list_)/list_[repeat_num]
    
    return [recrusive(i,number_list) for i in range(len(number_list))][-1]



store_result = []
store_num = []
result = 0

for  i,c in enumerate(input_list.split()):
    
    
    if i < len(input_list.split())-1:
        print('result',result)
        print('store_num',store_num)
        print('store_result',store_result)
        
        if c == '+' :
            result = plus(store_num)
            store_num = []
            store_result.append(result)
        elif c== "-":
            result = minus(store_num)
            store_num = []
            store_result.append(result)
        elif c =='*':
            result = multiply(store_num)
            store_num = []
            store_result.append(result)     
        elif c == '/':
            result = divide(store_num)
            store_num = []
            store_result.append(result)
        else:
            store_num.append(int(c))
    
    
    else:
        if c == '+' :
            result = plus(store_result)
        elif c== "-":
            result = minus(store_result)
        elif c =='*':
            result = multiply(store_result)
        elif c == '/':
            result = divide(store_result)
        
print(result)

Submission status: Runtime Error

Solution code:
def plus(number_list):
    return sum([int(num) for num in number_list])


def minus(number_list):
    numbers = [int(num) for num in number_list]
    
    return numbers[0] - sum(numbers[1:])


def multiply(number_list):
    
    numbers = [int(num) for num in number_list]
    
    def recrusive(repeat_num, list_):
    
        if repeat_num == 0:
            return list_[0]
        else:
            return recrusive(repeat_num -1,list_)*list_[repeat_num]
    
    return [recrusive(i,number_list) for i in range(len(number_list))][-1]


def divide(number_list):
    
    numbers = [int(num) for num in number_list]
    
    def recrusive(repeat_num, list_):
    
        if repeat_num == 0:
            return list_[0]
        else:
            return recrusive(repeat_num -1,list_)/list_[repeat_num]
    
    return [recrusive(i,number_list) for i in range(len(number_list))][-1]



store_result = []
store_num = []

result = 0

for  i,c in enumerate(input_list.split()):
    
    
    
    if i < len(input_list.split())-1:
        print('result',result)
        print('store_num',store_num)
        print('store_result',store_result)
        
        if c == '+' :
            result = plus(store_num)
            store_num = []
            store_result.append(result)
        elif c== "-":
            result = minus(store_num)
            store_num = []
            store_result.append(result)
        elif c =='*':
            result = multiply(store_num)
            store_num = []
            store_result.append(result)     
        elif c == '/':
            result = divide(store_num)
            store_num = []
            store_result.append(result)
        else:
            store_num.append(int(c))
    
    
    
    else:
        if c == '+' :
            result = plus(store_result)
        elif c== "-":
            result = minus(store_result)
        elif c =='*':
            result = multiply(store_result)
        elif c == '/':
            result = divide(store_result)
        
print(result)

Submission status: Runtime Error

Solution code:
def plus(number_list):
    return sum([int(num) for num in number_list])


def minus(number_list):
    numbers = [int(num) for num in number_list]
    
    return numbers[0] - sum(numbers[1:])


def multiply(number_list):
    
    numbers = [int(num) for num in number_list]
    
    def recrusive(repeat_num, list_):
    
        if repeat_num == 0:
            return list_[0]
        else:
            return recrusive(repeat_num -1,list_)*list_[repeat_num]
    
    return [recrusive(i,number_list) for i in range(len(number_list))][-1]


def divide(number_list):
    
    numbers = [int(num) for num in number_list]
    
    def recrusive(repeat_num, list_):
    
        if repeat_num == 0:
            return list_[0]
        else:
            return recrusive(repeat_num -1,list_)/list_[repeat_num]
    
    return [recrusive(i,number_list) for i in range(len(number_list))][-1]



store_result = []
store_num = []

result = 0

for  i,c in enumerate(input_list.split()):
    
    
    
    if i < len(input_list.split())-1:

        
        if c == '+' :
            result = plus(store_num)
            store_num = []
            store_result.append(result)
        elif c== "-":
            result = minus(store_num)
            store_num = []
            store_result.append(result)
        elif c =='*':
            result = multiply(store_num)
            store_num = []
            store_result.append(result)     
        elif c == '/':
            result = divide(store_num)
            store_num = []
            store_result.append(result)
        else:
            store_num.append(int(c))
    
    
    
    else:
        if c == '+' :
            result = plus(store_result)
        elif c== "-":
            result = minus(store_result)
        elif c =='*':
            result = multiply(store_result)
        elif c == '/':
            result = divide(store_result)
        
print(result)

Submission status: Runtime Error

Solution code:
def plus(number_list):
    return sum([int(num) for num in number_list])


def minus(number_list):
    numbers = [int(num) for num in number_list]
    return numbers[0] - sum(numbers[1:])


def multiply(number_list):
    
    numbers = [int(num) for num in number_list]
    
    def recrusive(repeat_num, list_):
    
        if repeat_num == 0:
            return list_[0]
        else:
            return recrusive(repeat_num -1,list_)*list_[repeat_num]
    
    return [recrusive(i,number_list) for i in range(len(number_list))][-1]


def divide(number_list):
    numbers = [int(num) for num in number_list]
    
    def recrusive(repeat_num, list_):
    
        if repeat_num == 0:
            return list_[0]
        else:
            return recrusive(repeat_num -1,list_)/list_[repeat_num]
    
    return [recrusive(i,number_list) for i in range(len(number_list))][-1]



store_result = []
store_num = []
result = 0

for  i,c in enumerate(input_list.split()):
    
    if i < len(input_list.split())-1:

        
        if c == '+' :
            result = plus(store_num)
            store_num = []
            store_result.append(result)
        elif c== "-":
            result = minus(store_num)
            store_num = []
            store_result.append(result)
        elif c =='*':
            result = multiply(store_num)
            store_num = []
            store_result.append(result)     
        elif c == '/':
            result = divide(store_num)
            store_num = []
            store_result.append(result)
        else:
            store_num.append(int(c))
    
    
    
    else:
        if c == '+' :
            result = plus(store_result)
        elif c== "-":
            result = minus(store_result)
        elif c =='*':
            result = multiply(store_result)
        elif c == '/':
            result = divide(store_result)
        
print(str(result))

Submission status: Runtime Error

Solution code:
stack = []
store_num = []
store_result = []

for i,c in enumerate(input_list.split()):

        
        
        def pop_and_stack(list_,num):
                     
            list_.pop()
            list_.pop()
            list_.append(num)
            
            return list_
            
    
        if c == '+' :
            a = stack[-2]
            b = stack[-1]
            num = a+b
            pop_and_stack(stack,num)

        elif c== "-":
            a = stack[-2]
            b = stack[-1]
            num = a-b
            pop_and_stack(stack,num)
        elif c =='*':
            a = stack[-2]
            b = stack[-1]
            num = a*b
            pop_and_stack(stack,num)  
        elif c == '/':
            a = stack[-2]
            b = stack[-1]
            num = a/b
            pop_and_stack(stack,num)
        else:
            stack.append(int(c))
            
print(stack[-1])

Submission status: Runtime Error

Solution code:



stack = []
store_num = []
store_result = []

for i,c in enumerate(input_list.split()):

        
        
        def pop_and_stack(list_,num):
                     
            list_.pop()
            list_.pop()
            list_.append(num)
            
            return list_
            
    
        if c == '+' :
            a = stack[-2]
            b = stack[-1]
            num = a+b
            pop_and_stack(stack,num)

        elif c== "-":
            a = stack[-2]
            b = stack[-1]
            num = a-b
            pop_and_stack(stack,num)
        elif c =='*':
            a = stack[-2]
            b = stack[-1]
            num = a*b
            pop_and_stack(stack,num)  
        elif c == '/':
            a = stack[-2]
            b = stack[-1]
            num = a/b
            pop_and_stack(stack,num)
        else:
            stack.append(int(c))
            
print(stack[-1])

Submission status: Runtime Error

Solution code:
stack = []
store_num = []
store_result = []

for i,c in enumerate(input.split()): 
        
        def pop_and_stack(list_,num):
                     
            list_.pop()
            list_.pop()
            list_.append(num)
            
            return list_
            
    
        if c == '+' :
            a = stack[-2]
            b = stack[-1]
            num = a+b
            pop_and_stack(stack,num)

        elif c== "-":
            a = stack[-2]
            b = stack[-1]
            num = a-b
            pop_and_stack(stack,num)
        elif c =='*':
            a = stack[-2]
            b = stack[-1]
            num = a*b
            pop_and_stack(stack,num)  
        elif c == '/':
            a = stack[-2]
            b = stack[-1]
            num = a/b
            pop_and_stack(stack,num)
        else:
            stack.append(int(c))
            
print(stack[-1])

Submission status: Runtime Error

Solution code:
stack = []
store_num = []
store_result = []

for i,c in enumerate(input.split()): 
        
        def pop_and_stack(list_,num):
                     
            list_.pop()
            list_.pop()
            list_.append(num)
            
            return list_
            
    
        if c == '+' :
            a = stack[-2]
            b = stack[-1]
            num = a+b
            pop_and_stack(stack,num)

        elif c== "-":
            a = stack[-2]
            b = stack[-1]
            num = a-b
            pop_and_stack(stack,num)
        elif c =='*':
            a = stack[-2]
            b = stack[-1]
            num = a*b
            pop_and_stack(stack,num)  
        elif c == '/':
            a = stack[-2]
            b = stack[-1]
            num = a/b
            pop_and_stack(stack,num)
        else:
            stack.append(int(c))
 
print(input())         
#print(stack[-1])

Submission status: Runtime Error

Solution code:
stack = []
store_num = []
store_result = []

for i,c in enumerate(input().split()): 
        
        def pop_and_stack(list_,num):
                     
            list_.pop()
            list_.pop()
            list_.append(num)
            
            return list_
            
    
        if c == '+' :
            a = stack[-2]
            b = stack[-1]
            num = a+b
            pop_and_stack(stack,num)

        elif c== "-":
            a = stack[-2]
            b = stack[-1]
            num = a-b
            pop_and_stack(stack,num)
        elif c =='*':
            a = stack[-2]
            b = stack[-1]
            num = a*b
            pop_and_stack(stack,num)  
        elif c == '/':
            a = stack[-2]
            b = stack[-1]
            num = a/b
            pop_and_stack(stack,num)
        else:
            stack.append(int(c))
 
print(input())         
#print(stack[-1])

Submission status: Runtime Error

Solution code:
class Stack:
    MAX = 100

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

    def is_full(self):
        return self.top >= self.__class__.MAX - 1

    def push(self, x):
        self.top += 1
        self.S[self.top] = x

    def pop(self):
        self.top -= 1
        return self.S[self.top + 1]


arr = [str(s) for s in input().split()]
stack = Stack()
for s in arr:
    if s in ["+", "-", "*"]:
        stack.push(
            eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
    else:
        stack.push(int(s))

print(stack.pop())

Submission status: Runtime Error

Solution code:
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

    def is_full(self):
        return self.top >= self.__class__.MAX - 1

    def push(self, x):
        self.top += 1
        self.S[self.top] = x

    def pop(self):
        self.top -= 1
        return self.S[self.top + 1]


arr = [str(s) for s in input().split()]
stack = Stack()
stack.push(eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
    if s in["+", "-", "*"] else stack.push(int(s)) for s in arr
print(stack.pop())

Submission status: Runtime Error

Solution code:
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

    def is_full(self):
        return self.top >= self.__class__.MAX - 1

    def push(self, x):
        self.top += 1
        self.S[self.top] = x

    def pop(self):
        self.top -= 1
        return self.S[self.top + 1]


stack = Stack()
[stack.push(eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
 if s in["+", "-", "*"]else stack.push(int(s)) for s in str(s) for s in input().split()]
print(stack.pop())

Submission status: Runtime Error

Solution code:
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

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

    def is_full(self):
        return self.top >= self.__class__.MAX - 1

    def push(self, x):
        self.top += 1
        self.S[self.top] = x

    def pop(self):
        self.top -= 1
        return self.S[self.top + 1]


stack = Stack()
[stack.push(eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
 if s in["+", "-", "*"]else stack.push(int(s)) for s in str(s) for s in [str(s) for s in input().split()]]
print(stack.pop())

Submission status: Runtime Error

Solution code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int top,S[100];
 
void push(int x){
  S[++top] = x;
}
 
int pop(){
  top--;
  return S[top+1];
}
 
int main(){
  int a,b;
  top = 0;
  char s[100];
 
  while( scanf("%s",s) != EOF){
    if(s[0] == '+'){
      a = pop();
      b = pop();
      push(a + b);
    }
    else if(s[0] == '-'){
      b = pop();
      a = pop();
      push(a - b);
    }
    else if(s[0] == '*'){
      a = pop();
      b = pop();
      push(a * b);
    }
    else{
      push(atoi(s));
    }
  }
 
  printf("%d\n",pop());
 
  return 0;
 
}

Submission status: Runtime Error

Solution code:
def ch(x):
    if x in ["+", "-", "*"]:
        return x
    else:
        return int(x)

def check(x):
    if (type(x[0]) is int) and (type(x[1]) is int) and (type(x[2]) is str):
        return True
    else:
        return False

def calc(x):
    if x[2] == "+":
        return x[0] + x[1]
    elif x[2] == "-":
        return x[0] - x[1]
    elif x[2] == "*":
        return x[0] * x[1]

N = list(map(ch, input().split()))

st = []
while True:
    if len(N) == 0:
        break
    elif len(st) in [0,1]:
        st.append(calc(N[:3]))
        N.pop(0); N.pop(0); N.pop(0);
    elif len(st) == 2:
        st.append(calc(st+[N[0]]))
        N.pop(0); st.pop(0); st.pop(0);
print(*st)

Submission status: Runtime Error

Solution code:
def main():
    # データ入力
    n, q = input().split()
    n = int( n )
    q = int( q )
    name = []
    time = []
    for i in range(n):
        tmp_n, tmp_t = input().split()
        name.append( tmp_n )
        time.append( int( tmp_t ) )

    # 処理
    count = 0
    while n > 0:
        if time[0] > q:
            time[0] -= q
            count += q
            time.append( time[0] )
            time.pop( 0 )
            name.append( name[0] )
            name.pop( 0 )
        else :
            count += time[0]
            print( name[0], end=" " )
            print( str( count ) )
            time.pop( 0 )
            name.pop( 0 )
            n -= 1

if __name__ == '__main__':
    main()

Submission status: WA: Presentation Error

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

stack = []

for c in A:
    if c == '+':
        rhs = stack.pop()
        lhs = stack.pop()
        stack.append(lhs + rhs)
    elif c == '-':
        rhs = stack.pop()
        lhs = stack.pop()
        stack.append(lhs - rhs)
    elif c == '*':
        rhs = stack.pop()
        lhs = stack.pop()
        stack.append(lhs * rhs)
    else:
        stack.append(int(c))


print(stack.pop(), end="")