N = int(eval(input()))

Ss = eval(input())



def getZArray(Ss):

    lenS = len(Ss)

    As = [lenS] * lenS

    i, j = 1, 0

    while i < lenS:

        while i+j < lenS and Ss[j] == Ss[i+j]:

            j += 1

        As[i] = j

        if j == 0:

            i += 1

        else:

            k = 1

            while i+k < lenS and k+As[k] < j:

                As[i+k] = As[k]

                k += 1

            i += k

            j -= k

    return As



ans = 0

for i in range(N):

    ZArray = getZArray(Ss[i:])

    for i, Z in enumerate(ZArray):

        L = min(Z, i)

        ans = max(ans, L)



print(ans)

N = int(eval(input()))

Ss = eval(input())



def isOK(k):

    strAs = ['' for _ in range(N)]

    strBs = ['' for _ in range(N)]

    for L in range(N-k+1):

        R = L+k-1

        ss = Ss[L:R+1]

        strAs[R] = ss

        strBs[L] = ss



    strCands = set()

    for iEn in range(N-1):

        if strAs[iEn] != '':

            strCands.add(strAs[iEn])

        if strBs[iEn+1] != '' and strBs[iEn+1] in strCands:

            return True



    return False





ng, ok = N//2 + 1, 0

while abs(ok-ng) > 1:

    mid = (ng+ok) // 2

    if isOK(mid):

        ok = mid

    else:

        ng = mid



print(ok)

N = int(eval(input()))
Ss = eval(input())


def getZArray(Ss):
    lenS = len(Ss)
    As = [lenS] * lenS
    i, j = 1, 0
    while i < lenS:
        while i + j < lenS and Ss[j] == Ss[i + j]:
            j += 1
        As[i] = j
        if j == 0:
            i += 1
        else:
            k = 1
            while i + k < lenS and k + As[k] < j:
                As[i + k] = As[k]
                k += 1
            i += k
            j -= k
    return As


ans = 0
for i in range(N):
    ZArray = getZArray(Ss[i:])
    for i, Z in enumerate(ZArray):
        L = min(Z, i)
        ans = max(ans, L)
print(ans)

N = int(eval(input()))
Ss = eval(input())


def isOK(k):
    strAs = ["" for _ in range(N)]
    strBs = ["" for _ in range(N)]
    for L in range(N - k + 1):
        R = L + k - 1
        ss = Ss[L : R + 1]
        strAs[R] = ss
        strBs[L] = ss
    strCands = set()
    for iEn in range(N - 1):
        if strAs[iEn] != "":
            strCands.add(strAs[iEn])
        if strBs[iEn + 1] != "" and strBs[iEn + 1] in strCands:
            return True
    return False


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

-def getZArray(Ss): -    lenS = len(Ss) -    As = [lenS] * lenS -    i, j = 1, 0 -    while i < lenS: -        while i + j < lenS and Ss[j] == Ss[i + j]: -            j += 1 -        As[i] = j -        if j == 0: -            i += 1 -        else: -            k = 1 -            while i + k < lenS and k + As[k] < j: -                As[i + k] = As[k] -                k += 1 -            i += k -            j -= k -    return As +def isOK(k): +    strAs = ["" for _ in range(N)] +    strBs = ["" for _ in range(N)] +    for L in range(N - k + 1): +        R = L + k - 1 +        ss = Ss[L : R + 1] +        strAs[R] = ss +        strBs[L] = ss +    strCands = set() +    for iEn in range(N - 1): +        if strAs[iEn] != "": +            strCands.add(strAs[iEn]) +        if strBs[iEn + 1] != "" and strBs[iEn + 1] in strCands: +            return True +    return False -ans = 0 -for i in range(N): -    ZArray = getZArray(Ss[i:]) -    for i, Z in enumerate(ZArray): -        L = min(Z, i) -        ans = max(ans, L) -print(ans) +ng, ok = N // 2 + 1, 0 +while abs(ok - ng) > 1: +    mid = (ng + ok) // 2 +    if isOK(mid): +        ok = mid +    else: +        ng = mid +print(ok)