n = int(eval(input()))

s = eval(input())



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

while ng-ok > 1:

	x = (ok+ng)//2

	possible = False

	d = set()

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

		d.add(s[i:i+x])

		if s[i+x:i+2*x] in d:

			possible = True

			break

	if possible:

		ok = x

	else:

		ng = x

print(ok)
n = int(eval(input()))

s = eval(input())



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

while ng-ok > 1:

	x = (ok+ng)//2

	possible = False

	d = set()

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

		d.add(hash(s[i:i+x]))

		if hash(s[i+x:i+2*x]) in d:

			possible = True

			break

	if possible:

		ok = x

	else:

		ng = x

print(ok)
n = int(eval(input()))
s = eval(input())
ok, ng = 0, n // 2 + 1
while ng - ok > 1:
    x = (ok + ng) // 2
    possible = False
    d = set()
    for i in range(n - 2 * x + 1):
        d.add(s[i : i + x])
        if s[i + x : i + 2 * x] in d:
            possible = True
            break
    if possible:
        ok = x
    else:
        ng = x
print(ok)

n = int(eval(input()))
s = eval(input())
ok, ng = 0, n // 2 + 1
while ng - ok > 1:
    x = (ok + ng) // 2
    possible = False
    d = set()
    for i in range(n - 2 * x + 1):
        d.add(hash(s[i : i + x]))
        if hash(s[i + x : i + 2 * x]) in d:
            possible = True
            break
    if possible:
        ok = x
    else:
        ng = x
print(ok)

-        d.add(s[i : i + x]) -        if s[i + x : i + 2 * x] in d: +        d.add(hash(s[i : i + x])) +        if hash(s[i + x : i + 2 * x]) in d: