#include <bits/stdc++.h>
using namespace std;
map<string,double> ch;
string s;
double cnt(int st)
{
double ans=0,p=0;
int i=st;
while(s[i]!=')'&&i<s.size())
{
if(s[i]>='A'&&s[i]<='Z')
{
ans+=p;
p=ch[s.substr(i,1+(s[i+1]>='a'&&s[i+1]<='z'))];
i+=1+(s[i+1]>='a'&&s[i+1]<='z');
continue;
}
if(s[i]=='(')
{
ans+=p;
int j=i+1;
while(s[j]!=')')
j++;
p=cnt(i+1);
i=j+1;
continue;
}
if(s[i]>='0'&&s[i]<='9')
{
double mul=0;
while(s[i]>='0'&&s[i]<='9')
{
mul=mul*10+s[i]-'0';
i++;
}
p*=mul;
}
if(s[i]=='~')
{
if(s[i+1]=='H')
ans+=18;
else
ans+=(s[i+1]-'0')*18;
break;
}
i++;
}
return ans+p;
}
int main()
{
ch["H"]=1;
ch["C"]=12;
ch["N"]=14;
ch["O"]=16;
ch["F"]=19;
ch["Na"]=23;
ch["Mg"]=24;
ch["Al"]=27;
ch["Si"]=28;
ch["P"]=31;
ch["S"]=32;
ch["Cl"]=35.5;
ch["K"]=39;
ch["Ca"]=40;
ch["Mn"]=55;
ch["Fe"]=56;
ch["Cu"]=64;
ch["Zn"]=65;
ch["Ag"]=108;
ch["I"]=127;
ch["Ba"]=137;
ch["Hf"]=178.5;
ch["Pt"]=195;
ch["Au"]=197;
ch["Hg"]=201;
cin>>s;
cout<<cnt(0)<<endl;
return 0;
}