There are many ways to represent a string. The following syntax
(x1 , k1 )(x2 , k2 ) . . . (xl , kl )
defines the string where xi is the ith string that has to repeat ki times. We call this representation a brief string because it can represent a very long string by using only relatively small amount of space. For example, (ab, 2)(a, 4) represents ababaaaa. If you are given a brief string, certainly you can quickly recover the string that it represents.
Conversely, if you are given an ordinary string, you can find many di?erent brief strings that represent it. We are interested in finding the shortest one. We define the length of a brief string (x1 , k1 )(x2 , k2 ) . . . (xl , kl ) to be |x1 | + |x2 | + ... + |xl |. That is, we only consider the total length of strings that has to be repeated and ignore all the numbers (as well as the parentheses and commas). The shortest brief string of an ordinary string is called a basis.
For example, both (a, 1)(ba, 3)(a, 3) and (ab, 3)(a, 4) represent the same string abababaaaa.
However, only the second one is its basis whose length is 3. In this problem, you need to find the length of a basis of an ordinary string.