#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;
char s[110];
//ifstream fin("date.in");
//ofstream fout("date.out");
int main()
{
    int tip,total,nr,i,subtotal;
    bool ok;
    while (cin.getline(s,110))
    {
        if (s[0]==0) break;
        total=0;
        i=0;
        ok=0;
        while (s[i]==' ') i++;
        strcpy(s,s+i);
        if (s[0]=='u')
        strcpy(s,s+9);
        i=0;
        while (s[i]==' ') i++;
        strcpy(s,s+i);
        if (s[0]=='c' && !ok)
        {
            tip=1;
            strcpy(s,s+5);
            ok=1;
        }
        if (s[0]=='s' && !ok)
        {
            tip=2;
            strcpy(s,s+6);
            ok=1;
        }
        if (s[0]=='i' && !ok)
        {
            tip=4;
            strcpy(s,s+4);
            ok=1;
        }
        i=0;
        while (s[i]==' ') i++;
        strcpy(s,s+i);
        //acum am declaratii de variabile
//        p=strtok(s,", ");
//        if (*(p+strlen(p)-1)!=']') total+=tip;
//        else
//        {
//            while (*p!=NULL)
//            {
//
//            }
//        }
        s[strlen(s)]=0;
        for (i=0; i<=strlen(s); i++)
        {
            subtotal=tip;
            while (s[i]=='[')
            {
                nr=0;
                //subtotal=1;
                i++;
                while (s[i]!=']')
                {
                    nr=nr*10 + s[i]-'0';
                    i++;
                }
                i++;
                subtotal*=nr;
            }
            if (s[i]==',') {total+=subtotal; subtotal=0; continue;}
            if (s[i]==0) {total+=subtotal; break;}

        }
        cout<<total<<'\n';

    }
    return 0;
}