// Rational number class template
#include <cctype>
#include <iostream>
#include <istream>
#include <ostream>
#include <stack>
#include "rational.h"

int main(int argc, char** argv)
{
  using namespace std;

  stack<rational<int> > stack;
  char c;
  while (cin >> c) {
    if (std::isdigit(c) || c == '-') {
      rational<int> x;
      cin.unget();
      cin >> x;
      stack.push(x);
      cout << x << '\n';
    } else if (c == '+') {
      rational<int> x(stack.top());
      stack.pop();
      rational<int> y(stack.top());
      stack.pop();
      rational<int> z(x + y);
      cout << z << '\n';
      stack.push(z);
    } else if (c == '*') {
      rational<int> x(stack.top());
      stack.pop();
      rational<int> y(stack.top());
      stack.pop();
      rational<int> z(x * y);
      cout << z << '\n';
      stack.push(z);
    } else if (c == '_') {
      rational<int> x(stack.top());
      stack.pop();
      rational<int> y(stack.top());
      stack.pop();
      rational<int> z(x - y);
      cout << z << '\n';
      stack.push(z);
    } else if (c == 'a') {
      rational<int> x(stack.top());
      rational<int> z(abs(x));
      cout << z << '\n';
      stack.push(z);
    } else {
      cout << "n/d, +, *, _, EOF\n";
    }
  }
}

