N = int(eval(input()))

S = eval(input())

ans = 0

for i in range(N):

    if N-i<ans:

        break

    if S[i+1:].find(S[i-ans:i+1])>=0:

        ans += 1

print(ans)
from collections import defaultdict

N = int(eval(input()))

S = list(map(ord, list(eval(input()))))

mod = 10**9+7

base = 1234

power = [1]*(N+1)

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

    power[i] = power[i-1]*base%mod

def check(m):

    if N-m<m:

        return False

    res = 0

    for i in range(m):

        res+=S[i]*power[m-i-1]

        res%=mod

    dic = defaultdict(lambda : -1)

    dic[res] = 0

    for i in range(N-m):

        res = ((res-S[i]*power[m-1])*base

                             +S[i+m])%mod

        if dic[res]>=0:

            index = dic[res]

            if index +m<=i+1:

                return True

        else:

            dic[res] = i+1

    return False

ok = 0

ng = N+1

while ng-ok>1:

    mid = (ok+ng)//2

    

    if check(mid):

        ok = mid

    else:

        ng = mid

print(ok)

        

N = int(eval(input()))
S = eval(input())
ans = 0
for i in range(N):
    if N - i < ans:
        break
    if S[i + 1 :].find(S[i - ans : i + 1]) >= 0:
        ans += 1
print(ans)

from collections import defaultdict

N = int(eval(input()))
S = list(map(ord, list(eval(input()))))
mod = 10**9 + 7
base = 1234
power = [1] * (N + 1)
for i in range(1, N + 1):
    power[i] = power[i - 1] * base % mod


def check(m):
    if N - m < m:
        return False
    res = 0
    for i in range(m):
        res += S[i] * power[m - i - 1]
        res %= mod
    dic = defaultdict(lambda: -1)
    dic[res] = 0
    for i in range(N - m):
        res = ((res - S[i] * power[m - 1]) * base + S[i + m]) % mod
        if dic[res] >= 0:
            index = dic[res]
            if index + m <= i + 1:
                return True
        else:
            dic[res] = i + 1
    return False


ok = 0
ng = N + 1
while ng - ok > 1:
    mid = (ok + ng) // 2
    if check(mid):
        ok = mid
    else:
        ng = mid
print(ok)

+from collections import defaultdict + -S = eval(input()) -ans = 0 -for i in range(N): -    if N - i < ans: -        break -    if S[i + 1 :].find(S[i - ans : i + 1]) >= 0: -        ans += 1 -print(ans) +S = list(map(ord, list(eval(input())))) +mod = 10**9 + 7 +base = 1234 +power = [1] * (N + 1) +for i in range(1, N + 1): +    power[i] = power[i - 1] * base % mod + + +def check(m): +    if N - m < m: +        return False +    res = 0 +    for i in range(m): +        res += S[i] * power[m - i - 1] +        res %= mod +    dic = defaultdict(lambda: -1) +    dic[res] = 0 +    for i in range(N - m): +        res = ((res - S[i] * power[m - 1]) * base + S[i + m]) % mod +        if dic[res] >= 0: +            index = dic[res] +            if index + m <= i + 1: +                return True +        else: +            dic[res] = i + 1 +    return False + + +ok = 0 +ng = N + 1 +while ng - ok > 1: +    mid = (ok + ng) // 2 +    if check(mid): +        ok = mid +    else: +        ng = mid +print(ok)