def zalgo(S):

    # SとS[i:n]のlcpの長さを記録した配列を返す

    n = len(S)

    A = [0] * n

    j = 0

    for i in range(1, n):

        if i+A[i-j] < j+A[j]:

            A[i] = A[i-j]

        else:

            k = max(0, A[j]-i+j)

            while i+k < n and S[k] == S[i+k]:

                k += 1

            A[i] = k

            j = i

    A[0] = n

    return A





n = int(eval(input()))

S = eval(input())

l = 0

for i in range(n):

    A = zalgo(S[i:])

    B = [min(j, a) for j, a in enumerate(A)]

    l = max(l, max(B))

print(l)

def ok(l):

    # 長さlの連続部分列で重ならずに2回以上現れるものがある

    D = {}

    for i in range(n-l+1):

        try:

            if D[S[i:i+l]]+l <= i:

                return True

        except:

            D[S[i:i+l]] = i

    return False





n = int(eval(input()))

S = eval(input())

# 二分探索でTrueになる最大のkを求める

l, r = 0, n+1

while r-l > 1:

    c = (l+r)//2

    if ok(c):

        l = c

    else:

        r = c

print(l)

def zalgo(S):
    # SとS[i:n]のlcpの長さを記録した配列を返す
    n = len(S)
    A = [0] * n
    j = 0
    for i in range(1, n):
        if i + A[i - j] < j + A[j]:
            A[i] = A[i - j]
        else:
            k = max(0, A[j] - i + j)
            while i + k < n and S[k] == S[i + k]:
                k += 1
            A[i] = k
            j = i
    A[0] = n
    return A


n = int(eval(input()))
S = eval(input())
l = 0
for i in range(n):
    A = zalgo(S[i:])
    B = [min(j, a) for j, a in enumerate(A)]
    l = max(l, max(B))
print(l)

def ok(l):
    # 長さlの連続部分列で重ならずに2回以上現れるものがある
    D = {}
    for i in range(n - l + 1):
        try:
            if D[S[i : i + l]] + l <= i:
                return True
        except:
            D[S[i : i + l]] = i
    return False


n = int(eval(input()))
S = eval(input())
# 二分探索でTrueになる最大のkを求める
l, r = 0, n + 1
while r - l > 1:
    c = (l + r) // 2
    if ok(c):
        l = c
    else:
        r = c
print(l)

-def zalgo(S): -    # SとS[i:n]のlcpの長さを記録した配列を返す -    n = len(S) -    A = [0] * n -    j = 0 -    for i in range(1, n): -        if i + A[i - j] < j + A[j]: -            A[i] = A[i - j] -        else: -            k = max(0, A[j] - i + j) -            while i + k < n and S[k] == S[i + k]: -                k += 1 -            A[i] = k -            j = i -    A[0] = n -    return A +def ok(l): +    # 長さlの連続部分列で重ならずに2回以上現れるものがある +    D = {} +    for i in range(n - l + 1): +        try: +            if D[S[i : i + l]] + l <= i: +                return True +        except: +            D[S[i : i + l]] = i +    return False -l = 0 -for i in range(n): -    A = zalgo(S[i:]) -    B = [min(j, a) for j, a in enumerate(A)] -    l = max(l, max(B)) +# 二分探索でTrueになる最大のkを求める +l, r = 0, n + 1 +while r - l > 1: +    c = (l + r) // 2 +    if ok(c): +        l = c +    else: +        r = c