eolymp
bolt
Try our new interface for solving problems
Problems

Analyzing Bit (Yet Special) Strings

Analyzing Bit (Yet Special) Strings

Do you think that analyzing bit strings is easy? This is not the case when you are in a dream. So you are in a dream. Unexpectedly, right? But... I am afraid it's not the dream you always wanted to be in. You have a string of bits in your dream, a long string of bits you are to deal with. And you clearly understand what you should do to leave this horrible dream right now: find the best \textit{special }string. Luckily, you know that you read a book about the theory of special strings yesterday. You only managed to remember the strangest definition of special strings, though, which sounded as follows. Suppose you have a string of bits \textbf{T} of length \textbf{n}. Bits of \textbf{T} are referred to as \textbf{T_1}, \textbf{T_2}, ..., \textbf{T_n}. Let's denote \textbf{A}(\textbf{i}, \textbf{j}) and \textbf{B}(\textbf{i}, \textbf{j}) as the number of \textbf{0}-bits and \textbf{1}-bits among \textbf{T_i}, \textbf{T_\{i+1\}}, ..., \textbf{T_j}, correspondingly. String \textbf{T} is called special if for every \textbf{i }between \textbf{1} and \textbf{n}, inclusive, both of the following conditions hold: \textbf{A}(\textbf{1}, \textbf{i}) ≥ \textbf{B}(\textbf{1}, \textbf{i}) and \textbf{A}(\textbf{i}, \textbf{n}) ≤ \textbf{B}(\textbf{i}, \textbf{n}). But you can't be satisfied with just any special string. You need the best special string. The dream was very strange and thus the rules to determine which of two strings was better were strange as well. Let \textbf{L_1} and \textbf{L_2} be the lengths of two strings, and \textbf{P_1} and \textbf{P_2} be their numbers of occurrences in the given string \textbf{S} as a substring, respectively. Then you know that first string is better than the second one if \textbf{L_1} ∙ \textbf{P_1} > \textbf{L_2} ∙ \textbf{P_2}. So your task is simple... or not? Find the best special string - a special string such that no other special string is better. \InputFile Only one line that contains the string \textbf{S} (\textbf{2} ≤ |\textbf{S}| ≤ \textbf{2*10^5}) consisting of zeroes and ones. \OutputFile The first line should contain the value of \textbf{L} ∙ \textbf{P}, where \textbf{L} is the length of the best special string and \textbf{P} is the number of its occurrences in \textbf{S} as a substring. The second line should contain the best special string itself. If there are several best special strings, you can choose any of them. It is guaranteed that at least one special string is a substring of \textbf{S}.
Time limit 3 seconds
Memory limit 256 MiB
Input example #1
00111001110101
Output example #1
8
0011
Author Gennady Korotkevich
Source Gennady Korotkevich Contest 1, Petrozavodsk Training Camp, Day 1, Friday, August 23, 2013