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 × 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

Solution in JAVA (judge verdict: Accepted)

import java.util.*;
public class Main{
    public static void main (String args[]){

        //初期処理
        Scanner sc=new Scanner(System.in);
        // int n=Integer.parseInt(sc.nextLine());
        // String[] sArray = sc.nextLine().split(" ");
        // int[] array=Arrays.stream(sArray).mapToInt(Integer::parseInt).toArray();

        String[] strArray = sc.nextLine().split(" ");
        Stack stack= new Stack(300);
        int answer=0;
        int a,b;

        for (String s:strArray){
            switch (s) {
                case "+":
                    a=Integer.parseInt(stack.pop());
                    b=Integer.parseInt(stack.pop());
                    answer=b+a;
                    stack.push(Integer.toString(answer));
                    break;
                
                case "-":
                    a=Integer.parseInt(stack.pop());
                    b=Integer.parseInt(stack.pop());
                    answer=b-a;
                    stack.push(Integer.toString(answer));
                    break;
                
                case "*":
                    a=Integer.parseInt(stack.pop());
                    b=Integer.parseInt(stack.pop());
                    answer=b*a;
                    stack.push(Integer.toString(answer));
                    break;
                case "/":
                    a=Integer.parseInt(stack.pop());
                    b=Integer.parseInt(stack.pop());
                    answer=b/a;
                    stack.push(Integer.toString(answer));
                    break;
                default:
                    stack.push(s);
                    break;
            }
        }
            System.out.println(answer);
        // String[] sArray2 = Arrays.stream(array).mapToObj(Integer::toString).toArray(s->new String[s]);
        // System.out.println(String.join(" ", sArray2));
        // System.out.println(count);
    }
}


class Stack {
    //メンバ変数
    private int top=0;
    private int n;          //配列サイズ
    private String[] stackArray;


    //コンストラクタ    
    public Stack(int n){
        this.n=n;
        stackArray=new String[n];
    }
    //ゲッターセッター
    public int getTop(){
        return top;
    }
    public int getN(){
        return n;
    }
    public String[] getstackArray(){
        return stackArray;
    }
    public void setTop(int top){
        this.top=top;
    }
    public void setN(int n){
        this.n=n;
    }
    public void setstackArray(String[] stackArray){
        this.stackArray=stackArray;
    }

    //メソッド
    public void push(String data){
        if (this.isFull()==false){
            stackArray[top+1]=data;
            top++;
        } else{;}
    }

    public String pop(){
        if (this.isEmpty()==false){
            String popedData=stackArray[top];
            stackArray[top]=null;
            top--;
            return popedData;
        } else{
            throw new NullPointerException();
        }
    }

    public boolean isFull(){
        if (top==n-1){
            return true;
        } else if (top<n-1){
            return false;
        }else{
            throw new NullPointerException();
        }
    }

    public boolean isEmpty(){
        if (top==0){
            return true;
        } else if (top>0){
            return false;
        }else{
            throw new NullPointerException();
        }
    }
}