from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
s = input()
dp = [[0 for i in range(n+5)] for j in range(n+5)]
res = 0
for i in range(n)[::-1]:
    for j in range(n)[::-1]:
        if i >= j: continue
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1
        else:
            dp[i][j] = 0
for i in range(n):
    for j in range(n):
        tmp = min(j-i, dp[i][j])
        res = max(res, tmp)
print(res) from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,pprint,fractions sys bisect math itertools pprint fractions sys.setrecursionlimit(10**8) sys.setrecursionlimit sys setrecursionlimit 10**8 10 8 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 INF = float('inf') INF float('inf') float 'inf' def inp(): return int(sys.stdin.readline()) inp def inpl(): return list(map(int, sys.stdin.readline().split())) inpl n = inp() n inp() inp s = input() s input() input [0 for i in range(n+5)] for j in range(n+5) for j in range(n+5) j range(n+5) range n+5 n 5 for j in range(n+5) [0 for i in range(n+5)] dp = [[0 for i in range(n+5)] for j in range(n+5)] dp [[0 for i in range(n+5)] for j in range(n+5)] res = 0 res 0 for i in range(n)[::-1]:
    for j in range(n)[::-1]:
        if i >= j: continue
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1
        else:
            dp[i][j] = 0 i range(n)[::-1] (n) range n ::-1 -1 for j in range(n)[::-1]:
        if i >= j: continue
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1
        else:
            dp[i][j] = 0 j range(n)[::-1] (n) range n ::-1 -1 if i >= j: continue
         i >= j i j if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1
        else:
            dp[i][j] = 0 s[i] == s[j] s[i] s i s[j] s j dp[i][j] = dp[i+1][j+1] + 1 dp[i][j] [i] dp i j dp[i+1][j+1] + 1 dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 1 dp[i][j] = 0 dp[i][j] [i] dp i j 0 for i in range(n):
    for j in range(n):
        tmp = min(j-i, dp[i][j])
        res = max(res, tmp) i range(n) range n for j in range(n):
        tmp = min(j-i, dp[i][j])
        res = max(res, tmp) j range(n) range n tmp = min(j-i, dp[i][j]) tmp min(j-i, dp[i][j]) min j-i j i dp[i][j] [i] dp i j res = max(res, tmp) res max(res, tmp) max res tmp print(res) print res dp = [[0 for i in range(n+5)] for j in range(n+5)] [[0 for i in range(n+5)] for j in range(n+5)] dp tmp = min(j-i, dp[i][j]) min(j-i, dp[i][j]) tmp mod = 10**9+7 10**9+7 mod def inp(): return int(sys.stdin.readline()) def inp(): return int(sys.stdin.readline()) inp n = inp() inp() n res = max(res, tmp) max(res, tmp) res res = 0 0 res s = input() input() s INF = float('inf') float('inf') INF def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl(): return list(map(int, sys.stdin.readline().split())) inpl
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
s = input()
dp = [[0 for i in range(n+5)] for j in range(n+5)]
res = 0
for i in range(n)[::-1]:
    for j in range(n)[::-1]:
        if i >= j: continue
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1
        else:
            dp[i][j] = 0
for i in range(n):
    for j in range(n):
        tmp = min(j-i, dp[i][j])
        res = max(res, tmp)
print(res)