#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

char type[20], restul[200];
int ad;

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif // ONLINE_JUDGE

    while(cin >> type) {
        if(strcmp(type, "unsigned") == 0) {
            cin >> type;
        }

        cin >> restul;

        if(strcmp(type, "char") == 0) ad = 1;
        if(strcmp(type, "int") == 0) ad = 4;
        if(strcmp(type, "short") == 0) ad = 2;

        int lg = strlen(restul);

        int rez = 0;
        int dim = 1;
        int p, k;

        for(int i = 0; i < lg; ++i) {
            if(restul[i] == ',') {
                rez += ad * dim;
                dim = 1;
            }
            else {
                if(restul[i] == '[') {
                    p = 0;
                    k = 1;
                }
                if(restul[i] == ']') {
                    dim *= p;
                    k = 0;
                }

                if(restul[i] <= '9' && '0' <= restul[i]) {
                    if(k == 1) {
                        p = p * 10 + restul[i] - '0';
                    }
                }
            }
        }

        rez += dim * ad;

        cout << rez << '\n';
    }

    return 0;
}