import random
from collections import defaultdict


def atoi(s):
    return ord(s) - ord("a") + 1


N = int(input())
S = input()

mod = (1 << 61) - 1
b = random.randint(10000, mod - 1)


l = 0
r = (N + 1) // 2 + 1
while r - l > 1:
    d = (r + l) // 2
    memo = defaultdict(int)
    isok = False
    h = 0
    t = pow(b, d, mod)
    for i in range(d):
        h = (h * b + atoi(S[i])) % mod
    memo[h] = 1
    for i in range(1, N - d + 1):
        h = (h*b + atoi(S[i+d-1]) - t * atoi(S[i-1])) % mod
        if not memo[h]:
            memo[h] = i + 1
        elif memo[h] and i - memo[h] + 1 >= d:
            isok = True
    if isok:
        l = d
    else:
        r = d

print(l) import random random from collections import defaultdict def atoi(s):
    return ord(s) - ord("a") + 1 atoi return ord(s) - ord("a") + 1 ord(s) - ord("a") + 1 ord(s) - ord("a") ord(s) ord s ord("a") ord "a" 1 s s N = int(input()) N int(input()) int input() input S = input() S input() input mod = (1 << 61) - 1 mod (1 << 61) - 1 1 << 61 1 61 1 b = random.randint(10000, mod - 1) b random.randint(10000, mod - 1) random.randint random randint 10000 mod - 1 mod 1 l = 0 l 0 r = (N + 1) // 2 + 1 r (N + 1) // 2 + 1 (N + 1) // 2 N + 1 N 1 2 1 while r - l > 1:
    d = (r + l) // 2
    memo = defaultdict(int)
    isok = False
    h = 0
    t = pow(b, d, mod)
    for i in range(d):
        h = (h * b + atoi(S[i])) % mod
    memo[h] = 1
    for i in range(1, N - d + 1):
        h = (h*b + atoi(S[i+d-1]) - t * atoi(S[i-1])) % mod
        if not memo[h]:
            memo[h] = i + 1
        elif memo[h] and i - memo[h] + 1 >= d:
            isok = True
    if isok:
        l = d
    else:
        r = d r - l > 1 r - l r l 1 d = (r + l) // 2 d (r + l) // 2 r + l r l 2 memo = defaultdict(int) memo defaultdict(int) defaultdict int isok = False isok False h = 0 h 0 t = pow(b, d, mod) t pow(b, d, mod) pow b d mod for i in range(d):
        h = (h * b + atoi(S[i])) % mod
     i range(d) range d h = (h * b + atoi(S[i])) % mod h (h * b + atoi(S[i])) % mod h * b + atoi(S[i]) h * b h b atoi(S[i]) atoi S[i] S i mod memo[h] = 1 memo[h] memo h 1 for i in range(1, N - d + 1):
        h = (h*b + atoi(S[i+d-1]) - t * atoi(S[i-1])) % mod
        if not memo[h]:
            memo[h] = i + 1
        elif memo[h] and i - memo[h] + 1 >= d:
            isok = True
     i range(1, N - d + 1) range 1 N - d + 1 N - d N d 1 h = (h*b + atoi(S[i+d-1]) - t * atoi(S[i-1])) % mod h (h*b + atoi(S[i+d-1]) - t * atoi(S[i-1])) % mod h*b + atoi(S[i+d-1]) - t * atoi(S[i-1]) h*b + atoi(S[i+d-1]) h*b h b atoi(S[i+d-1]) atoi S[i+d-1] S i+d-1 i+d i d 1 t * atoi(S[i-1]) t atoi(S[i-1]) atoi S[i-1] S i-1 i 1 mod if not memo[h]:
            memo[h] = i + 1
        elif memo[h] and i - memo[h] + 1 >= d:
            isok = True
     not memo[h] memo[h] memo h memo[h] = i + 1 memo[h] memo h i + 1 i 1 elif memo[h] and i - memo[h] + 1 >= d:
            isok = True
     memo[h] and i - memo[h] + 1 >= d memo[h] memo h i - memo[h] + 1 >= d i - memo[h] + 1 i - memo[h] i memo[h] memo h 1 d isok = True isok True if isok:
        l = d
    else:
        r = d isok l = d l d r = d r d print(l) print l l = d d l mod = (1 << 61) - 1 (1 << 61) - 1 mod d = (r + l) // 2 (r + l) // 2 d isok = True True isok memo = defaultdict(int) defaultdict(int) memo N = int(input()) int(input()) N r = (N + 1) // 2 + 1 (N + 1) // 2 + 1 r h = 0 0 h h = (h*b + atoi(S[i+d-1]) - t * atoi(S[i-1])) % mod (h*b + atoi(S[i+d-1]) - t * atoi(S[i-1])) % mod h b = random.randint(10000, mod - 1) random.randint(10000, mod - 1) b r = d d r def atoi(s):
    return ord(s) - ord("a") + 1 def atoi(s):
    return ord(s) - ord("a") + 1 atoi S = input() input() S h = (h * b + atoi(S[i])) % mod (h * b + atoi(S[i])) % mod h t = pow(b, d, mod) pow(b, d, mod) t l = 0 0 l isok = False False isok
import random
from collections import defaultdict


def atoi(s):
    return ord(s) - ord("a") + 1


N = int(input())
S = input()

mod = (1 << 61) - 1
b = random.randint(10000, mod - 1)


l = 0
r = (N + 1) // 2 + 1
while r - l > 1:
    d = (r + l) // 2
    memo = defaultdict(int)
    isok = False
    h = 0
    t = pow(b, d, mod)
    for i in range(d):
        h = (h * b + atoi(S[i])) % mod
    memo[h] = 1
    for i in range(1, N - d + 1):
        h = (h*b + atoi(S[i+d-1]) - t * atoi(S[i-1])) % mod
        if not memo[h]:
            memo[h] = i + 1
        elif memo[h] and i - memo[h] + 1 >= d:
            isok = True
    if isok:
        l = d
    else:
        r = d

print(l)