After failing to qualify for the National Olympiad in Informatics because of his childish mistake, Xorin decided to build a tool that will ensure he never gets a Memory Limit Exceeded feedback ever again.

When Xorin writes a new source file, he wants to be able to type into the tool a code sequence corresponding to his declaration of variables. The tool should then interpret the sequence and output the total memory allocated for said variables.

A C variable declaration looks like TYPE VAR1,VAR2,..,VARn, where

  • TYPE is the type of the variable: char (1 byte), short (2 bytes), int (4 bytes), each of them optionally preceded by unsigned
  • VARk looks like NAME (a scalar) or NAME[DIM1][DIM2]..[DIMn] (a N-dimensional vector). A vector needs as much memory as DIM1 * DIM2 * ... * DIMn scalars of the same type.
Example variable declarations: int n,m, unsigned short vec[5][100],othervec[105],randomvar.


A list of C variable declarations in the format above, separated by newlines. The input ends with a newline character.


A list of integers separated by newlines. The ith integer is the amount of memory needed to store the variabled declared on the ith line of the input


  • Each input line is at most 100 characters long
  • Variable names cannot be empty and may only contain lowercase letters
  • On each line, there are no spaces after the first letter of the first variable name
  • All numbers in the output are smaller than 109


char marint,a[20]
int b[2],c[1],d,e
unsigned int d
short a,b,c,d[2][2][2],munsigned

Sponsors Gold