import java.io.*;
class Stack{
int m_sp; //stack point
int m_size; //stack size
int m_stack[]; //stack
//引数を取る。
public Stack( int sz ){
m_size = sz ;
m_stack = new int[m_size] ;
m_sp = 0;
}
public Stack(){
m_size = 100;
m_stack = new int[m_size];
m_sp = 0;
}
public void push( int value ){
if( m_sp >= m_size ){
System.out.println("stack overflow");
System.exit(1);
}
m_stack[m_sp] = value ;
m_sp = m_sp + 1 ;
}
public int pop(){
if(m_sp <= 0 ){
System.err.println("stack underflow");
System.exit(1) ;
}
m_sp = m_sp - 1;
return m_stack[m_sp];
}
public int getLength(){
return m_sp;
}
public int peek(){
if(0 >= m_sp ){
System.err.println("stack underflow");
System.exit(1) ;
}
return m_stack[m_sp] -1;
}
}
class CCD{
public static void main(String args[]){
int value, op1, op2 ;
Stack ostack = new Stack( args.length );
for( int i = 0; i < args.length ; i++){
if( args[i].equals("+") ){
op2 = ostack.pop();
op1 = ostack.pop();
ostack.push( op1 + op2 );
}
else if( args[i].equals("-")){
op2 = ostack.pop();
op1 = ostack.pop();
ostack.push( op1 - op2 );
}
else if( args[i].equals("$")){
op2 = ostack.pop();
op1 = ostack.pop();
ostack.push( op1 * op2 );
}
else if( args[i].equals("/") ){
op2 = ostack.pop();
op1 = ostack.pop();
if( op2 == 0 ){
System.err.println("0で分けられない");
System.exit(1); //終了する
}
ostack.push( op1 / op2 );
}
else{
value = (new Integer(args[i])).intValue();
ostack.push( value );
}
}
if( ostack.getLength( ) != 1 ){
System.err.println("illegal expression");
System.exit(1);
}
value = ostack.pop();
System.out.println(value);
}
}

0