#https://tjkendev.github.io/procon-library/python/string/rolling_hash.html
class RollingHash():
    def __init__(self, s, base, mod):
        self.mod = mod
        self.pw = pw = [1]*(len(s)+1)
 
        l = len(s)
        self.h = h = [0]*(l+1)
 
        v = 0
        for i in range(l):
            h[i+1] = v = (v * base + ord(s[i])) % mod
        v = 1
        for i in range(l):
            pw[i+1] = v = v * base % mod
    def get(self, l, r):
        return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod
N=int(input())
S=input()
R1=RollingHash(S,37,10**9+7)
R2=RollingHash(S,29,10**9+9)
ans=0
for ln in range(1,N//2+1):
    D=dict()
    for l in range(N-ln+1):
        tmp=(R1.get(l,l+ln),R2.get(l,l+ln))
        if tmp in D:
            if D[tmp]+ln<=l:
                ans=max(ln,ans)
        else:
            D[tmp]=l
print(ans) class RollingHash():
    def __init__(self, s, base, mod):
        self.mod = mod
        self.pw = pw = [1]*(len(s)+1)
 
        l = len(s)
        self.h = h = [0]*(l+1)
 
        v = 0
        for i in range(l):
            h[i+1] = v = (v * base + ord(s[i])) % mod
        v = 1
        for i in range(l):
            pw[i+1] = v = v * base % mod
    def get(self, l, r):
        return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod RollingHash def __init__(self, s, base, mod):
        self.mod = mod
        self.pw = pw = [1]*(len(s)+1)
 
        l = len(s)
        self.h = h = [0]*(l+1)
 
        v = 0
        for i in range(l):
            h[i+1] = v = (v * base + ord(s[i])) % mod
        v = 1
        for i in range(l):
            pw[i+1] = v = v * base % mod
     __init__ self.mod = mod self.mod self mod mod self.pw = pw = [1]*(len(s)+1) self.pw self pw [1]*(len(s)+1) [1] 1 len(s)+1 len(s) len s 1 = pw = [1]*(len(s)+1) pw [1]*(len(s)+1) l = len(s) l len(s) len s self.h = h = [0]*(l+1) self.h self h [0]*(l+1) [0] 0 l+1 l 1 = h = [0]*(l+1) h [0]*(l+1) v = 0 v 0 for i in range(l):
            h[i+1] = v = (v * base + ord(s[i])) % mod
         i range(l) range l h[i+1] = v = (v * base + ord(s[i])) % mod h[i+1] h i+1 i 1 (v * base + ord(s[i])) % mod v * base + ord(s[i]) v * base v base ord(s[i]) ord s[i] s i mod = v = (v * base + ord(s[i])) % mod v (v * base + ord(s[i])) % mod v = 1 v 1 for i in range(l):
            pw[i+1] = v = v * base % mod
     i range(l) range l pw[i+1] = v = v * base % mod pw[i+1] pw i+1 i 1 v * base % mod v * base v base mod = v = v * base % mod v v * base % mod self self s s base base mod mod def get(self, l, r):
        return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod get return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod self.h[r] - self.h[l] * self.pw[r-l] self.h[r] self.h self h r self.h[l] * self.pw[r-l] self.h[l] self.h self h l self.pw[r-l] self.pw self pw r-l r l self.mod self mod self self l l r r N=int(input()) N int(input()) int input() input S=input() S input() input R1=RollingHash(S,37,10**9+7) R1 RollingHash(S,37,10**9+7) RollingHash S 37 10**9+7 10**9 10 9 7 R2=RollingHash(S,29,10**9+9) R2 RollingHash(S,29,10**9+9) RollingHash S 29 10**9+9 10**9 10 9 9 ans=0 ans 0 for ln in range(1,N//2+1):
    D=dict()
    for l in range(N-ln+1):
        tmp=(R1.get(l,l+ln),R2.get(l,l+ln))
        if tmp in D:
            if D[tmp]+ln<=l:
                ans=max(ln,ans)
        else:
            D[tmp]=l ln range(1,N//2+1) range 1 N//2+1 N//2 N 2 1 D=dict() D dict() dict for l in range(N-ln+1):
        tmp=(R1.get(l,l+ln),R2.get(l,l+ln))
        if tmp in D:
            if D[tmp]+ln<=l:
                ans=max(ln,ans)
        else:
            D[tmp]=l l range(N-ln+1) range N-ln+1 N-ln N ln 1 tmp=(R1.get(l,l+ln),R2.get(l,l+ln)) tmp (R1.get(l,l+ln),R2.get(l,l+ln)) R1.get(l,l+ln) R1.get R1 get l l+ln l ln R2.get(l,l+ln) R2.get R2 get l l+ln l ln if tmp in D:
            if D[tmp]+ln<=l:
                ans=max(ln,ans)
        else:
            D[tmp]=l tmp in D tmp D if D[tmp]+ln<=l:
                ans=max(ln,ans)
         D[tmp]+ln<=l D[tmp]+ln D[tmp] D tmp ln l ans=max(ln,ans) ans max(ln,ans) max ln ans D[tmp]=l D[tmp] D tmp l print(ans) print ans N=int(input()) int(input()) N R1=RollingHash(S,37,10**9+7) RollingHash(S,37,10**9+7) R1 S=input() input() S D=dict() dict() D tmp=(R1.get(l,l+ln),R2.get(l,l+ln)) (R1.get(l,l+ln),R2.get(l,l+ln)) tmp R2=RollingHash(S,29,10**9+9) RollingHash(S,29,10**9+9) R2 class RollingHash():
    def __init__(self, s, base, mod):
        self.mod = mod
        self.pw = pw = [1]*(len(s)+1)
 
        l = len(s)
        self.h = h = [0]*(l+1)
 
        v = 0
        for i in range(l):
            h[i+1] = v = (v * base + ord(s[i])) % mod
        v = 1
        for i in range(l):
            pw[i+1] = v = v * base % mod
    def get(self, l, r):
        return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod class RollingHash():
    def __init__(self, s, base, mod):
        self.mod = mod
        self.pw = pw = [1]*(len(s)+1)
 
        l = len(s)
        self.h = h = [0]*(l+1)
 
        v = 0
        for i in range(l):
            h[i+1] = v = (v * base + ord(s[i])) % mod
        v = 1
        for i in range(l):
            pw[i+1] = v = v * base % mod
    def get(self, l, r):
        return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod RollingHash ans=0 0 ans ans=max(ln,ans) max(ln,ans) ans
#https://tjkendev.github.io/procon-library/python/string/rolling_hash.html
class RollingHash():
    def __init__(self, s, base, mod):
        self.mod = mod
        self.pw = pw = [1]*(len(s)+1)
 
        l = len(s)
        self.h = h = [0]*(l+1)
 
        v = 0
        for i in range(l):
            h[i+1] = v = (v * base + ord(s[i])) % mod
        v = 1
        for i in range(l):
            pw[i+1] = v = v * base % mod
    def get(self, l, r):
        return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod
N=int(input())
S=input()
R1=RollingHash(S,37,10**9+7)
R2=RollingHash(S,29,10**9+9)
ans=0
for ln in range(1,N//2+1):
    D=dict()
    for l in range(N-ln+1):
        tmp=(R1.get(l,l+ln),R2.get(l,l+ln))
        if tmp in D:
            if D[tmp]+ln<=l:
                ans=max(ln,ans)
        else:
            D[tmp]=l
print(ans)
