#P8791. Memory Calculation

    ID: 21955 Type: Default 1000ms 256MiB

Memory Calculation

Memory Calculation

Little Blue loves to calculate how much memory is occupied by the variables defined in his code. There are only three types of variables:

  • \( int \): occupies \( 4 \) Byte per variable.
  • \( long \): occupies \( 8 \) Byte per variable.
  • \( String \): occupies \( L \) Byte if the string length is \( L \) (if \( L=0 \), then 0 Byte).

There are two forms of definition statements:

Form 1:

type var1=value1,var2=value2...;

For example:

  • int a=1,b=5,c=6; occupies \( 3 \times 4 = 12 \) Byte.
  • long a=1,b=5; occupies \( 2 \times 8 = 16 \) Byte.
  • String s1="",s2="hello",s3="world"; occupies \( 0+5+5 = 10 \) Byte.

Form 2:

type[] arr1=new type[size1],arr2=new type[size2]...;

This defines one-dimensional arrays. Note that the base type will only be int or long. For example:

  • int[] a1=new int[10]; occupies \( 10 \times 4 = 40 \) Byte.
  • long[] a1=new long[10],a2=new long[10]; occupies \( 2 \times 10 \times 8 = 160 \) Byte.

You are given \( T \) definition statements. Your task is to compute the total occupied memory and output the result in the format:

aGBbMBcKBdB

Here, \( a \), \( b \), \( c \), and \( d \) represent the counts for gigabytes, megabytes, kilobytes, and bytes respectively, after converting using the relations \( 1\,GB=1024\,MB \), \( 1\,MB=1024\,KB \), and \( 1\,KB=1024\,B \). Only output the nonzero units starting from the largest unit.

inputFormat

The first line contains an integer ( T ) denoting the number of definition statements. Each of the following ( T ) lines contains a variable definition statement in one of the two forms described above.

outputFormat

Output a single string representing the total memory usage in the format aGBbMBcKBdB. Omit any units that are 0.

sample

3
int a=1,b=5,c=6;
long a=1,b=5;
String s1="",s2="hello",s3="world";
38B