N = int(eval(input()))

S = eval(input())



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



for i in range(N-1, -1, -1):

    for j in range(N-1, -1, -1):

        if S[i] == S[j]:

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



ans = 0

for i in range(N):

    for j in range(N):

        if i >= j:

            continue

        now = min(dp[i][j], j-i)

        ans = max(ans, now)



print(ans)

N = int(eval(input()))

S = eval(input())



ans = 0

for i in range(N-1):

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

        if S[i] == S[j]:

            if i != 0:

                if S[i-1] == S[j-1]:

                    continue

            equal = 1

            for k in range(1, min(j-i, N-j)):

                if S[i+k] == S[j+k]:

                    equal += 1

                else:

                    break

            ans = max(ans, equal)



print(ans)

N = int(eval(input()))
S = eval(input())
dp = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(N - 1, -1, -1):
    for j in range(N - 1, -1, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i + 1][j + 1] + 1
ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        now = min(dp[i][j], j - i)
        ans = max(ans, now)
print(ans)

N = int(eval(input()))
S = eval(input())
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if S[i] == S[j]:
            if i != 0:
                if S[i - 1] == S[j - 1]:
                    continue
            equal = 1
            for k in range(1, min(j - i, N - j)):
                if S[i + k] == S[j + k]:
                    equal += 1
                else:
                    break
            ans = max(ans, equal)
print(ans)

-dp = [[0] * (N + 1) for _ in range(N + 1)] -for i in range(N - 1, -1, -1): -    for j in range(N - 1, -1, -1): +ans = 0 +for i in range(N - 1): +    for j in range(i + 1, N): -            dp[i][j] = dp[i + 1][j + 1] + 1 -ans = 0 -for i in range(N): -    for j in range(N): -        if i >= j: -            continue -        now = min(dp[i][j], j - i) -        ans = max(ans, now) +            if i != 0: +                if S[i - 1] == S[j - 1]: +                    continue +            equal = 1 +            for k in range(1, min(j - i, N - j)): +                if S[i + k] == S[j + k]: +                    equal += 1 +                else: +                    break +            ans = max(ans, equal)