The task is to find a substring that is occurs continuously in a 
given string (which be represented as S). It's easy to find several
O(n^2) algorithms.
  - Process KMP n times at n different starting point. Suppose now
    you are process KMP starting at i. If (j+1-i) mod (j+1-i-pi[j])
    =0, you can conclude that there is a subtring that occurs 
    continuously (j+1-i) div (j+1-i-pi[j]) times in the S[i..j].
  - Use f[i,j] represent the maximal k such that 
      S[i+1-kj]=S[i+1-(k-1)j]=...=s[i]
    obviously f[i,j]=f[i-j,j] if S[i]=S[i-j] and f[i,j]=0 otherwise.
    then the times that S[i,j] continuously occurs before s[j] is
    min{f[i,j+1-i],f[i+1,j+1-i],...,f[j,j+1-i]}
  - There are many such kind of O(n^2) algorithms that I don't know...

Since for this problem n is up to 50,000, an O(n^2) algorithm is not 
enough. We have to design a more efficient algorithm. Notice that if 
we have found that S[i,j] where some string occurs k (k>1, for k=1 is 
trivial) with length l. then for any substring of S[i,j] with 
length l S[p,p+l-1], we can expand it to the left and to the right 
with matching. And Note that n/1+n/2+...+n/l=O(nlogn). It drives us
to design an algorithm which, for length l, divide S into n/l blocks,
and for each block expand it to the left and to the right with 
matching. 
For example, for string
  aabaabaabaab
we can get it if we expand the substring baa (from position 3 to 
position 5) matching aa with aab and baabaab with baa)
Now the problem leave us how to expand a substring with matching 
quickly.

Here suffix array is a good way to achieve it. As we know that suffix
array can make us get LCP (Longest Common Prefix) of any two suffix of 
S in O(1) time. Then when we want to expand S[i,i+l-1] to the right
we see LCP of S[i..n] and S[i+l-1..n], and see LCP of S'[i..n] and 
S'[i+l-1..n] (where S' is the reverse of S) when to the left.

Since suffix array can be preprocessed in O(nlogn) time, and n/1+n/2+
...+n/l=O(nlogn). The time complexity of this algorithm is O(nlogn).
But you have to build suffix array two times for there is also an S'.
The algorithm is still a little slow. Here in our contest I have 
design an O(n(logn)^2) algorithm which interestingly a little faster
than the O(nlogn) algorithm for it need not build the suffix array of
S'.

The algorithm just simply change LCP in O(1) time to that we verify 
two substring of S of length l in O(logl) time. It's easy to achieve
use the intermediate result of suffix array (i.e.: the rank of 
S[i,i+2^k-1]). We can divide the target string into some string of 
length 1,2,...,2^k,... then compare them separately. Since the string
does not always match. This comparing procession will be stop quickly
at most of the time. For length l, you can divide S into n/l blocks 
and for each consecutive same blocks expand to the left and to the 
right. Here the expanding operation is somewhat like comparing 
substing just to see whether it can be expanded 2^k, 2^k-1, etc.

The program repeats.pas is the O(n(logn)^2) algorithm, while 
repeats2.pas is the O(nlogn) algorithm. Interestingly, the 
O(n(logn)^2) algorithm is a little faster than O(nlogn).

If you think more about this problem, you will get a theoretic O(n)
algorithm by using some trick to reduce the number of necessary 
repetends to O(n) and using suffix tree instead of suffix array.
I will put on this algorithm as soon as possible :)