ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests

Ural SU contest. Petrozavodsk training camp. Summer 2010

About     Problems     Submit solution     Judge status     Standings
Contest is over

B. Local Roots

Time limit: 0.5 second
Memory limit: 64 MB
Consider a word w consisting of n symbols. We can decompose it at point i (1 ≤ in − 1) into a prefix p of length i and a suffix s of length ni. Local root of a word w at point i is a non-empty word r such that:
  • p is a suffix of r, or r is a suffix of p, or r is equal to p;
  • s is a prefix of r, or r is a prefix of s, or r is equal to s;
  • r has minimal possible length.
Your goal is to find such a point that the length of local root at this point is maximal possible.


The only line contains a word w consisting of lowercase English letters. Its length is at least two and at most 300 000 symbols.


Output the required point of decomposition and the length of local root at this point. If there are several possible answers, output any of them.


5 6


Local roots of a word “aababaaa” at different points:
Point 1 2 3 4 5 6 7
Local root a babaa ab ba aaabab a a
Problem Author: Ivan Burmistrov
Problem Source: Ural SU Contest. Petrozavodsk Summer Session, August 2010
To submit the solution for this problem go to the Problem set: 1842. Local Roots