#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; int N; string A[1010]; int a1, a2, ans; stack st; int main() { cin >> N; for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) { if (A[i] == "+" || A[i] == "-") { a2 = st.top(); st.pop(); a1 = st.top(); st.pop(); if (A[i] == "+") ans = a1 + a2; if (A[i] == "-") ans = a1 - a2; st.push(ans); } else { ans = stoi(A[i]); st.push(ans); } } cout << st.top() << endl; }