# -*- coding: utf-8 -*-
# E
# 文字列比較をローリングハッシュを用いると高速
# 用いなくてもpypy使わなくえれば通る

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

n = int(input())
s = input()[:-1]
# s = list(map(ord, list(input()[:-1])))
# print(s)

lb = 0
ub = n//2 + 1


def check(len):
    # これはTLE
    for l1 in range(n-len):
        for l2 in range(l1+len, n-len+1):
            if s[l1:l1+len] == s[l2:l2+len]:
                return True
    return False


def check3(m):
    # これはOK(pypyではなくpython3）
    dic = defaultdict(str)
    # dic = {}
    for i in range(n-m+1):
        s_ = s[i:i+m]
        if s_ in dic.keys():
            if dic[s_]+m<=i:
                return True
        else:
            dic[s_] = i
    return False


mod = 10**9+7
base = 1234
power = [1]*(n+1)
for i in range(1, n+1):
    power[i] = power[i-1]*base%mod

def check2(m):
    res = 0
    for i in range(m):
        res+=s[i]*power[m-i-1]
        res%=mod

    dic = {res: 0}
    # defaultdictが早い
    # dic = defaultdict(int)
    # dic[res] = 0

    for i in range(n-m):
        res = ((res-s[i]*power[m-1])*base
                             +s[i+m])%mod
        if res in dic.keys():
            index = dic[res]
            if index +m<=i+1:
                return True
        else:
            dic[res] = i+1
    return False


while ub > lb+1:
    x = (lb + ub)//2
    if check3(x):
        lb = x
    else:
        ub = x
    # print(lb, ub)


'''
print(3, check(3))
print(4, check(4))
print(5, check(5))
'''

print(lb) import sys sys from collections import defaultdict, deque from heapq import heappush, heappop import math math import bisect bisect input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline n = int(input()) n int(input()) int input() input s = input()[:-1] s input()[:-1] () input :-1 -1 lb = 0 lb 0 ub = n//2 + 1 ub n//2 + 1 n//2 n 2 1 def check(len):
    # これはTLE
    for l1 in range(n-len):
        for l2 in range(l1+len, n-len+1):
            if s[l1:l1+len] == s[l2:l2+len]:
                return True
    return False check for l1 in range(n-len):
        for l2 in range(l1+len, n-len+1):
            if s[l1:l1+len] == s[l2:l2+len]:
                return True
     l1 range(n-len) range n-len n len for l2 in range(l1+len, n-len+1):
            if s[l1:l1+len] == s[l2:l2+len]:
                return True
     l2 range(l1+len, n-len+1) range l1+len l1 len n-len+1 n-len n len 1 if s[l1:l1+len] == s[l2:l2+len]:
                return True
     s[l1:l1+len] == s[l2:l2+len] s[l1:l1+len] s l1:l1+len l1 l1+len l1 len s[l2:l2+len] s l2:l2+len l2 l2+len l2 len return True True return False False len len def check3(m):
    # これはOK(pypyではなくpython3）
    dic = defaultdict(str)
    # dic = {}
    for i in range(n-m+1):
        s_ = s[i:i+m]
        if s_ in dic.keys():
            if dic[s_]+m<=i:
                return True
        else:
            dic[s_] = i
    return False check3 dic = defaultdict(str) dic defaultdict(str) defaultdict str for i in range(n-m+1):
        s_ = s[i:i+m]
        if s_ in dic.keys():
            if dic[s_]+m<=i:
                return True
        else:
            dic[s_] = i
     i range(n-m+1) range n-m+1 n-m n m 1 s_ = s[i:i+m] s_ s[i:i+m] s i:i+m i i+m i m if s_ in dic.keys():
            if dic[s_]+m<=i:
                return True
        else:
            dic[s_] = i
     s_ in dic.keys() s_ dic.keys() dic.keys dic keys if dic[s_]+m<=i:
                return True
         dic[s_]+m<=i dic[s_]+m dic[s_] dic s_ m i return True True dic[s_] = i dic[s_] dic s_ i return False False m m mod = 10**9+7 mod 10**9+7 10**9 10 9 7 base = 1234 base 1234 power = [1]*(n+1) power [1]*(n+1) [1] 1 n+1 n 1 for i in range(1, n+1):
    power[i] = power[i-1]*base%mod i range(1, n+1) range 1 n+1 n 1 power[i] = power[i-1]*base%mod power[i] power i power[i-1]*base%mod power[i-1]*base power[i-1] power i-1 i 1 base mod def check2(m):
    res = 0
    for i in range(m):
        res+=s[i]*power[m-i-1]
        res%=mod

    dic = {res: 0}
    # defaultdictが早い
    # dic = defaultdict(int)
    # dic[res] = 0

    for i in range(n-m):
        res = ((res-s[i]*power[m-1])*base
                             +s[i+m])%mod
        if res in dic.keys():
            index = dic[res]
            if index +m<=i+1:
                return True
        else:
            dic[res] = i+1
    return False check2 res = 0 res 0 for i in range(m):
        res+=s[i]*power[m-i-1]
        res%=mod

     i range(m) range m res+=s[i]*power[m-i-1] res s[i]*power[m-i-1] s[i] s i power[m-i-1] power m-i-1 m-i m i 1 res%=mod res mod dic = {res: 0} dic {res: 0} res res 0 for i in range(n-m):
        res = ((res-s[i]*power[m-1])*base
                             +s[i+m])%mod
        if res in dic.keys():
            index = dic[res]
            if index +m<=i+1:
                return True
        else:
            dic[res] = i+1
     i range(n-m) range n-m n m res = ((res-s[i]*power[m-1])*base
                             +s[i+m])%mod res ((res-s[i]*power[m-1])*base
                             +s[i+m])%mod (res-s[i]*power[m-1])*base
                             +s[i+m] (res-s[i]*power[m-1])*base res-s[i]*power[m-1] res s[i]*power[m-1] s[i] s i power[m-1] power m-1 m 1 base s[i+m] s i+m i m mod if res in dic.keys():
            index = dic[res]
            if index +m<=i+1:
                return True
        else:
            dic[res] = i+1
     res in dic.keys() res dic.keys() dic.keys dic keys index = dic[res] index dic[res] dic res if index +m<=i+1:
                return True
         index +m<=i+1 index +m index m i+1 i 1 return True True dic[res] = i+1 dic[res] dic res i+1 i 1 return False False m m while ub > lb+1:
    x = (lb + ub)//2
    if check3(x):
        lb = x
    else:
        ub = x
    # print(lb, ub) ub > lb+1 ub lb+1 lb 1 x = (lb + ub)//2 x (lb + ub)//2 lb + ub lb ub 2 if check3(x):
        lb = x
    else:
        ub = x
    # print(lb, ub) check3(x) check3 x lb = x lb x ub = x ub x '''
print(3, check(3))
print(4, check(4))
print(5, check(5))
''' print(lb) print lb ub = n//2 + 1 n//2 + 1 ub lb = x x lb ub = x x ub def check2(m):
    res = 0
    for i in range(m):
        res+=s[i]*power[m-i-1]
        res%=mod

    dic = {res: 0}
    # defaultdictが早い
    # dic = defaultdict(int)
    # dic[res] = 0

    for i in range(n-m):
        res = ((res-s[i]*power[m-1])*base
                             +s[i+m])%mod
        if res in dic.keys():
            index = dic[res]
            if index +m<=i+1:
                return True
        else:
            dic[res] = i+1
    return False def check2(m):
    res = 0
    for i in range(m):
        res+=s[i]*power[m-i-1]
        res%=mod

    dic = {res: 0}
    # defaultdictが早い
    # dic = defaultdict(int)
    # dic[res] = 0

    for i in range(n-m):
        res = ((res-s[i]*power[m-1])*base
                             +s[i+m])%mod
        if res in dic.keys():
            index = dic[res]
            if index +m<=i+1:
                return True
        else:
            dic[res] = i+1
    return False check2 n = int(input()) int(input()) n lb = 0 0 lb mod = 10**9+7 10**9+7 mod def check(len):
    # これはTLE
    for l1 in range(n-len):
        for l2 in range(l1+len, n-len+1):
            if s[l1:l1+len] == s[l2:l2+len]:
                return True
    return False def check(len):
    # これはTLE
    for l1 in range(n-len):
        for l2 in range(l1+len, n-len+1):
            if s[l1:l1+len] == s[l2:l2+len]:
                return True
    return False check s = input()[:-1] input()[:-1] s input = sys.stdin.readline sys.stdin.readline input def check3(m):
    # これはOK(pypyではなくpython3）
    dic = defaultdict(str)
    # dic = {}
    for i in range(n-m+1):
        s_ = s[i:i+m]
        if s_ in dic.keys():
            if dic[s_]+m<=i:
                return True
        else:
            dic[s_] = i
    return False def check3(m):
    # これはOK(pypyではなくpython3）
    dic = defaultdict(str)
    # dic = {}
    for i in range(n-m+1):
        s_ = s[i:i+m]
        if s_ in dic.keys():
            if dic[s_]+m<=i:
                return True
        else:
            dic[s_] = i
    return False check3 x = (lb + ub)//2 (lb + ub)//2 x base = 1234 1234 base power = [1]*(n+1) [1]*(n+1) power
# -*- coding: utf-8 -*-
# E
# 文字列比較をローリングハッシュを用いると高速
# 用いなくてもpypy使わなくえれば通る

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

n = int(input())
s = input()[:-1]
# s = list(map(ord, list(input()[:-1])))
# print(s)

lb = 0
ub = n//2 + 1


def check(len):
    # これはTLE
    for l1 in range(n-len):
        for l2 in range(l1+len, n-len+1):
            if s[l1:l1+len] == s[l2:l2+len]:
                return True
    return False


def check3(m):
    # これはOK(pypyではなくpython3）
    dic = defaultdict(str)
    # dic = {}
    for i in range(n-m+1):
        s_ = s[i:i+m]
        if s_ in dic.keys():
            if dic[s_]+m<=i:
                return True
        else:
            dic[s_] = i
    return False


mod = 10**9+7
base = 1234
power = [1]*(n+1)
for i in range(1, n+1):
    power[i] = power[i-1]*base%mod

def check2(m):
    res = 0
    for i in range(m):
        res+=s[i]*power[m-i-1]
        res%=mod

    dic = {res: 0}
    # defaultdictが早い
    # dic = defaultdict(int)
    # dic[res] = 0

    for i in range(n-m):
        res = ((res-s[i]*power[m-1])*base
                             +s[i+m])%mod
        if res in dic.keys():
            index = dic[res]
            if index +m<=i+1:
                return True
        else:
            dic[res] = i+1
    return False


while ub > lb+1:
    x = (lb + ub)//2
    if check3(x):
        lb = x
    else:
        ub = x
    # print(lb, ub)


'''
print(3, check(3))
print(4, check(4))
print(5, check(5))
'''

print(lb)