N = int(eval(input()))

S = list(eval(input()))

#LCSRe i番目とj番目でそれぞれ終わるような共通文字列の長さ

#i < j であるi文字目とj文字目が等しいならLCSRe[i + 1][j + 1] = LCSRe[i][j] + 1

#res_lengthよりLCSReの更新した値が大なら、その時のindexをiへ、res_lengthも更新



def longestRepeatedSubstring(s): 

  n = len(s) 

  LCSRe = [[0 for _ in range(n + 1)] for _ in range(n + 1)] 

  res = "" 

  res_length = 0

  index = 0

  for i in range(1, n + 1): 

    for j in range(i + 1, n + 1): 

      if s[i - 1] == s[j - 1] and LCSRe[i - 1][j - 1] < j - i: 

        LCSRe[i][j] = LCSRe[i - 1][j - 1] + 1

        if LCSRe[i][j] > res_length: 

          res_length = LCSRe[i][j] 

          index = max(i, index) 

      else: 

        LCSRe[i][j] = 0

  #print(LCSRe)

  if res_length > 0: 

    for i in range(index - res_length + 1, index + 1): 

      res = res + s[i - 1] 

  return res_length

print((longestRepeatedSubstring(S)))
N = int(eval(input()))

S = list(eval(input())) + ["!"]

dp = [[0] * N for _ in range(N)]

for j in range(1, N):

  if S[0] == S[j]:

    dp[0][j] = 1

res = 0

for i in range(N):

  for j in range(i, N):

    res = max(dp[i][j], res)

    if i == N - 1 or j == N - 1:

      continue

    if S[i + 1] == S[j + 1] and j - i > dp[i][j]:

      dp[i + 1][j + 1] = dp[i][j] + 1

    else:

      dp[i + 1][j + 1] = 0

print(res)
N = int(eval(input()))
S = list(eval(input()))
# LCSRe i番目とj番目でそれぞれ終わるような共通文字列の長さ
# i < j であるi文字目とj文字目が等しいならLCSRe[i + 1][j + 1] = LCSRe[i][j] + 1
# res_lengthよりLCSReの更新した値が大なら、その時のindexをiへ、res_lengthも更新
def longestRepeatedSubstring(s):
    n = len(s)
    LCSRe = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
    res = ""
    res_length = 0
    index = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if s[i - 1] == s[j - 1] and LCSRe[i - 1][j - 1] < j - i:
                LCSRe[i][j] = LCSRe[i - 1][j - 1] + 1
                if LCSRe[i][j] > res_length:
                    res_length = LCSRe[i][j]
                    index = max(i, index)
            else:
                LCSRe[i][j] = 0
    # print(LCSRe)
    if res_length > 0:
        for i in range(index - res_length + 1, index + 1):
            res = res + s[i - 1]
    return res_length


print((longestRepeatedSubstring(S)))

N = int(eval(input()))
S = list(eval(input())) + ["!"]
dp = [[0] * N for _ in range(N)]
for j in range(1, N):
    if S[0] == S[j]:
        dp[0][j] = 1
res = 0
for i in range(N):
    for j in range(i, N):
        res = max(dp[i][j], res)
        if i == N - 1 or j == N - 1:
            continue
        if S[i + 1] == S[j + 1] and j - i > dp[i][j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
        else:
            dp[i + 1][j + 1] = 0
print(res)

-S = list(eval(input())) -# LCSRe i番目とj番目でそれぞれ終わるような共通文字列の長さ -# i < j であるi文字目とj文字目が等しいならLCSRe[i + 1][j + 1] = LCSRe[i][j] + 1 -# res_lengthよりLCSReの更新した値が大なら、その時のindexをiへ、res_lengthも更新 -def longestRepeatedSubstring(s): -    n = len(s) -    LCSRe = [[0 for _ in range(n + 1)] for _ in range(n + 1)] -    res = "" -    res_length = 0 -    index = 0 -    for i in range(1, n + 1): -        for j in range(i + 1, n + 1): -            if s[i - 1] == s[j - 1] and LCSRe[i - 1][j - 1] < j - i: -                LCSRe[i][j] = LCSRe[i - 1][j - 1] + 1 -                if LCSRe[i][j] > res_length: -                    res_length = LCSRe[i][j] -                    index = max(i, index) -            else: -                LCSRe[i][j] = 0 -    # print(LCSRe) -    if res_length > 0: -        for i in range(index - res_length + 1, index + 1): -            res = res + s[i - 1] -    return res_length - - -print((longestRepeatedSubstring(S))) +S = list(eval(input())) + ["!"] +dp = [[0] * N for _ in range(N)] +for j in range(1, N): +    if S[0] == S[j]: +        dp[0][j] = 1 +res = 0 +for i in range(N): +    for j in range(i, N): +        res = max(dp[i][j], res) +        if i == N - 1 or j == N - 1: +            continue +        if S[i + 1] == S[j + 1] and j - i > dp[i][j]: +            dp[i + 1][j + 1] = dp[i][j] + 1 +        else: +            dp[i + 1][j + 1] = 0 +print(res)