import math import sys import fractions sys.setrecursionlimit(2 ** 20) # DEBUG = True DEBUG = False if DEBUG: input = open('date.in', 'r') output = open('date.out', 'w') else: input = sys.stdin output = sys.stdout def solve(S): A = S.split(' ') st = 0 if A[0] == 'unsigned': st += 1 T = A[st] D = A[st + 1] tSize = 1 if T == 'short': tSize = 2 elif T == 'int': tSize = 4 V = D.split(',') total = 0 for v in V: dim = 1 pos = 0 while v.find('[', pos) != -1: nxt = v.find('[', pos) nxtClose = v.find(']', nxt + 1) num = int(v[nxt+1:nxtClose]) dim *= num pos = nxt + 1 total += dim total *= tSize return total S = input.readline().strip() while len(S) > 0: ans = solve(S) output.write('{}\n'.format(ans)) S = input.readline().strip() input.close() output.close()