#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <fstream>
#include <cctype>
#include <iomanip>
#include <cmath>
#include <cstring>

using namespace std;

int main()
{

    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    int sum = 0;
    string tip, s;
    while(cin>>tip)
    {
        sum = 0;
        if(tip == "unsigned")
            cin>>tip;
        int t;
        if(tip == "char")
            t = 1;
        else if(tip == "int")
            t = 4;
        else if(tip == "short")
            t = 2;
        cin>>s;
        for(int i = 0; i < s.size() ;i ++)
        {
            if(isalpha(s[i]))
            {

                while(isalpha(s[i]) && i < s.size())
                    i++;
                if(i  == s.size() || s[i] == ',')
                    sum++;
                else
                {
                    int temp = 1;
                    //++i;

                    while(s[i] =='[')
                    {
                        int nr = 0;
                        ++i;
                        while(s[i] >= '0' && s[i] <= '9')
                        {
                            nr = nr*10 + s[i] - '0';
                            i++;
                        }
                        temp *= nr;
                        ++i;

                    }
                    sum += temp;
                }


            }
        }
        cout<<sum*t<<'\n';

    }


    return 0;
}


//FILE!!!!!!