This page is still under construction.

Parts of this page are still being built. What you see may change.

Repeats

Time limit6sMemory limit512 MB

Summary
Given a binary string of length n, find a substring that is some seed repeated as many times as possible, and report the count, seed length, and 1-based start position.
Level

Hard8 of 10

Topics
String, String matching, Sorting, Binary search
Solved
No attempts yet

Problem

A string ss is called a (k,l)(k, l)-repeat if ss is obtained by concatenating k≥1k \ge 1 copies of some seed string tt of length l≥1l \ge 1. For example, the string

s = abaabaabaaba

is a (4,3)(4,3)-repeat with seed string

t = aba

That is, the seed string tt has length 3, and the whole string ss is obtained by repeating tt four times.

Write a program for the following task. The input is a long string uu consisting of the characters ‘a’ and ‘b’. The program must find a (k,l)(k,l)-repeat that occurs as a substring of uu with kk as large as possible. For example, the input string

u = babbabaabaabaabab

contains the (4,3)(4,3)-repeat ss starting at position 5. Since uu contains no other contiguous substring with more than 4 repeats, the program must output this substring.

Input

The first line contains one integer, the length nn of the input string (1≤n≤500001 \le n \le 50000).

The next nn lines contain the input string, one character (‘a’ or ‘b’) per line, in order.

Output

The output consists of three integers, each on its own line. They report the (k,l)(k, l)-repeat your program found as follows.

  1. The first line contains the repeat count kk that is maximized.
  2. The second line contains the length ll of the seed string that is repeated kk times.
  3. The third and final line contains the position pp at which the (k,l)(k, l)-repeat starts (1≤p≤n1 \le p \le n).

If the given input has several answers with the same kk, your program may report any one of them.

Hint

A (4,3)(4, 3)-repeat starts at the 5th character of the input string (line 6 of the input).

Examples1

  1. Example 1

    Input
    17
    b
    a
    b
    b
    a
    b
    a
    a
    b
    a
    a
    b
    a
    a
    b
    a
    b
    
    Expected output
    4
    3
    5