You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).
The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100.
def build_suffix_array(string):
    length = len(string)
    suffix_array = [i for i in range(length)]
    rank = [ord(string[i]) for i in range(length)]
    k = 1
    while k < length:
        suffix_array.sort(key=lambda i: (rank[i], rank[i+k] if i+k < length else -1))
        new_rank = [0] * length
        r = 0
        for i in range(length):
            if i > 0 and rank[suffix_array[i]] == rank[suffix_array[i-1]] and rank[suffix_array[i]+k if suffix_array[i]+k < length else -1] == rank[suffix_array[i-1]+k if suffix_array[i-1]+k < length else -1]:
                new_rank[suffix_array[i]] = r
            else:
                r += 1
                new_rank[suffix_array[i]] = r
        rank = new_rank
        k *= 2
    return suffix_array

def lcp_array(string, suffix_array):
    length = len(string)
    rank = [0] * length
    for i in range(length):
        rank[suffix_array[i]] = i
    lcp = [0] * (length-1)
    h = 0
    for i in range(length):
        if rank[i] < length-1:
            j = suffix_array[rank[i]+1]
            while i+h < length and j+h < length and string[i+h] == string[j+h]:
                h += 1
            lcp[rank[i]] = h
            if h > 0:
                h -= 1
    return lcp

input_string = input()
length = len(input_string)
suffix_array = build_suffix_array(input_string)
lcp = lcp_array(input_string, suffix_array)
answer = max(lcp) if lcp else 0
print(answer)

 	 		 	  		 				  	 		      			