#include #define rep(i, start, end) for (long long i = start; i < end; ++i) #define repreverse(i, start, end) for (long long i = start; i >= end; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define len(x) ((long long)(x).size()) #define lcm(a, b) ((a) / __gcd((a), (b)) * (b)) using namespace std; using ll = long long; using ld = long double; using vll = vector; using vllvll = vector; using vc = vector; using pll = pair; templatevoid print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);} templatebool haskey(T mp, U key) { return mp.find(key) != mp.end(); } templatebool isin(T el, U container) { return find(all(container), el) != container.end(); } templatebool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } templatebool even(T n) { return ! (n & 1); } templatebool odd(T n) { return n & 1; } templateld deg2rad(T deg) { return M_PI * deg / 180.0; } templateld rad2deg(T rad) { return 180.0 * rad / M_PI; } ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} const long double pi = M_PI; const long long big = 1LL << 50; const long long inf = 1LL << 60; const long long mod = 1e9 + 7; std::vector split(std::string s, string sep) { std::regex regex_sep = regex(sep); std::sregex_token_iterator first(s.begin(), s.end(), regex_sep, -1); std::sregex_token_iterator last; return std::vector(first, last); } int main() { ll N; string tmp; getline(cin, tmp); N = stoll(tmp); getline(cin, tmp); auto A = split(tmp, " "); stack s; rep(i, 0, N) { if (isdigit(A[i][0])) { s.push(A[i]); } else if (A[i] == "+") { ll rhs = stoll(s.top()); s.pop(); ll lhs = stoll(s.top()); s.pop(); ll res = lhs + rhs; s.push(to_string(res)); } else if (A[i] == "-") { ll rhs = stoll(s.top()); s.pop(); ll lhs = stoll(s.top()); s.pop(); ll res = lhs - rhs; s.push(to_string(res)); } } cout << s.top() << endl; }