#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define OPERAND_MIN (1)
#define OPERAND_MAX (1000000)
#define OPERANDS_CNT_MIN (2)
#define OPERANDS_CNT_MAX (100)
#define OPERATOR_CNT_MIN (1) 
#define OPERATOR_CNT_MAX (99)
#define VALUE_IN_STACK_MIN (-1000000000)
#define VALUE_IN_STACK_MAX (1000000000)
#define STACK_SIZE (OPERATOR_CNT_MAX + OPERANDS_CNT_MAX)
#define IN_STR_MAX (8) /* OPERAND_MAX + \n */ 
#define SUCCESS    (0)
#define FAILURE    (-1)
#define AOJ_TRUE   (1)
#define AOJ_FALSE  (0)

typedef struct stack_info
{
    int arr[STACK_SIZE];
    int top;
}STACK;

STACK g_stack;

int schedule(STACK *p_st);
void init(STACK *p_st);
int is_empty(STACK *p_st);
int is_full(STACK *p_st);
int push(STACK *p_st, int key);
int pop(STACK *p_st, int *key);
int binary_operation(char ope, int x, int y);
int get_str(char *p_str, int min, int max);
int judge_constraint(int test_num, int min, int max);


int main(void)
{
    int ret;
    
    schedule(&g_stack);
    
    if(g_stack.top != 1)
    {
        return FAILURE;
    }
    
    
    pop(&g_stack, &ret);
    printf("%d\n", ret);
        
    return SUCCESS;
}


int schedule(STACK *p_st)
{
    char str[IN_STR_MAX];
    int x;
    int y;
    
    while(get_str(str, 1, IN_STR_MAX) != FAILURE)
    {
        if((str[0] == '+') || (str[0] == '-') || (str[0] == '*'))
        {
            if(pop(p_st, &x) == FAILURE)
            {
                return FAILURE;
            }
            if(pop(p_st, &y) == FAILURE)
            {
                return FAILURE;
            }
            if(push(p_st, binary_operation(str[0], y, x)) == FAILURE)
            {
                return FAILURE;
            }
        }
        else if(str[0] >= '0' && str[0] <= '9')
        {
            if(push(p_st, atoi(&str[0])) == FAILURE)
            {
                return FAILURE;
            }
        }
        else
        {
            return FAILURE;
        }
    }    
    
    return SUCCESS;
}

void init(STACK *p_st)
{
    p_st->top = 0;
    
    return;
}

int is_empty(STACK *p_st)
{
    if(p_st->top == 0)
    {
        return AOJ_TRUE;
    }
    
    return AOJ_FALSE;
}


int is_full(STACK *p_st)
{
    if(p_st->top >= STACK_SIZE - 1)
    {
        return AOJ_TRUE;
    }
    
    return AOJ_FALSE;
}


int push(STACK *p_st, int key)
{
    if(is_full(p_st))
    {
        return FAILURE;
    }
    
    p_st->top++;
    p_st->arr[p_st->top] = key;
    
    return SUCCESS;
}
int pop(STACK *p_st, int *key)
{
    if(is_empty(p_st))
    {
        return FAILURE;
    }
    
    *key = p_st->arr[p_st->top];
    p_st->top--;
    
    return SUCCESS;
}

int binary_operation(char ope, int x, int y)
{
    switch(ope)
    {
    case '+':
        return x + y;
    case '-':
        return x - y;
    case '*':
        return x * y;
    }
    
    return 0;
}

int get_str(char *p_str, int min, int max)
{
    int cnt = 0;
    int ch;
    
    while((ch = getchar()) != -1)
    {
       
        if(ch == ' ' || ch == '\n')
        {
            p_str[cnt] = '\0';
            return ch;
        }
        
        p_str[cnt] = ch;
        cnt++;
        
        if(judge_constraint(cnt, min, max) == FAILURE)
        {
            return FAILURE;
        }
    }
    
    return FAILURE;
}
int judge_constraint(int test_num, int min, int max)
{
    if((test_num < min) || (test_num > max))
    {
        return FAILURE;
    }
    
    return SUCCESS;
}

Measured memory_bytes: 1860