#include <algorithm>
#include <cctype>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>

// 编译：g++ -std=c++17 -O2 -Wall -Wextra infix_evaluator.cpp -o infix_evaluator
// 每行输入一个表达式；每行输出一个整数结果，或以“错误：”开头的提示。

namespace {

using Wide = __int128_t;
constexpr Wide kMax = (Wide{1} << 63) - 1;
constexpr Wide kMin = -(Wide{1} << 63);
constexpr Wide kMaxMagnitude = Wide{1} << 63;

enum class Kind { Number, Operator, LeftParen, RightParen };

struct Token {
    Kind kind;
    Wide number = 0;
    char op = '\0'; // P/N 分别表示一元正号/负号
};

bool is_digit(char ch) { return ch >= '0' && ch <= '9'; }
bool in_range(Wide value) { return value >= kMin && value <= kMax; }
bool is_unary(char op) { return op == 'P' || op == 'N'; }

int priority(char op) {
    if (is_unary(op)) return 3;
    if (op == '*' || op == '/') return 2;
    return 1;
}

std::vector<Token> tokenize(const std::string& text) {
    std::vector<Token> tokens;
    bool expect_operand = true;

    for (std::size_t i = 0; i < text.size();) {
        const unsigned char ch = static_cast<unsigned char>(text[i]);
        if (std::isspace(ch)) {
            ++i;
            continue;
        }

        if (is_digit(text[i])) {
            if (!expect_operand) throw std::runtime_error("数字前缺少运算符");
            Wide value = 0;
            do {
                value = value * 10 + (text[i] - '0');
                if (value > kMaxMagnitude) throw std::runtime_error("64 位整数溢出");
                ++i;
            } while (i < text.size() && is_digit(text[i]));
            tokens.push_back({Kind::Number, value, '\0'});
            expect_operand = false;
            continue;
        }

        if (text[i] == '(') {
            if (!expect_operand) throw std::runtime_error("左括号前缺少运算符");
            tokens.push_back({Kind::LeftParen, 0, '('});
            ++i;
            continue;
        }

        if (text[i] == ')') {
            if (expect_operand) throw std::runtime_error("右括号前缺少数字或表达式");
            tokens.push_back({Kind::RightParen, 0, ')'});
            expect_operand = false;
            ++i;
            continue;
        }

        const char op = text[i];
        if (op == '+' || op == '-' || op == '*' || op == '/') {
            if (expect_operand && op != '+' && op != '-') {
                throw std::runtime_error("这里需要数字或左括号");
            }
            const char actual = expect_operand ? (op == '+' ? 'P' : 'N') : op;
            tokens.push_back({Kind::Operator, 0, actual});
            expect_operand = true;
            ++i;
            continue;
        }

        throw std::runtime_error("表达式含不支持的字符");
    }

    if (tokens.empty()) throw std::runtime_error("请输入表达式");
    if (expect_operand) throw std::runtime_error("表达式不能以运算符或左括号结尾");
    return tokens;
}

std::vector<Token> to_postfix(const std::vector<Token>& tokens) {
    std::vector<Token> output;
    std::vector<Token> operators;

    for (const Token& token : tokens) {
        if (token.kind == Kind::Number) {
            output.push_back(token);
        } else if (token.kind == Kind::LeftParen) {
            operators.push_back(token);
        } else if (token.kind == Kind::RightParen) {
            const bool has_left = std::any_of(operators.begin(), operators.end(),
                                              [](const Token& item) { return item.kind == Kind::LeftParen; });
            if (!has_left) throw std::runtime_error("括号不匹配：多了右括号");
            while (operators.back().kind != Kind::LeftParen) {
                output.push_back(operators.back());
                operators.pop_back();
            }
            operators.pop_back();
        } else {
            while (!operators.empty() && operators.back().kind == Kind::Operator) {
                const int top = priority(operators.back().op);
                const int current = priority(token.op);
                if (top < current || (is_unary(token.op) && top == current)) break;
                output.push_back(operators.back());
                operators.pop_back();
            }
            operators.push_back(token);
        }
    }

    while (!operators.empty()) {
        if (operators.back().kind == Kind::LeftParen) {
            throw std::runtime_error("括号不匹配：缺少右括号");
        }
        output.push_back(operators.back());
        operators.pop_back();
    }
    return output;
}

long long evaluate(const std::vector<Token>& postfix) {
    std::vector<Wide> values;
    for (const Token& token : postfix) {
        if (token.kind == Kind::Number) {
            values.push_back(token.number);
            continue;
        }

        if (is_unary(token.op)) {
            if (values.empty()) throw std::runtime_error("输入格式错误：一元运算缺少数字");
            const Wide operand = values.back();
            values.pop_back();
            const Wide result = token.op == 'N' ? -operand : operand;
            if (!in_range(result)) throw std::runtime_error("64 位整数溢出");
            values.push_back(result);
            continue;
        }

        if (values.size() < 2) throw std::runtime_error("输入格式错误：二元运算缺少数字");
        const Wide right = values.back();
        values.pop_back();
        const Wide left = values.back();
        values.pop_back();
        if (!in_range(left) || !in_range(right)) throw std::runtime_error("64 位整数溢出");

        Wide result = 0;
        switch (token.op) {
            case '+': result = left + right; break;
            case '-': result = left - right; break;
            case '*': result = left * right; break;
            case '/':
                if (right == 0) throw std::runtime_error("除数不能为 0");
                result = left / right; // C++17 的整数除法向零截断
                break;
            default: throw std::runtime_error("输入格式错误：未知运算符");
        }
        if (!in_range(result)) throw std::runtime_error("64 位整数溢出");
        values.push_back(result);
    }

    if (values.size() != 1) throw std::runtime_error("输入格式错误：表达式无法求值");
    if (!in_range(values.back())) throw std::runtime_error("64 位整数溢出");
    return static_cast<long long>(values.back());
}

} // namespace

int main() {
    std::string expression;
    while (std::getline(std::cin, expression)) {
        try {
            std::cout << evaluate(to_postfix(tokenize(expression))) << '\n';
        } catch (const std::exception& error) {
            std::cout << "错误：" << error.what() << '\n';
        }
    }
    return 0;
}
