def main():

    n = int(eval(input()))

    s = eval(input())

    dp = [[0]*(n+1) for i in range(n+1)]

    ans = 0

    for i in range(n-1)[::-1]:

        for j in range(i+1,n)[::-1]:

            if s[i] == s[j]:

                dp[i][j] = max(dp[i][j], dp[i+1][j+1] + 1)

                ans = max(ans, min(dp[i][j],j-i))

    print(ans)

main()

n = int(eval(input()))

s = eval(input())



mod = 10**20 + 7

base = 12345



def ok(l):

    array = {}

    rolling_hash = 0

    for i in range(n):

        rolling_hash *= base

        rolling_hash += ord(s[i])

        if i - l >= 0:

            rolling_hash -= ord(s[i-l]) * pow(base, l, mod)

        rolling_hash %= mod

        if i >= l-1:

            if rolling_hash in list(array.keys()):

                array[rolling_hash].append(i)

            else:

                array[rolling_hash] = [i]

    for check in list(array.values()):

        if max(check) - min(check) >= l:

            return True

    return False



top = n

bottom = 0



while top - bottom > 1:

    mid = (top + bottom)//2

    if ok(mid):

        bottom = mid

    else:

        top = mid

print(bottom)

def main():
    n = int(eval(input()))
    s = eval(input())
    dp = [[0] * (n + 1) for i in range(n + 1)]
    ans = 0
    for i in range(n - 1)[::-1]:
        for j in range(i + 1, n)[::-1]:
            if s[i] == s[j]:
                dp[i][j] = max(dp[i][j], dp[i + 1][j + 1] + 1)
                ans = max(ans, min(dp[i][j], j - i))
    print(ans)


main()

n = int(eval(input()))
s = eval(input())
mod = 10**20 + 7
base = 12345


def ok(l):
    array = {}
    rolling_hash = 0
    for i in range(n):
        rolling_hash *= base
        rolling_hash += ord(s[i])
        if i - l >= 0:
            rolling_hash -= ord(s[i - l]) * pow(base, l, mod)
        rolling_hash %= mod
        if i >= l - 1:
            if rolling_hash in list(array.keys()):
                array[rolling_hash].append(i)
            else:
                array[rolling_hash] = [i]
    for check in list(array.values()):
        if max(check) - min(check) >= l:
            return True
    return False


top = n
bottom = 0
while top - bottom > 1:
    mid = (top + bottom) // 2
    if ok(mid):
        bottom = mid
    else:
        top = mid
print(bottom)

-def main(): -    n = int(eval(input())) -    s = eval(input()) -    dp = [[0] * (n + 1) for i in range(n + 1)] -    ans = 0 -    for i in range(n - 1)[::-1]: -        for j in range(i + 1, n)[::-1]: -            if s[i] == s[j]: -                dp[i][j] = max(dp[i][j], dp[i + 1][j + 1] + 1) -                ans = max(ans, min(dp[i][j], j - i)) -    print(ans) +n = int(eval(input())) +s = eval(input()) +mod = 10**20 + 7 +base = 12345 -main() +def ok(l): +    array = {} +    rolling_hash = 0 +    for i in range(n): +        rolling_hash *= base +        rolling_hash += ord(s[i]) +        if i - l >= 0: +            rolling_hash -= ord(s[i - l]) * pow(base, l, mod) +        rolling_hash %= mod +        if i >= l - 1: +            if rolling_hash in list(array.keys()): +                array[rolling_hash].append(i) +            else: +                array[rolling_hash] = [i] +    for check in list(array.values()): +        if max(check) - min(check) >= l: +            return True +    return False + + +top = n +bottom = 0 +while top - bottom > 1: +    mid = (top + bottom) // 2 +    if ok(mid): +        bottom = mid +    else: +        top = mid +print(bottom)