#include<iostream> #include<cstring> #include<cstdio> using namespace std; int main(){ char a[100],b[100],f[2],tmp[100]; int m,sum; sum = 0; while(true){ scanf("%s",tmp); if(!strcmp(tmp,"#")){ break; } else if(!strcmp(tmp,"0")){ printf("%d\n",sum); sum = 0; continue; } strcpy(a,tmp); scanf("%s%d%s",b,&m,f); if(!strcmp(f,"F")){ sum += m*2; } else if(!strcmp(f,"B")){ sum += m+(m+1)/2; } else if(!strcmp(f,"Y")){ if(m<=500){ sum += 500; } else{ sum += m; } } } return 0; }