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.  After that Lesha removes all characters on indexes contained in these pairs and the algorithm is over. 

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


-----Input-----

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


-----Output-----

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.


-----Examples-----
Input
abcdd

Output
3 abc
2 bc
1 c
0 
1 d

Input
abbcdddeaaffdfouurtytwoo

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



-----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"

Difficulty: VERY_HARD
Tags: String algorithms

Dynamic programming

Implementation

Greedy algorithms
Skill types: Dynamic programming

Greedy algorithms

Starter code:

Solutions:
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
s = input()
cs = ['']
ans = []
last = ['']
poped = False
for c in s[::-1]:
	if not poped and c == cs[-1] and (c > last[-2]):
		cs.pop()
		if not cs or c != cs[-1]:
			last.pop()
		poped = True
	else:
		poped = False
		if c != cs[-1]:
			last.append(c)
		cs.append(c)
	if len(cs) <= 11:
		ans.append((len(cs) - 1, ''.join(cs[::-1])))
	else:
		ans.append((len(cs) - 1, (''.join(cs[:3]) + '...' + ''.join(cs[-5:]))[::-1]))
for (a, b) in ans[::-1]:
	print(a, b)


import sys
s = input().strip()
N = len(s)
if len(s) == 1:
	print(1, s[0])
	return
X = [s[-1], s[-2] + s[-1] if s[-2] != s[-1] else '']
Y = [1, 2 if s[-2] != s[-1] else 0]
for i in range(N - 3, -1, -1):
	c = s[i]
	k1 = c + X[-1]
	ng = Y[-1] + 1
	if ng > 10:
		k1 = k1[:5] + '...' + k1[-2:]
	if c == s[i + 1] and k1 > X[-2]:
		k1 = X[-2]
		ng = Y[-2]
	X.append(k1)
	Y.append(ng)
for i in range(N - 1, -1, -1):
	print(Y[i], X[i])


s = input()
cs = ['']
ans = []
last = ['']
poped = False
for c in s[::-1]:
	if not poped and c == cs[-1] and (c > last[-2]):
		cs.pop()
		if not cs or c != cs[-1]:
			last.pop()
		poped = True
	else:
		poped = False
		if c != cs[-1]:
			last.append(c)
		cs.append(c)
	if len(cs) <= 11:
		ans.append((len(cs) - 1, ''.join(cs[::-1])))
	else:
		ans.append((len(cs) - 1, (''.join(cs[:3]) + '...' + ''.join(cs[-5:]))[::-1]))
for (a, b) in ans[::-1]:
	print(a, b)


import sys
z = sys.stdin.readline
s = z().strip()
l = len(s)
b = [' ']
o = []
m = [' ']
for i in range(l):
	c = s[-1 - i]
	if c == b[-1]:
		if c > m[-1].lower() or (c == m[-1].lower() and c > m[-2].lower()):
			b.pop()
			if b[-1].lower() != m[-1].lower():
				m.pop()
			b[-1] = b[-1].upper()
			m[-1] = m[-1].upper()
		else:
			b += [c]
	else:
		b += [c]
		if b[-1] != m[-1].lower():
			m += [b[-1]]
	if len(b) > 11:
		o += [(str(len(b) - 1) + ' ' + ''.join(b[:-6:-1]) + '...' + b[2] + b[1]).lower()]
	elif len(b) > 1:
		o += [(str(len(b) - 1) + ' ' + ''.join(b[-1::-1])).lower()]
	else:
		o.append('0')
print('\n'.join(o[::-1]))


s = input()
n = len(s)
res = ['', s[-1]]
l = [1]
flag = True
last = ['']
for i in range(n - 2, -1, -1):
	tmp = res[-1]
	if flag and s[i] == tmp[0] and (s[i] > last[-1]):
		res.append(res[-2])
		l.append(l[-1] - 1)
		flag = False
		if l[-1] > 0 and res[-1][0] != s[i]:
			last.pop()
	else:
		l.append(l[-1] + 1)
		tmp = s[i] + tmp
		flag = True
		if len(tmp) > 10:
			res.append(tmp[:5] + '...' + tmp[-2:])
		else:
			res.append(tmp)
		if len(res[-1]) > 1 and res[-1][0] != res[-1][1]:
			last.append(res[-1][1])
res.pop(0)
for i in range(n - 1, -1, -1):
	print(l[i], res[i])


import io
import os
from collections import deque

def solve(S):
	N = len(S)
	ans = []
	suff = deque()
	suffUnique = deque()
	count = 0
	for i in reversed(range(N)):
		x = S[i]
		if i == N - 1 or S[i] != S[i + 1]:
			count = 1
		else:
			count += 1
		if suffUnique and x < suffUnique[0] or (len(suffUnique) >= 2 and x == suffUnique[0] and (x < suffUnique[1])):
			suff.appendleft(x)
			if not suffUnique or x != suffUnique[0]:
				suffUnique.appendleft(x)
		elif count % 2 == 1:
			suff.appendleft(x)
			if not suffUnique or x != suffUnique[0]:
				suffUnique.appendleft(x)
		else:
			suff.popleft()
			if suffUnique and (not suff or suffUnique[0] != suff[0]):
				suffUnique.popleft()
		if len(suff) <= 10:
			ans.append(str(len(suff)) + ' ' + ''.join(suff))
		else:
			line = [str(len(suff)), ' ']
			for i in range(5):
				line.append(suff[i])
			line.append('...')
			line.append(suff[-2])
			line.append(suff[-1])
			ans.append(''.join(line))
	return '\n'.join(ans[::-1])
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
S = input().decode().rstrip()
ans = solve(S)
print(ans)


def main(s):
	if len(s) == 0:
		return []
	if len(s) == 1:
		return [[s], [1]]
	s = s[::-1]
	sres = [s[0]]
	nres = [1]
	if s[0] == s[1]:
		sres.append('')
		nres.append(0)
	else:
		sres.append(s[1] + s[0])
		nres.append(2)
	for i in range(2, len(s)):
		st = s[i] + sres[-1]
		nt = nres[-1] + 1
		if nt > 10:
			st = st[:5] + '...' + st[-2:]
		if s[i] == s[i - 1] and st > sres[-1]:
			st = sres[-2]
			nt = nres[-2]
		sres.append(st)
		nres.append(nt)
	return [sres, nres]
s = input()
(sres, nres) = main(s)
for i in range(len(s) - 1, -1, -1):
	print(nres[i], sres[i])


import os
import sys
from io import BytesIO, IOBase

def main():
	s = input()
	curs = []
	n = len(s)
	ans = []
	ansNum = []
	blocked = False
	hint = 'A'
	for i in range(n - 1, -1, -1):
		elem = s[i]
		if not curs:
			curs.append(elem)
			blocked = False
		elif elem == curs[-1] and (len(curs) <= 1 or ord(curs[-2]) < ord(elem)) and (not blocked):
			curs.pop()
			blocked = True
		elif elem == curs[-1] and (len(curs) <= 1 or ord(curs[-2]) == ord(elem)) and (not blocked):
			if ord(hint) < ord(elem):
				curs.pop()
				blocked = True
			else:
				curs.append(elem)
				blocked = False
		else:
			if ord(curs[-1]) == ord(elem):
				if len(curs) >= 2 and curs[-2] != elem:
					hint = curs[-2]
				elif len(curs) >= 2:
					pass
				else:
					hint = 'A'
			curs.append(elem)
			blocked = False
		ansNum.append(len(curs))
		if ansNum[-1] > 10:
			ans.append(curs[-1] + curs[-2] + curs[-3] + curs[-4] + curs[-5] + '...' + curs[1] + curs[0])
		else:
			ans.append(''.join(reversed(curs)))
	for i in range(n - 1, -1, -1):
		print(str(ansNum[i]) + ' ' + ans[i])
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
s = input()
n = len(s)
res = ['', s[-1]]
l = [1]
flag = True
last = ['']
for i in range(n - 2, -1, -1):
	tmp = res[-1]
	if flag and s[i] == tmp[0] and (s[i] > last[-1]):
		res.append(res[-2])
		l.append(l[-1] - 1)
		flag = False
		if l[-1] > 0 and res[-1][0] != s[i]:
			last.pop()
	else:
		l.append(l[-1] + 1)
		tmp = s[i] + tmp
		flag = True
		if len(tmp) > 10:
			res.append(tmp[:5] + '...' + tmp[-2:])
		else:
			res.append(tmp)
		if len(res[-1]) > 1 and res[-1][0] != res[-1][1]:
			last.append(res[-1][1])
res.pop(0)
for i in range(n - 1, -1, -1):
	print(l[i], res[i])


import os
import sys
import io
import functools
import copy
import math
GANS = []

def cmp(x, y):
	if x[1] == y[1]:
		return -(y[0] - x[0])
	return -(x[1] - y[1])
s = input()
ans = []
cur = []
ctr = []
pos = []
pv = [chr(0)]
pvc = chr(1)
for (p, i) in enumerate(s[::-1]):
	if cur and cur[-1] == i:
		f = True
		if len(cur) >= 2:
			if cur[-2] > i:
				f = False
			elif cur[-2] == i:
				if pos[-2] == p - 2:
					f = False
				if pv[-1] >= i:
					f = False
		if f and p == pos[-1] + 1:
			cur.pop()
			pos.pop()
			pv.pop()
			pvc = pv[-1]
		else:
			cur.append(i)
			pos.append(p)
			pv.append(pvc)
	else:
		if cur:
			pvc = cur[-1]
		cur.append(i)
		pos.append(p)
		pv.append(pvc)
	ctr.append(len(cur))
	if ctr[-1] > 10:
		ans.append(''.join(cur[-5:][::-1]) + '...' + ''.join(cur[:2][::-1]))
	else:
		ans.append(''.join(cur[::-1]))
for i in range(len(ans)):
	print(ctr[-i - 1], ans[-i - 1])