>>102462320
def build_suffix_array(s):
return sorted(range(len(s)), key=lambda i: s[i:])
def lcp(s1, s2):
length = min(len(s1), len(s2))
for i in range(length):
if s1[i] != s2[i]:
return s1[:i]
return s1[:length]
def longest_repeated_substring(s):
suffix_array = build_suffix_array(s)
result = ''
for i in range(len(s)-1):
substring = lcp(s[suffix_array[i]:], s[suffix_array[i+1]:])
result = max(result, substring, key=len)
return result