#include <iostream>
#include <string>
#include <sstream>
#include <stack>

struct Token {
  bool number;
  int value;
  char op;
  Token(){}
  Token(int value) { 
    number = true;
    this->value = value; 
  }
  Token(char c) { 
    number = false;
    this->op = c; 
  }
  

};

//istream& getline(istream&a, std::string&out);

bool isSingleTokenChar(char c ) {
  switch(c) {
    case '+':
    case '-':
    case '*':
    case '/':
    case '%':
    case 'd':
    case 'p':
    case 'x':
    case 'c':
    case 'q':
      return true;
    default:
      return false;
  }
}

std::istream& readToken(std::istream&a, Token&out){
  std::string s;
  if(a >> s){
    if (s.length()>0 && isSingleTokenChar(s[0])) {
      out = Token(s[0]);
    }
    std::istringstream ss(s);
    int i;
    if (ss >> i){
      out = Token(i);
    }
  }
  return a;
}

#if 0
#define SIZE 5
#define OP +
#define M(a,b,c) (a c b)
M(5,2,+)     -->     5 + 2
#endif
 

int main() {
  std::stack<int> s;
  Token t;
  while (readToken(std::cin, t)){
    if (t.number) {
      s.push(t.value);
      continue;
    }
    
#define OP(ch, o) \
    if(t.op==ch){ \
      if(s.size()<2){ \
        std::cerr << "There is less than 2 elements" << std::endl; \
        continue;\
      }\
      int a = s.top();\
      s.pop();\
      int b = s.top();\
      s.pop();\
      s.push(b o a);\
      continue;\
    }

    OP('+', +)
    OP('-', -)
    OP('*', *)
    OP('/', /)
    OP('%', %)
#undef OP

#define CHECKSTACK(SIZE) \
  if(s.size() < SIZE){ \
        std::cerr << "Wrong use of the stack!" << std::endl; \
        continue; \
      }

    if(t.op == 'p'){
      CHECKSTACK(1)
      std::cout << s.top() << std::endl;
      continue;
    }

    if(t.op == 'q'){
      break;
    }

    if (t.op == 'c') {
      CHECKSTACK(1)
      s.push(s.top());
      continue;
    }

    if (t.op == 'x') {
      CHECKSTACK(2)
      int a = s.top();
      s.pop();
      int b = s.top();
      s.pop();
      s.push(a);
      s.push(b);
      continue;
    } 

    if (t.op == 'd') {
      CHECKSTACK(1)
      s.pop();
      continue;
    }
  }

  
#if 0
  while (!s.empty())
    std::cout << s.top() << std::endl,
    s.pop();

  std::ostringstream b;
  b << "hello";
  b << 123;
  std::cout << b.str() << std::endl;
#endif
  return 0;
}
