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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;


class Main {
	//計算用array
	static int[] array = new int[101];
	static int[] temporary = new int[102];
	//ただ読み込むのみ
	static String[] read = new String[300];
	//計算用arrayのindex
	static int count = 0;
	
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
			String string = br.readLine();
			StringTokenizer tokenizer = new StringTokenizer(string," ");
			//一度すべて読み込んでしまう
			int i = 0;
			while (tokenizer.hasMoreTokens()) {
				read[i] = tokenizer.nextToken();
				i++;
			}
			
			int j =0;
			while(read[j]!=null){
				
				String next = read[j];
				if(next.equals("+")){
					popcalc(0);
				}else if(next.equals("-")){
					popcalc(1);
				}else if (next.equals("*")) {
					popcalc(2);
				}else{
					int number = Integer.parseInt(next);
					push(number);
				}
			
				j++;
			}
			
		System.out.println(array[0]);
	}

	
	//popメソッド
	public static void popcalc(int judge) {
	//上から2個とる、1つずつずらす、計算結果をpushする。
		int answer;
		int first = array[0];
		int second = array[1];
		
		//先に計算
		if(judge == 0){
			//足し算
			//System.out.println("たしざん");
			answer=first+second;
		}else if (judge == 1) {
			//引き算
			answer=second-first;
		}else{
			answer=first*second;
		}
		//コピー
		for(int i=0;i<array.length-1;i++){
			temporary[i] = array[i];
		}
		for(int i=2;i<array.length;i++){
			array[i-1]=temporary[i];
		}
		array[0]=answer;
	}
	
	
	//pushメソッド
	public static void push(int number){
		//numberを0番目に、それぞれ一個ずつずらしていく
		
		//同じ配列を複製
		for(int i=0;i<array.length-1;i++){
			temporary[i] = array[i];
		}
		for(int i =0;i<array.length-1;i++){
			array[i+1] = temporary[i];
		}
		array[0]=number;
	}
}