/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <cstdint>
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>

enum class DataType : int32_t { kValue = 0, kPlus, kMinus, kMultiply, kEOF };

struct LoadedData {
  DataType data_type{DataType::kValue};
  int32_t value{0};
};

DataType JudgeDataType(const std::string &str);

LoadedData LoadOne(std::istream &input_stream);

constexpr int32_t kMaxArraySize = 100;

class Stack {
 public:
  Stack() noexcept;
  ~Stack() noexcept;
  void Main(std::istream &input_stream) noexcept;
  void LoadAndCompute(std::istream &input_stream);
  void Push(const int32_t x);
  int32_t Pop();
  bool IsEmpty() const noexcept;
  bool IsFull() const noexcept;

 private:
  void PopAndPrint() noexcept;

 private:
  Stack(const Stack &obj) noexcept = delete;
  Stack &operator=(const Stack &obj) noexcept = delete;
  Stack(Stack &&obj) = delete;
  Stack &operator=(Stack &&obj) = delete;

 private:
  int32_t top_position_;
  int32_t values_[kMaxArraySize];
};

DataType JudgeDataType(const std::string &str) {
  DataType data_type;
  if (std::all_of(str.cbegin(), str.cend(), isdigit)) {
    data_type = DataType::kValue;
  } else if (str == "+") {
    data_type = DataType::kPlus;
  } else if (str == "-") {
    data_type = DataType::kMinus;
  } else if (str == "*") {
    data_type = DataType::kMultiply;
  } else {
    std::cout << "ERROR: JudgeDataType(): Invalid input data. " << str << std::endl;
    throw 1;
  }
  return data_type;
}

LoadedData LoadOne(std::istream &input_stream) {
  LoadedData data;
  try {
    std::string loaded_str;
    input_stream >> loaded_str;
    if (input_stream.eof()) {
      data.data_type = DataType::kEOF;
      data.value = 0;
    } else {
      data.data_type = JudgeDataType(loaded_str);
      if (data.data_type == DataType::kValue) {
        data.value = stoi(loaded_str);
      } else {
        data.value = 0;
      }
    }
  } catch (...) {
    throw;
  }
  return data;
}

Stack::Stack() noexcept : top_position_(0), values_{0} {}

Stack::~Stack() noexcept {}

void Stack::Main(std::istream &input_stream) noexcept {
  try {
    LoadAndCompute(input_stream);
    PopAndPrint();
  } catch (...) {
    std::cout << "ERROR: Main()" << std::endl;
  }
}

void Stack::LoadAndCompute(std::istream &input_stream) {
  constexpr int32_t kMaxNumberOfInputs = 200;
  try {
    for (int32_t i = 0; i < kMaxNumberOfInputs; ++i) {
      const LoadedData data = LoadOne(input_stream);
      if (data.data_type == DataType::kEOF) {
        break;
      } else {
        switch (data.data_type) {
          int32_t x;
          int32_t y;
          case DataType::kValue:
            Push(data.value);
            break;
          case DataType::kPlus:
            y = Pop();
            x = Pop();
            Push(x + y);
            break;
          case DataType::kMinus:
            y = Pop();
            x = Pop();
            Push(x - y);
            break;
          case DataType::kMultiply:
            y = Pop();
            x = Pop();
            Push(x * y);
            break;
          default:
            throw 1;
        }
      }
    }
  } catch (...) {
    std::cout << "ERROR: Load()" << std::endl;
    throw;
  }
}

void Stack::PopAndPrint() noexcept {
  std::cout << Pop() << std::endl;
}

bool Stack::IsEmpty() const noexcept {
  return (top_position_ <= 0);
}

bool Stack::IsFull() const noexcept {
  return (top_position_ >= kMaxArraySize);
}

void Stack::Push(const int32_t x) {
  if (IsFull()) {
    std::cout << "ERROR: Push(): stack is full." << std::endl;
    throw 1;
  }
  values_[top_position_] = x;
  ++top_position_;
}

int32_t Stack::Pop() {
  if (IsEmpty()) {
    std::cout << "ERROR: Pop(): stack is empty." << std::endl;
    throw 1;
  }
  --top_position_;
  return values_[top_position_];
}

int main(int argc, char *argv[]) {
  Stack *stack = new Stack();
  stack->Main(std::cin);
  delete stack;
  return 0;
}



Measured memory_bytes: 3160