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


class RollingHash:
    base1 = 1007
    base2 = 2009
    mod1 = 10 ** 9 + 7
    mod2 = 10 ** 9 + 9
    
    def __init__(self, s):
        self.s = s
        
        n = len(s)
        self.hash1 = [0] * (n + 1)
        self.hash2 = [0] * (n + 1)
        self.power1 = [1] * (n + 1)
        self.power2 = [1] * (n + 1)
        for i in range(n):
            self.hash1[i + 1] = (self.hash1[i] * self.base1 + ord(s[i])) % self.mod1
            self.hash2[i + 1] = (self.hash2[i] * self.base2 + ord(s[i])) % self.mod2
            self.power1[i + 1] = (self.power1[i] * self.base1) % self.mod1
            self.power2[i + 1] = (self.power2[i] * self.base2) % self.mod2
            
    def get_hash(self, l, r):
        """Gets hash of S[left:right]"""
        res1 = self.hash1[r] - self.hash1[l] * self.power1[r - l] % self.mod1
        if res1 < 0:
            res1 += self.mod1
        res2 = self.hash2[r] - self.hash2[l] * self.power2[r - l] % self.mod2
        if res2 < 0:
            res2 += self.mod2
            
        return (res1, res2)
    
    def get_lcp(self, a, b):
        """Gets lcp of S[a:] and S[b:]"""
        low = 0
        high = min(len(self.hash1) - a, len(self.hash1) - b)
        
        while high - low > 1:
            mid = (low + high) >> 1
            if self.get_hash(a, a + mid) != self.get_hash(b, b + mid):
                high = mid
            else:
                low = mid
                
        return low


def check(d):
    ctr = {}
    for i in range(N - d + 1):
        p = rh.get_hash(i, i + d)
        if p in ctr:
            if i - ctr[p] >= d:
                return True
        else:
            ctr[p] = i
            
    return False


rh = RollingHash(S)
left = 0
right = N // 2 + 1
while right - left > 1:
    mid = (left + right) >> 1
    if check(mid):
        left = mid
    else:
        right = mid

print(left) N = int(input()) N int(input()) int input() input S = input() S input() input class RollingHash:
    base1 = 1007
    base2 = 2009
    mod1 = 10 ** 9 + 7
    mod2 = 10 ** 9 + 9
    
    def __init__(self, s):
        self.s = s
        
        n = len(s)
        self.hash1 = [0] * (n + 1)
        self.hash2 = [0] * (n + 1)
        self.power1 = [1] * (n + 1)
        self.power2 = [1] * (n + 1)
        for i in range(n):
            self.hash1[i + 1] = (self.hash1[i] * self.base1 + ord(s[i])) % self.mod1
            self.hash2[i + 1] = (self.hash2[i] * self.base2 + ord(s[i])) % self.mod2
            self.power1[i + 1] = (self.power1[i] * self.base1) % self.mod1
            self.power2[i + 1] = (self.power2[i] * self.base2) % self.mod2
            
    def get_hash(self, l, r):
        """Gets hash of S[left:right]"""
        res1 = self.hash1[r] - self.hash1[l] * self.power1[r - l] % self.mod1
        if res1 < 0:
            res1 += self.mod1
        res2 = self.hash2[r] - self.hash2[l] * self.power2[r - l] % self.mod2
        if res2 < 0:
            res2 += self.mod2
            
        return (res1, res2)
    
    def get_lcp(self, a, b):
        """Gets lcp of S[a:] and S[b:]"""
        low = 0
        high = min(len(self.hash1) - a, len(self.hash1) - b)
        
        while high - low > 1:
            mid = (low + high) >> 1
            if self.get_hash(a, a + mid) != self.get_hash(b, b + mid):
                high = mid
            else:
                low = mid
                
        return low RollingHash base1 = 1007 base1 1007 base2 = 2009 base2 2009 mod1 = 10 ** 9 + 7 mod1 10 ** 9 + 7 10 ** 9 10 9 7 mod2 = 10 ** 9 + 9 mod2 10 ** 9 + 9 10 ** 9 10 9 9 def __init__(self, s):
        self.s = s
        
        n = len(s)
        self.hash1 = [0] * (n + 1)
        self.hash2 = [0] * (n + 1)
        self.power1 = [1] * (n + 1)
        self.power2 = [1] * (n + 1)
        for i in range(n):
            self.hash1[i + 1] = (self.hash1[i] * self.base1 + ord(s[i])) % self.mod1
            self.hash2[i + 1] = (self.hash2[i] * self.base2 + ord(s[i])) % self.mod2
            self.power1[i + 1] = (self.power1[i] * self.base1) % self.mod1
            self.power2[i + 1] = (self.power2[i] * self.base2) % self.mod2
            
     __init__ self.s = s self.s self s s n = len(s) n len(s) len s self.hash1 = [0] * (n + 1) self.hash1 self hash1 [0] * (n + 1) [0] 0 n + 1 n 1 self.hash2 = [0] * (n + 1) self.hash2 self hash2 [0] * (n + 1) [0] 0 n + 1 n 1 self.power1 = [1] * (n + 1) self.power1 self power1 [1] * (n + 1) [1] 1 n + 1 n 1 self.power2 = [1] * (n + 1) self.power2 self power2 [1] * (n + 1) [1] 1 n + 1 n 1 for i in range(n):
            self.hash1[i + 1] = (self.hash1[i] * self.base1 + ord(s[i])) % self.mod1
            self.hash2[i + 1] = (self.hash2[i] * self.base2 + ord(s[i])) % self.mod2
            self.power1[i + 1] = (self.power1[i] * self.base1) % self.mod1
            self.power2[i + 1] = (self.power2[i] * self.base2) % self.mod2
            
     i range(n) range n self.hash1[i + 1] = (self.hash1[i] * self.base1 + ord(s[i])) % self.mod1 self.hash1[i + 1] self.hash1 self hash1 i + 1 i 1 (self.hash1[i] * self.base1 + ord(s[i])) % self.mod1 self.hash1[i] * self.base1 + ord(s[i]) self.hash1[i] * self.base1 self.hash1[i] self.hash1 self hash1 i self.base1 self base1 ord(s[i]) ord s[i] s i self.mod1 self mod1 self.hash2[i + 1] = (self.hash2[i] * self.base2 + ord(s[i])) % self.mod2 self.hash2[i + 1] self.hash2 self hash2 i + 1 i 1 (self.hash2[i] * self.base2 + ord(s[i])) % self.mod2 self.hash2[i] * self.base2 + ord(s[i]) self.hash2[i] * self.base2 self.hash2[i] self.hash2 self hash2 i self.base2 self base2 ord(s[i]) ord s[i] s i self.mod2 self mod2 self.power1[i + 1] = (self.power1[i] * self.base1) % self.mod1 self.power1[i + 1] self.power1 self power1 i + 1 i 1 (self.power1[i] * self.base1) % self.mod1 self.power1[i] * self.base1 self.power1[i] self.power1 self power1 i self.base1 self base1 self.mod1 self mod1 self.power2[i + 1] = (self.power2[i] * self.base2) % self.mod2 self.power2[i + 1] self.power2 self power2 i + 1 i 1 (self.power2[i] * self.base2) % self.mod2 self.power2[i] * self.base2 self.power2[i] self.power2 self power2 i self.base2 self base2 self.mod2 self mod2 self self s s def get_hash(self, l, r):
        """Gets hash of S[left:right]"""
        res1 = self.hash1[r] - self.hash1[l] * self.power1[r - l] % self.mod1
        if res1 < 0:
            res1 += self.mod1
        res2 = self.hash2[r] - self.hash2[l] * self.power2[r - l] % self.mod2
        if res2 < 0:
            res2 += self.mod2
            
        return (res1, res2)
    
     get_hash """Gets hash of S[left:right]""" res1 = self.hash1[r] - self.hash1[l] * self.power1[r - l] % self.mod1 res1 self.hash1[r] - self.hash1[l] * self.power1[r - l] % self.mod1 self.hash1[r] self.hash1 self hash1 r self.hash1[l] * self.power1[r - l] % self.mod1 self.hash1[l] * self.power1[r - l] self.hash1[l] self.hash1 self hash1 l self.power1[r - l] self.power1 self power1 r - l r l self.mod1 self mod1 if res1 < 0:
            res1 += self.mod1
         res1 < 0 res1 0 res1 += self.mod1 res1 self.mod1 self mod1 res2 = self.hash2[r] - self.hash2[l] * self.power2[r - l] % self.mod2 res2 self.hash2[r] - self.hash2[l] * self.power2[r - l] % self.mod2 self.hash2[r] self.hash2 self hash2 r self.hash2[l] * self.power2[r - l] % self.mod2 self.hash2[l] * self.power2[r - l] self.hash2[l] self.hash2 self hash2 l self.power2[r - l] self.power2 self power2 r - l r l self.mod2 self mod2 if res2 < 0:
            res2 += self.mod2
            
         res2 < 0 res2 0 res2 += self.mod2 res2 self.mod2 self mod2 return (res1, res2) (res1, res2) res1 res2 self self l l r r def get_lcp(self, a, b):
        """Gets lcp of S[a:] and S[b:]"""
        low = 0
        high = min(len(self.hash1) - a, len(self.hash1) - b)
        
        while high - low > 1:
            mid = (low + high) >> 1
            if self.get_hash(a, a + mid) != self.get_hash(b, b + mid):
                high = mid
            else:
                low = mid
                
        return low get_lcp """Gets lcp of S[a:] and S[b:]""" low = 0 low 0 high = min(len(self.hash1) - a, len(self.hash1) - b) high min(len(self.hash1) - a, len(self.hash1) - b) min len(self.hash1) - a len(self.hash1) len self.hash1 self hash1 a len(self.hash1) - b len(self.hash1) len self.hash1 self hash1 b while high - low > 1:
            mid = (low + high) >> 1
            if self.get_hash(a, a + mid) != self.get_hash(b, b + mid):
                high = mid
            else:
                low = mid
                
         high - low > 1 high - low high low 1 mid = (low + high) >> 1 mid (low + high) >> 1 low + high low high 1 if self.get_hash(a, a + mid) != self.get_hash(b, b + mid):
                high = mid
            else:
                low = mid
                
         self.get_hash(a, a + mid) != self.get_hash(b, b + mid) self.get_hash(a, a + mid) self.get_hash self get_hash a a + mid a mid self.get_hash(b, b + mid) self.get_hash self get_hash b b + mid b mid high = mid high mid low = mid low mid return low low self self a a b b def check(d):
    ctr = {}
    for i in range(N - d + 1):
        p = rh.get_hash(i, i + d)
        if p in ctr:
            if i - ctr[p] >= d:
                return True
        else:
            ctr[p] = i
            
    return False check ctr = {} ctr {} for i in range(N - d + 1):
        p = rh.get_hash(i, i + d)
        if p in ctr:
            if i - ctr[p] >= d:
                return True
        else:
            ctr[p] = i
            
     i range(N - d + 1) range N - d + 1 N - d N d 1 p = rh.get_hash(i, i + d) p rh.get_hash(i, i + d) rh.get_hash rh get_hash i i + d i d if p in ctr:
            if i - ctr[p] >= d:
                return True
        else:
            ctr[p] = i
            
     p in ctr p ctr if i - ctr[p] >= d:
                return True
         i - ctr[p] >= d i - ctr[p] i ctr[p] ctr p d return True True ctr[p] = i ctr[p] ctr p i return False False d d rh = RollingHash(S) rh RollingHash(S) RollingHash S left = 0 left 0 right = N // 2 + 1 right N // 2 + 1 N // 2 N 2 1 while right - left > 1:
    mid = (left + right) >> 1
    if check(mid):
        left = mid
    else:
        right = mid right - left > 1 right - left right left 1 mid = (left + right) >> 1 mid (left + right) >> 1 left + right left right 1 if check(mid):
        left = mid
    else:
        right = mid check(mid) check mid left = mid left mid right = mid right mid print(left) print left right = N // 2 + 1 N // 2 + 1 right S = input() input() S left = mid mid left mid = (left + right) >> 1 (left + right) >> 1 mid right = mid mid right left = 0 0 left rh = RollingHash(S) RollingHash(S) rh N = int(input()) int(input()) N def check(d):
    ctr = {}
    for i in range(N - d + 1):
        p = rh.get_hash(i, i + d)
        if p in ctr:
            if i - ctr[p] >= d:
                return True
        else:
            ctr[p] = i
            
    return False def check(d):
    ctr = {}
    for i in range(N - d + 1):
        p = rh.get_hash(i, i + d)
        if p in ctr:
            if i - ctr[p] >= d:
                return True
        else:
            ctr[p] = i
            
    return False check class RollingHash:
    base1 = 1007
    base2 = 2009
    mod1 = 10 ** 9 + 7
    mod2 = 10 ** 9 + 9
    
    def __init__(self, s):
        self.s = s
        
        n = len(s)
        self.hash1 = [0] * (n + 1)
        self.hash2 = [0] * (n + 1)
        self.power1 = [1] * (n + 1)
        self.power2 = [1] * (n + 1)
        for i in range(n):
            self.hash1[i + 1] = (self.hash1[i] * self.base1 + ord(s[i])) % self.mod1
            self.hash2[i + 1] = (self.hash2[i] * self.base2 + ord(s[i])) % self.mod2
            self.power1[i + 1] = (self.power1[i] * self.base1) % self.mod1
            self.power2[i + 1] = (self.power2[i] * self.base2) % self.mod2
            
    def get_hash(self, l, r):
        """Gets hash of S[left:right]"""
        res1 = self.hash1[r] - self.hash1[l] * self.power1[r - l] % self.mod1
        if res1 < 0:
            res1 += self.mod1
        res2 = self.hash2[r] - self.hash2[l] * self.power2[r - l] % self.mod2
        if res2 < 0:
            res2 += self.mod2
            
        return (res1, res2)
    
    def get_lcp(self, a, b):
        """Gets lcp of S[a:] and S[b:]"""
        low = 0
        high = min(len(self.hash1) - a, len(self.hash1) - b)
        
        while high - low > 1:
            mid = (low + high) >> 1
            if self.get_hash(a, a + mid) != self.get_hash(b, b + mid):
                high = mid
            else:
                low = mid
                
        return low class RollingHash:
    base1 = 1007
    base2 = 2009
    mod1 = 10 ** 9 + 7
    mod2 = 10 ** 9 + 9
    
    def __init__(self, s):
        self.s = s
        
        n = len(s)
        self.hash1 = [0] * (n + 1)
        self.hash2 = [0] * (n + 1)
        self.power1 = [1] * (n + 1)
        self.power2 = [1] * (n + 1)
        for i in range(n):
            self.hash1[i + 1] = (self.hash1[i] * self.base1 + ord(s[i])) % self.mod1
            self.hash2[i + 1] = (self.hash2[i] * self.base2 + ord(s[i])) % self.mod2
            self.power1[i + 1] = (self.power1[i] * self.base1) % self.mod1
            self.power2[i + 1] = (self.power2[i] * self.base2) % self.mod2
            
    def get_hash(self, l, r):
        """Gets hash of S[left:right]"""
        res1 = self.hash1[r] - self.hash1[l] * self.power1[r - l] % self.mod1
        if res1 < 0:
            res1 += self.mod1
        res2 = self.hash2[r] - self.hash2[l] * self.power2[r - l] % self.mod2
        if res2 < 0:
            res2 += self.mod2
            
        return (res1, res2)
    
    def get_lcp(self, a, b):
        """Gets lcp of S[a:] and S[b:]"""
        low = 0
        high = min(len(self.hash1) - a, len(self.hash1) - b)
        
        while high - low > 1:
            mid = (low + high) >> 1
            if self.get_hash(a, a + mid) != self.get_hash(b, b + mid):
                high = mid
            else:
                low = mid
                
        return low RollingHash
N = int(input())
S = input()


class RollingHash:
    base1 = 1007
    base2 = 2009
    mod1 = 10 ** 9 + 7
    mod2 = 10 ** 9 + 9
    
    def __init__(self, s):
        self.s = s
        
        n = len(s)
        self.hash1 = [0] * (n + 1)
        self.hash2 = [0] * (n + 1)
        self.power1 = [1] * (n + 1)
        self.power2 = [1] * (n + 1)
        for i in range(n):
            self.hash1[i + 1] = (self.hash1[i] * self.base1 + ord(s[i])) % self.mod1
            self.hash2[i + 1] = (self.hash2[i] * self.base2 + ord(s[i])) % self.mod2
            self.power1[i + 1] = (self.power1[i] * self.base1) % self.mod1
            self.power2[i + 1] = (self.power2[i] * self.base2) % self.mod2
            
    def get_hash(self, l, r):
        """Gets hash of S[left:right]"""
        res1 = self.hash1[r] - self.hash1[l] * self.power1[r - l] % self.mod1
        if res1 < 0:
            res1 += self.mod1
        res2 = self.hash2[r] - self.hash2[l] * self.power2[r - l] % self.mod2
        if res2 < 0:
            res2 += self.mod2
            
        return (res1, res2)
    
    def get_lcp(self, a, b):
        """Gets lcp of S[a:] and S[b:]"""
        low = 0
        high = min(len(self.hash1) - a, len(self.hash1) - b)
        
        while high - low > 1:
            mid = (low + high) >> 1
            if self.get_hash(a, a + mid) != self.get_hash(b, b + mid):
                high = mid
            else:
                low = mid
                
        return low


def check(d):
    ctr = {}
    for i in range(N - d + 1):
        p = rh.get_hash(i, i + d)
        if p in ctr:
            if i - ctr[p] >= d:
                return True
        else:
            ctr[p] = i
            
    return False


rh = RollingHash(S)
left = 0
right = N // 2 + 1
while right - left > 1:
    mid = (left + right) >> 1
    if check(mid):
        left = mid
    else:
        right = mid

print(left)
