eolymp
bolt
Try our new interface for solving problems
Problems

Folding

Folding

Bill is trying to compactly represent sequences of capital alphabetic characters from '\textbf{A}' to '\textbf{Z}' by folding repeating subsequences inside them. For example, one way to represent a sequence \textbf{AAAAAAAAAABABABCCD is} \textbf{10(A)2(BA)B2(C)D}. He formally defines folded sequences of characters along with the unfolding transformation for them in the following way: \begin{itemize} \item A sequence that contains a single character from '\textbf{A}' to '\textbf{Z}' is considered to be a folded sequence. Unfolding of this sequence produces the same sequence of a single character itself. \item If \textbf{S} and \textbf{Q} are folded sequences, then \textbf{SQ} is also a folded sequence. If \textbf{S} unfolds to \textbf{S'} and \textbf{Q} unfolds to \textbf{Q'}, then \textbf{SQ} unfolds to \textbf{S'Q'}. \item If \textbf{S} is a folded sequence, then \textbf{X(S)} is also a folded sequence, where \textbf{X} is a decimal representation of an integer number greater than \textbf{1}. If \textbf{S} unfolds to \textbf{S'}, then \textbf{X(S)} unfolds to \textbf{S'} repeated \textbf{X} times. \end{itemize} According to this definition it is easy to unfold any given folded sequence. However, Bill is much more interested in the reverse transformation. He wants to fold the given sequence in such a way that the resulting folded sequence contains the least possible number of characters. \InputFile The input contains a single line of characters from '\textbf{A}' to '\textbf{Z}' with at least 1 and at most \textbf{100} characters. \OutputFile Write a single line that contains the shortest possible folded sequence that unfolds to the sequence that is given in the input. If there are many such sequences then write any one of them.
Time limit 1 second
Memory limit 64 MiB
Input example #1
AAAAAAAAAABABABCCD
Output example #1
9(A)3(AB)CCD
Author Roman Elizarov
Source 2002-2003 ACM Northeastern European Regional Programming Contest