n = int(eval(input()))

s = eval(input())

high = n//2

low = 1

ans = 0



while low <= high:

    t = set()

    i = (high+low)//2

    for j in range(n-i*2+1):

        t.add(s[j:i+j])

        if s[i+j:j+2*i] in t:

            if ans < i:

                ans = i

                low = i+1

                break

    if ans < i:

        high = i-1

print(ans)
import sys

input = sys.stdin.readline

 

def main():

    n = int(eval(input()))

    s = eval(input())

    high = n//2

    low = 1

    ans = 0



    while low <= high:

        t = set()

        i = (high+low)//2

        for j in range(n-i*2+1):

            t.add(s[j:i+j])

            if s[i+j:j+2*i] in t:

                if ans < i:

                    ans = i

                    low = i+1

                    break

        if ans < i:

            high = i-1

    print(ans)



if __name__ == '__main__':

    main()
n = int(eval(input()))
s = eval(input())
high = n // 2
low = 1
ans = 0
while low <= high:
    t = set()
    i = (high + low) // 2
    for j in range(n - i * 2 + 1):
        t.add(s[j : i + j])
        if s[i + j : j + 2 * i] in t:
            if ans < i:
                ans = i
                low = i + 1
                break
    if ans < i:
        high = i - 1
print(ans)

import sys

input = sys.stdin.readline


def main():
    n = int(eval(input()))
    s = eval(input())
    high = n // 2
    low = 1
    ans = 0
    while low <= high:
        t = set()
        i = (high + low) // 2
        for j in range(n - i * 2 + 1):
            t.add(s[j : i + j])
            if s[i + j : j + 2 * i] in t:
                if ans < i:
                    ans = i
                    low = i + 1
                    break
        if ans < i:
            high = i - 1
    print(ans)


if __name__ == "__main__":
    main()

-n = int(eval(input())) -s = eval(input()) -high = n // 2 -low = 1 -ans = 0 -while low <= high: -    t = set() -    i = (high + low) // 2 -    for j in range(n - i * 2 + 1): -        t.add(s[j : i + j]) -        if s[i + j : j + 2 * i] in t: -            if ans < i: -                ans = i -                low = i + 1 -                break -    if ans < i: -        high = i - 1 -print(ans) +import sys + +input = sys.stdin.readline + + +def main(): +    n = int(eval(input())) +    s = eval(input()) +    high = n // 2 +    low = 1 +    ans = 0 +    while low <= high: +        t = set() +        i = (high + low) // 2 +        for j in range(n - i * 2 + 1): +            t.add(s[j : i + j]) +            if s[i + j : j + 2 * i] in t: +                if ans < i: +                    ans = i +                    low = i + 1 +                    break +        if ans < i: +            high = i - 1 +    print(ans) + + +if __name__ == "__main__": +    main()