logo AlgoBeat OnlineJudge
登录 注册

#214918. [ICPC 2023 Yokohama R] Nested Repetition Compression

内存限制:2048 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

You have a number of strings of lowercase letters to be sent in e-mails, but some of them are so long that typing as they are would be tiresome. As you found repeated parts in them, you have decided to try out a simple compression method in which repeated sequences are enclosed in parentheses, prefixed with digits meaning the numbers of repetitions. For example, the string “abababaaaaa” can be represented as “3(ab)5(a)” or “a3(ba)4(a)”. The syntax of compressed representations is given below in Backus-Naur form with the start symbol .

Note that numbers of repetitions are specified by a single digit, and thus at most nine, but more repetitions can be specified by nesting them. A string of thirty a’s can be represented as “6(5(a))” or “3(5(2(a)))”, for example.

Find the shortest possible representation of the given string in this compression scheme.

输入格式

The input is a line containing a string of lowercase letters. The number of letters in the string is at least one and at most 200.

输出格式

Output a single line containing the shortest possible representation of the input string. If there exist two or more shortest representations, any of them is acceptable.

样例

样例输入 1

abababaaaaa

样例输出 1

3(ab)5(a)

样例输入 2

abababcaaaaaabababcaaaaa

样例输出 2

2(3(ab)c5(a))

样例输入 3

abcdefg 

样例输出 3

abcdefg