#include <testlib.h>

const int maxn = 100;

long long s[maxn];

int main()
{
  registerValidation();
  int n = 0, sn = 0;
  while (!inf.eof())
  {
    std::string token = inf.readToken();
    if (++n > maxn)
      quitf(_fail, "Too many tokens!");
    if (pattern("-?[0-9]{1,10}").matches(token))
    {
      long long value = atoi(token.c_str());
      if (std::abs(value) > 0x7fffffff)
        quitf(_fail, "Bad value: %lld", value);
      s[sn++] = value;
    }
    else if (token == "+")
    {
      if (sn < 2)
        quitf(_fail, "[#%d]: stack is empty", n);
      s[sn - 2] += s[sn - 1], sn--;
      if (std::abs(s[sn - 1]) > 0x7fffffff)
        quitf(_fail, "[#%d]: owerflow");
    }
    else if (token == "-")
    {
      if (sn < 2)
        quitf(_fail, "[#%d]: stack is empty", n);
      s[sn - 2] -= s[sn - 1], sn--;
      if (std::abs(s[sn - 1]) > 0x7fffffff)
        quitf(_fail, "[#%d]: owerflow");
    }
    else if (token == "*")
    {
      if (sn < 2)
        quitf(_fail, "[#%d]: stack is empty", n);
      s[sn - 2] *= s[sn - 1], sn--;
      if (std::abs(s[sn - 1]) > 0x7fffffff)
        quitf(_fail, "[#%d]: owerflow");
    }
    else
      quitf(_fail, "bad token: %s", token.c_str());
    inf.skipBlanks();
  }
  if (sn != 1)
    quitf(_fail, "bad expression: %d numbers in stack", sn);
  inf.readEof();
  return 0;
}

