# PyPy なら通る

# DP(貰うDP)

N = int(eval(input()))

S = eval(input())



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

result = 0

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

            t = dp[i][j]

            if t > j - i:

                t = j - i

            if t > result:

                result = t

print(result)

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

result = 0

for i in range(N):

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

        t = dp[i][j]

        if t > j - i:

            t = j - i

        if t > result:

            result = t

print(result)

# PyPy なら通る
# DP(貰うDP)
N = int(eval(input()))
S = eval(input())
dp = [[0] * (N + 1) for _ in range(N + 1)]
result = 0
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
            t = dp[i][j]
            if t > j - i:
                t = j - i
            if t > result:
                result = t
print(result)

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
result = 0
for i in range(N):
    for j in range(i + 1, N):
        t = dp[i][j]
        if t > j - i:
            t = j - i
        if t > result:
            result = t
print(result)

-# PyPy なら通る -# DP(貰うDP) -result = 0 -            t = dp[i][j] -            if t > j - i: -                t = j - i -            if t > result: -                result = t +result = 0 +for i in range(N): +    for j in range(i + 1, N): +        t = dp[i][j] +        if t > j - i: +            t = j - i +        if t > result: +            result = t