#include <stack>
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <map>
#include <functional>

using namespace std;
using stack_op = void(*)(stack<int>&);
//using op = function<void(stack<int>&)>;
#define STACK_OP(name, op) void o_##name(stack<int>& s) { if (s.size() < 2) { \
        cerr << "Chyba vstupu operatoru" #op << endl; }\
    else { int x, y; \
    	x = s.top(); s.pop(); y = s.top(); s.pop(); \
	s.push(x op y); } }

STACK_OP(plus, +)
STACK_OP(minus, -)
STACK_OP(mult, *)

void print(stack<int>& s) {

    if (s.size()) {
        cout << s.top() << endl;
    }
}
#undef STACK_OP
void quit(stack<int>&) {

    exit(0);
}
int main()
{
    stack<int> s;
    map<string, stack_op> ops;
    ops["+"] = o_plus;
    ops["-"] = o_minus;
    ops["*"] = o_mult;
    ops["q"] = quit;
    ops["p"] = print;
    for_each(istream_iterator<string>(cin), istream_iterator<string>(),
        [&s, &ops](const string& token) {
        if (ops.count(token)) ops[token](s);
        else s.push([&token]()->int {
		int i; istringstream(token) >> i; return i;
	}());

    });

    return 0;
}
