RT
#include<bits/stdc++.h>
using namespace std;
long long sta[100005];
int top=0;
long long stb[100005];
int main(){
string a;
while(cin>>a){
if(a=="REPEAT"){
int b;cin>>b;
sta[++top]=b;
char t;cin>>t;
}
if(a=="FD"){
int b;cin>>b;
stb[top]+=b;
}
if(a=="BK"){
int b;cin>>b;
stb[top]-=b;
}
if(a[0]==']'){
for(int i=0;i<a.length();i++){
stb[top-1]+=stb[top]*sta[top];
top--;
}
}
}
cout<<abs(stb[0]);
return 0;
}