STL 栈
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
stack<long long> st;
char op;
long long x,ans=0;
int main(){
cin>>x;
st.push(x);
while(cin>>op>>x){
if(op=='+'){
st.push(x);
}else{
x=(st.top()*x)%10000;
st.pop();
st.push(x);
}
}
while(st.size()){
ans=(ans+st.top())%10000;
st.pop();
}
cout<<ans;
return 0;
}