#include <iostream>
using namespace std;
int main()
{
char c;
int n,num,sum=0;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>c;
if(c=='r')
{
cin>>num;
sum+=num;
}
if(c=='y') sum+=2;
if(c=='g') sum+=3;
if(c=='c') sum+=4;
if(c=='b') sum+=5;
if(c=='p') sum+=6;
if(c=='B') sum+=7;
}
cout<<sum;
}