#include<bits/stdc++.h>
using namespace std;
string s;
long long does(string x)
{
long long ans=0;
int id=0;
while(id<x.size())
{
if(x[id]=='F')
{
id+=3;
long long ls=0;
while(isdigit(x[id]))
ls=ls*10+x[id]-'0',++id;
ans+=ls;
}
if(x[id]=='B')
{
id+=3;
long long ls=0;
while(isdigit(x[id]))
ls=ls*10+x[id]-'0',++id;
ans-=ls;
}
++id;
}
return ans;
}
long long get(string x)
{
if(x[0]=='[')
x.erase(0,1);
long long xb=x.find('[');
if(xb==string::npos)
{
return does(x);
}
long long ans=0;
if(x[0]!='R')
{
ans+=does(x.substr(0,x.find('R')));
}
if(x[x.size()-1]!=']')
ans+=get(x.substr(x.find_last_of(']')+1));
long long c=xb-1;
string ls;
while(isdigit(x[c]))
ls=x[c]+ls,--c;
stringstream ss;
ss<<ls;
ss>>c;
long long y=0;
while(x[xb+y]!=']')
++y;
return ans+c*get(x.substr(xb,y+1));
}
int main()
{
getline(cin,s);
cout<<abs(get(s));
}
90分求助,WA#2,求hack