#include <iostream>
#include <cstring>
using namespace std;
int sum,mat,i,a,poz,val;
char sir[105];
char aux[105];
int main()
{
    while(cin.getline(sir,105))
    {
        char *p=sir;
        p=strtok(sir," ");
        strcpy(aux,p);
        if(!strcmp(aux,"unsigned")) {p=strtok(NULL," ");
        strcpy(aux,p);}
        if(!strcmp(aux,"int")) val=4;
            else if(!strcmp(aux,"short")) val=2;
                else if(!strcmp(aux,"char")) val=1;
        p=strtok(NULL,",;");
        sum=0;
        strcpy(aux,p);
        while(aux[0]!=NULL)
        {
            char *unde;
            strcpy(aux,p);
            unde=strchr(aux,'[');
            if(unde!=NULL)
            {
                poz=unde-aux;
                int mat=1;
                while(aux[poz]=='[')
                {
                    a=0;
                    ++poz;
                    while(aux[poz]!=']') a=a*10+aux[poz]-'0',++poz;
                    mat*=a;
                    ++poz;
                }
                sum+=mat*val;
            }
            else sum+=val;
            p=strtok(NULL,",;");
            if(p==NULL) break;
            strcpy(aux,p);
        }
        cout<<sum<<'\n';
    }
    return 0;
}