#include <stdio.h>#include <string.h>#include <stack>#include <ctype.h>char s[1005];std:: stack <int> dsta;std:: stack <char> osta;int main(){ int n; scanf("%d",&n); s[0]='('; while(n--) { scanf("%s",s+1); int len=strlen(s); s[len]=')'; for(int i=0;i<len+1;i++) { if(isdigit(s[i])) { int a=0; while(isdigit(s[i])) a = a*10+(s[i++]-'0'); i--; dsta.push(a); } else if(s[i]=='S') i += 3; else if(s[i]=='(') osta.push('('); else if(s[i]=='+'||s[i]=='-') { int a,b; while(osta.top()!='('&&osta.top()!=',') { a=dsta.top();dsta.pop(); b=dsta.top();dsta.pop(); switch(osta.top()) { case '+': dsta.push(b+a);break; case '-': dsta.push(b-a);break; case '*': dsta.push(b*a);break; } osta.pop(); } osta.push(s[i]); } else if(s[i]=='*') { int a,b; switch(osta.top()) { case '*': a=dsta.top();dsta.pop(); b=dsta.top();dsta.pop(); dsta.push(b*a); osta.pop();break; default: osta.push('*');break; } } else if(s[i]==',') { int a,b; while(osta.top()!='(') { a=dsta.top();dsta.pop(); b=dsta.top();dsta.pop(); switch(osta.top()) { case '*': dsta.push(b*a); break; case '+': dsta.push(b+a); break; case '-': dsta.push(b-a); break; } osta.pop(); } osta.push(','); } else if(s[i]==')') { int a,b,aa=0,bb=0; while(osta.top()!='(') { a=dsta.top();dsta.pop(); b=dsta.top();dsta.pop(); switch(osta.top()) { case '+': dsta.push(b+a);break; case '-': dsta.push(b-a);break; case '*': dsta.push(b*a);break; case ',': while(a>0) { aa += a; a/=10; } while(b>0) { bb += b; b/=10; } aa=aa>bb?aa:bb; dsta.push(aa); break; } osta.pop(); } osta.pop(); } } printf("%d\n",dsta.top()); dsta.pop(); } return 0;}