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())



BASE = 10**9 + 7

MOD = 2**61 - 1



def genRollingHash_AllRight(Ss, lenInit, BASE, MOD):

    As = [ord(S) for S in Ss]

    hashS = 0

    for A in As[:lenInit]:

        hashS = (hashS*BASE + A) % MOD

    yield hashS



    powB_L = pow(BASE, lenInit, MOD)

    for Aadd, Asub in zip(As[lenInit:], As[:len(As)-lenInit]):

        hashS = (hashS*BASE + Aadd - Asub*powB_L) % MOD

        yield hashS



def isOK(k):

    hashSs = list(genRollingHash_AllRight(Ss, k, BASE, MOD))

    setHashS = set()

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

        setHashS.add(hashSs[i-k])

        if hashSs[i] in setHashS:

            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 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())
BASE = 10**9 + 7
MOD = 2**61 - 1


def genRollingHash_AllRight(Ss, lenInit, BASE, MOD):
    As = [ord(S) for S in Ss]
    hashS = 0
    for A in As[:lenInit]:
        hashS = (hashS * BASE + A) % MOD
    yield hashS
    powB_L = pow(BASE, lenInit, MOD)
    for Aadd, Asub in zip(As[lenInit:], As[: len(As) - lenInit]):
        hashS = (hashS * BASE + Aadd - Asub * powB_L) % MOD
        yield hashS


def isOK(k):
    hashSs = list(genRollingHash_AllRight(Ss, k, BASE, MOD))
    setHashS = set()
    for i in range(k, N - k + 1):
        setHashS.add(hashSs[i - k])
        if hashSs[i] in setHashS:
            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)

+BASE = 10**9 + 7 +MOD = 2**61 - 1 + + +def genRollingHash_AllRight(Ss, lenInit, BASE, MOD): +    As = [ord(S) for S in Ss] +    hashS = 0 +    for A in As[:lenInit]: +        hashS = (hashS * BASE + A) % MOD +    yield hashS +    powB_L = pow(BASE, lenInit, MOD) +    for Aadd, Asub in zip(As[lenInit:], As[: len(As) - lenInit]): +        hashS = (hashS * BASE + Aadd - Asub * powB_L) % MOD +        yield hashS -    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: +    hashSs = list(genRollingHash_AllRight(Ss, k, BASE, MOD)) +    setHashS = set() +    for i in range(k, N - k + 1): +        setHashS.add(hashSs[i - k]) +        if hashSs[i] in setHashS: