N = int(eval(input()))

S = eval(input())



ans = 0

while S:

    Z = [0] * N

    i = 1

    j = 0

    while i < N:

        while i + j < N and S[j] == S[i + j]:

            j += 1



        Z[i] = j



        if j == 0:

            i += 1

        else:

            k = 1

            while k < j and k + Z[k] < j:

                Z[i + k] = Z[k]

                k += 1

            i += k

            j -= k    



    ans = max(ans, max(min(i, z) for i, z in enumerate(Z)))



    S = S[1:]

    N -= 1



print(ans)
N = int(eval(input()))

S = eval(input())



MOD = 2 ** 61 - 1

root = 10000



rhs = [0]

for h in map(ord, S):

    rhs.append((root * rhs[-1] + h) % MOD)



pws = [1]

for i in range(N):

    pws.append(pws[-1] * root % MOD)



ok = 0

ng = N

while ng - ok > 1:

    mid = (ok + ng) // 2

    hashes = dict()

    flg = False

    for i in range(N - mid + 1):

        hashofsub = (rhs[i+mid] - rhs[i] * pws[mid]) % MOD

        if hashofsub in hashes:

            if i >= hashes[hashofsub] + mid:

                flg = True

                break

        else:

            hashes[hashofsub] = i

    

    if flg:

        ok = mid

    else:

        ng = mid



print(ok)
N = int(eval(input()))
S = eval(input())
ans = 0
while S:
    Z = [0] * N
    i = 1
    j = 0
    while i < N:
        while i + j < N and S[j] == S[i + j]:
            j += 1
        Z[i] = j
        if j == 0:
            i += 1
        else:
            k = 1
            while k < j and k + Z[k] < j:
                Z[i + k] = Z[k]
                k += 1
            i += k
            j -= k
    ans = max(ans, max(min(i, z) for i, z in enumerate(Z)))
    S = S[1:]
    N -= 1
print(ans)

N = int(eval(input()))
S = eval(input())
MOD = 2**61 - 1
root = 10000
rhs = [0]
for h in map(ord, S):
    rhs.append((root * rhs[-1] + h) % MOD)
pws = [1]
for i in range(N):
    pws.append(pws[-1] * root % MOD)
ok = 0
ng = N
while ng - ok > 1:
    mid = (ok + ng) // 2
    hashes = dict()
    flg = False
    for i in range(N - mid + 1):
        hashofsub = (rhs[i + mid] - rhs[i] * pws[mid]) % MOD
        if hashofsub in hashes:
            if i >= hashes[hashofsub] + mid:
                flg = True
                break
        else:
            hashes[hashofsub] = i
    if flg:
        ok = mid
    else:
        ng = mid
print(ok)

-ans = 0 -while S: -    Z = [0] * N -    i = 1 -    j = 0 -    while i < N: -        while i + j < N and S[j] == S[i + j]: -            j += 1 -        Z[i] = j -        if j == 0: -            i += 1 +MOD = 2**61 - 1 +root = 10000 +rhs = [0] +for h in map(ord, S): +    rhs.append((root * rhs[-1] + h) % MOD) +pws = [1] +for i in range(N): +    pws.append(pws[-1] * root % MOD) +ok = 0 +ng = N +while ng - ok > 1: +    mid = (ok + ng) // 2 +    hashes = dict() +    flg = False +    for i in range(N - mid + 1): +        hashofsub = (rhs[i + mid] - rhs[i] * pws[mid]) % MOD +        if hashofsub in hashes: +            if i >= hashes[hashofsub] + mid: +                flg = True +                break -            k = 1 -            while k < j and k + Z[k] < j: -                Z[i + k] = Z[k] -                k += 1 -            i += k -            j -= k -    ans = max(ans, max(min(i, z) for i, z in enumerate(Z))) -    S = S[1:] -    N -= 1 -print(ans) +            hashes[hashofsub] = i +    if flg: +        ok = mid +    else: +        ng = mid +print(ok)