def func(s):
for l in range(1, len(s) + 1):
r = s[:l]
if len(r) * 2 > len(s):
return s
f = True
for m in range(l * 2, len(s) + 1, l):
if r != s[m - l:m]:
f = False
break
if f:
break
return r
print(func('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'))
print(func('123412312341231234123123412312341231234123'))
print(func('oxoxoxoxoxoxoxoxxoxoxoxoxoxoxoxoxx'))
print(func('abac'))
ZGVmIGZ1bmMocyk6Cglmb3IgbCBpbiByYW5nZSgxLCBsZW4ocykgKyAxKToKCQlyID0gc1s6bF0KCQlpZiBsZW4ocikgKiAyID4gbGVuKHMpOgoJCQlyZXR1cm4gcwoJCWYgPSBUcnVlCgkJZm9yIG0gaW4gcmFuZ2UobCAqIDIsIGxlbihzKSArIDEsIGwpOgoJCQlpZiByICE9IHNbbSAtIGw6bV06CgkJCQlmID0gRmFsc2UKCQkJCWJyZWFrCgkJaWYgZjoKCQkJYnJlYWsKCXJldHVybiByCgpwcmludChmdW5jKCdhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYScpKQpwcmludChmdW5jKCcxMjM0MTIzMTIzNDEyMzEyMzQxMjMxMjM0MTIzMTIzNDEyMzEyMzQxMjMnKSkKcHJpbnQoZnVuYygnb3hveG94b3hveG94b3hveHhveG94b3hveG94b3hveG94eCcpKQpwcmludChmdW5jKCdhYmFjJykpCg==