#include<iostream>
using namespace std;
char f[100],t[100],zifu[5];
int main()
{
float num,sum;
do{
cin>>f;
if(f[0]=='#')
break;
cin>>t;
sum=0;
while(1)
{
cin>>num>>zifu;
switch(zifu[0])
{
case 'F':
sum+=num*2;
break;
case 'B':
sum+=num*1.5;
break;
default:
if(num>500)
sum+=num;
else
sum+=500;
break;
}
cin>>f;
if(f[0]!='0')
cin>>t;
else
break;
}
cout<<sum<<endl;
}while(1);
return 0;
}