Minlexes
Contest: Codeforces Round 675 (Div. 2)
Difficulty rating: 2700
Tags: dp, greedy, implementation, strings

Some time ago Lesha found an entertaining string $$$s$$$ consisting of lowercase English letters. Lesha immediately developed an unique algorithm for this string and shared it with you. The algorithm is as follows.

Lesha chooses an arbitrary (possibly zero) number of pairs on positions $$$(i, i + 1)$$$ in such a way that the following conditions are satisfied:

- for each pair $$$(i, i + 1)$$$ the inequality $$$0 \le i < |s| - 1$$$ holds;
- for each pair $$$(i, i + 1)$$$ the equality $$$s_i = s_{i + 1}$$$ holds;
- there is no index that is contained in more than one pair.

Lesha is interested in the lexicographically smallest strings he can obtain by applying the algorithm to the suffixes of the given string.

Input format:
The only line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$) — the initial string consisting of lowercase English letters only.

Output format:
In $$$|s|$$$ lines print the lengths of the answers and the answers themselves, starting with the answer for the longest suffix. The output can be large, so, when some answer is longer than $$$10$$$ characters, instead print the first $$$5$$$ characters, then "...", then the last $$$2$$$ characters of the answer.

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Note:
Consider the first example.

- The longest suffix is the whole string "abcdd". Choosing one pair $$$(4, 5)$$$, Lesha obtains "abc".
- The next longest suffix is "bcdd". Choosing one pair $$$(3, 4)$$$, we obtain "bc".
- The next longest suffix is "cdd". Choosing one pair $$$(2, 3)$$$, we obtain "c".
- The next longest suffix is "dd". Choosing one pair $$$(1, 2)$$$, we obtain "" (an empty string).
- The last suffix is the string "d". No pair can be chosen, so the answer is "d".

In the second example, for the longest suffix "abbcdddeaaffdfouurtytwoo" choose three pairs $$$(11, 12)$$$, $$$(16, 17)$$$, $$$(23, 24)$$$ and we obtain "abbcdddeaadfortytw"

Example input:
abcdd

Example output:
3 abc
2 bc
1 c
0 
1 d

Example input:
abbcdddeaaffdfouurtytwoo

Example output:
18 abbcd...tw
17 bbcdd...tw
16 bcddd...tw
15 cddde...tw
14 dddea...tw
13 ddeaa...tw
12 deaad...tw
11 eaadf...tw
10 aadfortytw
9 adfortytw
8 dfortytw
9 fdfortytw
8 dfortytw
7 fortytw
6 ortytw
5 rtytw
6 urtytw
5 rtytw
4 tytw
3 ytw
2 tw
1 w
0 
1 o

Editorial:
Let's find the answer $$$ans_i$$$ for all suffixes, starting with the smallest in length. $$$ ans_n $$$ is equal to an empty string. Then if $$$ s_i = s_{i + 1} $$$ ($$$ 0 \le i + 1 < n $$$), then $$$ ans_i = min (s_i + ans_{i + 1}, ans_{i + 2}) $$$, and otherwise $$$ ans_i = s_i + ans_{i + 1} $$$. To quickly find minimum of two strings, they can be stored as "binary lifts"  – $$$ next_ {i, j} $$$ will be equal to the position in the string $$$s$$$, on which the $$$2 ^ j$$$ character $$$ ans_i $$$ will be located, and $$$ hash_{i, j} $$$  – hash from the prefix $$$ ans_i $$$ of length $$$ 2 ^ j $$$. Values for $$$ (i, j) $$$ can be obtained from $$$ (i, j-1) $$$ and $$$ (i + 2 ^ {j-1}, j-1) $$$. To restore the answer, $$$ next_ {i, j} $$$ will be enough for us, and for simplicity we can additionally store the length of each answer.