#include <bits/stdc++.h> using namespace std; // 定義三個函數的計算 long long int f(int x) { return 2*x-3; } long long int g(int x, int y) { return 2*x+y-7; } long long int h(int x, int y, int z) { return 3*x-2*y+z; } int main(){ string s; vector<string> a; while (cin>>s){ a.push_back(s); } reverse(a.begin(),a.end()); stack<long long int> st; for (int i=0;i<a.size();i++){ if (a[i]=="f"){ long long int arg=st.top(); st.pop(); st.push(f(arg)); } else if (a[i]=="g"){ long long int arg1=st.top(); st.pop(); long long int arg2=st.top(); st.pop(); st.push(g(arg1, arg2)); } else if (a[i]=="h"){ long long int arg1=st.top(); st.pop(); long long int arg2=st.top(); st.pop(); long long int arg3=st.top(); st.pop(); st.push(h(arg1,arg2,arg3)); } else{ // 數字 st.push(stoll(a[i])); } } cout<<st.top()<<endl; return 0; }