This page is still under construction.

Parts of this page are still being built. What you see may change.

String Folding

Interview

Time limit2sMemory limit128 MB

Summary
Find the length of the shortest folded sequence, using repeat counts like 3(AB), that unfolds to the given uppercase string.
Level

Medium6 of 10

Topics
Dynamic programming, String
Solved
No attempts yet

Problem

Bill wants to compactly represent strings of uppercase letters 'A' to 'Z' by folding their repeating parts. For example, the string AAAAAAAAAABABABCCD can be written as 10(A)2(BA)B2(C)D.

A folded sequence and its unfolding are defined as follows.

  • A string consisting of a single character from 'A' to 'Z' is a folded sequence. Unfolding it yields that same single character.
  • If SS and QQ are folded sequences, then SQSQ is also a folded sequence. If SS unfolds to S′S' and QQ unfolds to Q′Q', then SQSQ unfolds to S′Q′S'Q'.
  • If SS is a folded sequence, then X(S)X(S) is also a folded sequence, where XX is the decimal representation of an integer greater than 1. If SS unfolds to S′S', then X(S)X(S) unfolds to S′S' repeated XX times.

Among all folded sequences that unfold to the given string, find the number of characters in the shortest one.

Input

A single line containing a string of uppercase letters from 'A' to 'Z'. Its length is between 1 and 100, inclusive.

Output

Print a single integer: the number of characters in the shortest folded sequence that unfolds to the input string.

Examples2

  1. Example 1

    Input
    AAAAAAAAAABABABCCD
    
    Expected output
    12
    
  2. Example 2

    Input
    NEERCYESYESYESNEERCYESYESYES
    
    Expected output
    14