Period

Time limit1sMemory limit128 MB

Summary
For every prefix of a string, find the largest exponent K such that the prefix equals some string A repeated K times, using KMP failure function.
Level

Medium4 of 10

Topics
String matching, String, Implementation
Solved
No attempts yet

Problem

You are given a string SS made of NN characters whose ASCII codes are between 9797 and 126126 inclusive. For every prefix of SS, you want to decide whether that prefix is a periodic string.

More precisely, for each ii with 2≤i≤N2 \le i \le N, consider the prefix of SS of length ii. You want the largest K>1K > 1 such that this prefix can be written as AKA^K for some string AA.

Here AKA^K denotes the string formed by concatenating AA exactly KK times. For example, if AA is abad and K=3K = 3, then AKA^K is abadabadabad.

Input

The input consists of several test cases. Each test case is given on two lines. The first line contains an integer NN, the length of the string SS (2≤N≤1062 \le N \le 10^6). The second line contains the string SS. The end of the input is indicated by a line containing a single 00.

Output

For each test case, print Test case # followed by the test case number on one line. Then, for every length ii whose prefix can be written as AKA^K with a largest exponent K>1K > 1, print the length ii and that value KK on one line, separated by a space. Print these lines in increasing order of the prefix length ii. After the answer for each test case, print one blank line.

Examples1

  1. Example 1

    Input
    3
    aaa
    12
    aabaabaabaab
    0
    
    Expected output
    Test case #1
    2 2
    3 3
    
    Test case #2
    2 2
    6 2
    9 3
    12 4