/* 
 * File:   main.c
 * Author: s1252007
 *
 * Created on June 24, 2018, 8:20 PM
 */

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

/*
 * 
 */

int isempty();

int isfull();

int pop();

void push(int data);

int MAXSIZE = 100;       
int stack[100];     
int top = -1;            

int main(int argc, char** argv) {
    int data1, data2, result;
    char save[1000];
    while(scanf("%s", save) != EOF)
    {
        if (save[0] == '+')
        {
            data1 = pop();
            data2 = pop();
            push(data1 + data2);
        }
        else if (save[0] == '-')
        {
            data2 = pop();
            data1 = pop();
            push(data1 - data2);
        }
        else if (save[0] == '*')
        {
            data1 = pop();
            data2 = pop();
            push(data1 * data2);
        }
        else
        {
            push(atoi(save));
        }
    }
    result = pop();
    printf("%d\n", result);
    return (EXIT_SUCCESS);
}

int isempty()
{
   if (top == -1)
        return 1;
   else
        return 0;
}
   
int isfull() 
{
    if (top == MAXSIZE)
        return 1;
    else
        return 0;
}

int pop()
{
   int data;
	
   if (!isempty()) {
        data = stack[top];
        top = top - 1;   
        return data;
    }    
   else 
   {
        printf("Could not retrieve data, Stack is empty.\n");
   }
}

void push(int data)
{
   if (!isfull()) 
   {
        top = top + 1;   
        stack[top] = data;
   } 
   else 
   {
        printf("Could not insert data, Stack is full.\n");
   }
}


