from collections import defaultdict

class RollingHash(object):
    def __init__(self, S: str, MOD: int = 10 ** 9 + 7, BASE: int = 10 ** 5 + 7):
        self.S = S
        self.N = N = len(S)
        self.MOD = MOD
        self.BASE = BASE
        
        S_arr = [ord(x) for x in S]
        POWER = [1] * (N + 1)
        HASH  = [0] * (N + 1)
        p, h = 1, 0
        for i in range(N):
            POWER[i + 1] = p = (p * BASE) % MOD
            HASH[i + 1] = h = (h * BASE + S_arr[i]) % MOD
        self.S_arr = S_arr
        self.POWER = POWER
        self.HASH = HASH

    def hash(self, l: int, r: int):
        # get hash for S[l:r]
        _hash = (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD
        return _hash

def main():
    N = int(input())
    S = input()
    MOD = 998244353
    rs = RollingHash(S, MOD=MOD, BASE=37)
    h, p = rs.HASH, rs.POWER

    left, right = 0, N // 2 + 1
    D = [0] * N
    while abs(right - left) > 1:
        mid = (left + right) // 2
        # hash_to_left = defaultdict(list)
        hashes = set()
        L = mid
        P = p[L]
        for i in range(min(L, N-2*L+1)):
            D[i] = (h[L+i] - h[i]*P) % MOD
        hashes = set()
        ok = False
        for i in range(L, N-L+1):
            hashes.add(D[i-L])
            D[i] = v = (h[L+i] - h[i]*P) % MOD
            if v in hashes:
                ok = True
                break
        if ok:
            left = mid
        else:
            right = mid

    print(left)

if __name__ == '__main__':
    main() from collections import defaultdict class RollingHash(object):
    def __init__(self, S: str, MOD: int = 10 ** 9 + 7, BASE: int = 10 ** 5 + 7):
        self.S = S
        self.N = N = len(S)
        self.MOD = MOD
        self.BASE = BASE
        
        S_arr = [ord(x) for x in S]
        POWER = [1] * (N + 1)
        HASH  = [0] * (N + 1)
        p, h = 1, 0
        for i in range(N):
            POWER[i + 1] = p = (p * BASE) % MOD
            HASH[i + 1] = h = (h * BASE + S_arr[i]) % MOD
        self.S_arr = S_arr
        self.POWER = POWER
        self.HASH = HASH

    def hash(self, l: int, r: int):
        # get hash for S[l:r]
        _hash = (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD
        return _hash RollingHash def __init__(self, S: str, MOD: int = 10 ** 9 + 7, BASE: int = 10 ** 5 + 7):
        self.S = S
        self.N = N = len(S)
        self.MOD = MOD
        self.BASE = BASE
        
        S_arr = [ord(x) for x in S]
        POWER = [1] * (N + 1)
        HASH  = [0] * (N + 1)
        p, h = 1, 0
        for i in range(N):
            POWER[i + 1] = p = (p * BASE) % MOD
            HASH[i + 1] = h = (h * BASE + S_arr[i]) % MOD
        self.S_arr = S_arr
        self.POWER = POWER
        self.HASH = HASH

     __init__ self.S = S self.S self S S self.N = N = len(S) self.N self N len(S) len S = N = len(S) N len(S) self.MOD = MOD self.MOD self MOD MOD self.BASE = BASE self.BASE self BASE BASE ord(x) for x in S for x in S x S for x in S ord(x) ord x S_arr = [ord(x) for x in S] S_arr [ord(x) for x in S] POWER = [1] * (N + 1) POWER [1] * (N + 1) [1] 1 N + 1 N 1 HASH  = [0] * (N + 1) HASH [0] * (N + 1) [0] 0 N + 1 N 1 p, h = 1, 0 p 1 h 0 for i in range(N):
            POWER[i + 1] = p = (p * BASE) % MOD
            HASH[i + 1] = h = (h * BASE + S_arr[i]) % MOD
         i range(N) range N POWER[i + 1] = p = (p * BASE) % MOD POWER[i + 1] POWER i + 1 i 1 (p * BASE) % MOD p * BASE p BASE MOD = p = (p * BASE) % MOD p (p * BASE) % MOD HASH[i + 1] = h = (h * BASE + S_arr[i]) % MOD HASH[i + 1] HASH i + 1 i 1 (h * BASE + S_arr[i]) % MOD h * BASE + S_arr[i] h * BASE h BASE S_arr[i] S_arr i MOD = h = (h * BASE + S_arr[i]) % MOD h (h * BASE + S_arr[i]) % MOD self.S_arr = S_arr self.S_arr self S_arr S_arr self.POWER = POWER self.POWER self POWER POWER self.HASH = HASH self.HASH self HASH HASH self self S: str S MOD: int = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 BASE: int = 10 ** 5 + 7 BASE 10 ** 5 + 7 10 ** 5 10 5 7 def hash(self, l: int, r: int):
        # get hash for S[l:r]
        _hash = (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD
        return _hash hash _hash = (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD _hash (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD self.HASH[r] - self.HASH[l] * self.POWER[r - l] self.HASH[r] self.HASH self HASH r self.HASH[l] * self.POWER[r - l] self.HASH[l] self.HASH self HASH l self.POWER[r - l] self.POWER self POWER r - l r l self.MOD self MOD return _hash _hash self self l: int l r: int r object def main():
    N = int(input())
    S = input()
    MOD = 998244353
    rs = RollingHash(S, MOD=MOD, BASE=37)
    h, p = rs.HASH, rs.POWER

    left, right = 0, N // 2 + 1
    D = [0] * N
    while abs(right - left) > 1:
        mid = (left + right) // 2
        # hash_to_left = defaultdict(list)
        hashes = set()
        L = mid
        P = p[L]
        for i in range(min(L, N-2*L+1)):
            D[i] = (h[L+i] - h[i]*P) % MOD
        hashes = set()
        ok = False
        for i in range(L, N-L+1):
            hashes.add(D[i-L])
            D[i] = v = (h[L+i] - h[i]*P) % MOD
            if v in hashes:
                ok = True
                break
        if ok:
            left = mid
        else:
            right = mid

    print(left) main N = int(input()) N int(input()) int input() input S = input() S input() input MOD = 998244353 MOD 998244353 rs = RollingHash(S, MOD=MOD, BASE=37) rs RollingHash(S, MOD=MOD, BASE=37) RollingHash S MOD=MOD MOD MOD BASE=37 BASE 37 h, p = rs.HASH, rs.POWER h rs.HASH rs HASH p rs.POWER rs POWER left, right = 0, N // 2 + 1 left 0 right N // 2 + 1 N // 2 N 2 1 D = [0] * N D [0] * N [0] 0 N while abs(right - left) > 1:
        mid = (left + right) // 2
        # hash_to_left = defaultdict(list)
        hashes = set()
        L = mid
        P = p[L]
        for i in range(min(L, N-2*L+1)):
            D[i] = (h[L+i] - h[i]*P) % MOD
        hashes = set()
        ok = False
        for i in range(L, N-L+1):
            hashes.add(D[i-L])
            D[i] = v = (h[L+i] - h[i]*P) % MOD
            if v in hashes:
                ok = True
                break
        if ok:
            left = mid
        else:
            right = mid

     abs(right - left) > 1 abs(right - left) abs right - left right left 1 mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 hashes = set() hashes set() set L = mid L mid P = p[L] P p[L] p L for i in range(min(L, N-2*L+1)):
            D[i] = (h[L+i] - h[i]*P) % MOD
         i range(min(L, N-2*L+1)) range min(L, N-2*L+1) min L N-2*L+1 N-2*L N 2*L 2 L 1 D[i] = (h[L+i] - h[i]*P) % MOD D[i] D i (h[L+i] - h[i]*P) % MOD h[L+i] - h[i]*P h[L+i] h L+i L i h[i]*P h[i] h i P MOD hashes = set() hashes set() set ok = False ok False for i in range(L, N-L+1):
            hashes.add(D[i-L])
            D[i] = v = (h[L+i] - h[i]*P) % MOD
            if v in hashes:
                ok = True
                break
         i range(L, N-L+1) range L N-L+1 N-L N L 1 hashes.add(D[i-L]) hashes.add hashes add D[i-L] D i-L i L D[i] = v = (h[L+i] - h[i]*P) % MOD D[i] D i (h[L+i] - h[i]*P) % MOD h[L+i] - h[i]*P h[L+i] h L+i L i h[i]*P h[i] h i P MOD = v = (h[L+i] - h[i]*P) % MOD v (h[L+i] - h[i]*P) % MOD if v in hashes:
                ok = True
                break
         v in hashes v hashes ok = True ok True break if ok:
            left = mid
        else:
            right = mid

     ok left = mid left mid right = mid right mid print(left) print left if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main class RollingHash(object):
    def __init__(self, S: str, MOD: int = 10 ** 9 + 7, BASE: int = 10 ** 5 + 7):
        self.S = S
        self.N = N = len(S)
        self.MOD = MOD
        self.BASE = BASE
        
        S_arr = [ord(x) for x in S]
        POWER = [1] * (N + 1)
        HASH  = [0] * (N + 1)
        p, h = 1, 0
        for i in range(N):
            POWER[i + 1] = p = (p * BASE) % MOD
            HASH[i + 1] = h = (h * BASE + S_arr[i]) % MOD
        self.S_arr = S_arr
        self.POWER = POWER
        self.HASH = HASH

    def hash(self, l: int, r: int):
        # get hash for S[l:r]
        _hash = (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD
        return _hash class RollingHash(object):
    def __init__(self, S: str, MOD: int = 10 ** 9 + 7, BASE: int = 10 ** 5 + 7):
        self.S = S
        self.N = N = len(S)
        self.MOD = MOD
        self.BASE = BASE
        
        S_arr = [ord(x) for x in S]
        POWER = [1] * (N + 1)
        HASH  = [0] * (N + 1)
        p, h = 1, 0
        for i in range(N):
            POWER[i + 1] = p = (p * BASE) % MOD
            HASH[i + 1] = h = (h * BASE + S_arr[i]) % MOD
        self.S_arr = S_arr
        self.POWER = POWER
        self.HASH = HASH

    def hash(self, l: int, r: int):
        # get hash for S[l:r]
        _hash = (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD
        return _hash RollingHash def main():
    N = int(input())
    S = input()
    MOD = 998244353
    rs = RollingHash(S, MOD=MOD, BASE=37)
    h, p = rs.HASH, rs.POWER

    left, right = 0, N // 2 + 1
    D = [0] * N
    while abs(right - left) > 1:
        mid = (left + right) // 2
        # hash_to_left = defaultdict(list)
        hashes = set()
        L = mid
        P = p[L]
        for i in range(min(L, N-2*L+1)):
            D[i] = (h[L+i] - h[i]*P) % MOD
        hashes = set()
        ok = False
        for i in range(L, N-L+1):
            hashes.add(D[i-L])
            D[i] = v = (h[L+i] - h[i]*P) % MOD
            if v in hashes:
                ok = True
                break
        if ok:
            left = mid
        else:
            right = mid

    print(left) def main():
    N = int(input())
    S = input()
    MOD = 998244353
    rs = RollingHash(S, MOD=MOD, BASE=37)
    h, p = rs.HASH, rs.POWER

    left, right = 0, N // 2 + 1
    D = [0] * N
    while abs(right - left) > 1:
        mid = (left + right) // 2
        # hash_to_left = defaultdict(list)
        hashes = set()
        L = mid
        P = p[L]
        for i in range(min(L, N-2*L+1)):
            D[i] = (h[L+i] - h[i]*P) % MOD
        hashes = set()
        ok = False
        for i in range(L, N-L+1):
            hashes.add(D[i-L])
            D[i] = v = (h[L+i] - h[i]*P) % MOD
            if v in hashes:
                ok = True
                break
        if ok:
            left = mid
        else:
            right = mid

    print(left) main
from collections import defaultdict

class RollingHash(object):
    def __init__(self, S: str, MOD: int = 10 ** 9 + 7, BASE: int = 10 ** 5 + 7):
        self.S = S
        self.N = N = len(S)
        self.MOD = MOD
        self.BASE = BASE
        
        S_arr = [ord(x) for x in S]
        POWER = [1] * (N + 1)
        HASH  = [0] * (N + 1)
        p, h = 1, 0
        for i in range(N):
            POWER[i + 1] = p = (p * BASE) % MOD
            HASH[i + 1] = h = (h * BASE + S_arr[i]) % MOD
        self.S_arr = S_arr
        self.POWER = POWER
        self.HASH = HASH

    def hash(self, l: int, r: int):
        # get hash for S[l:r]
        _hash = (self.HASH[r] - self.HASH[l] * self.POWER[r - l]) % self.MOD
        return _hash

def main():
    N = int(input())
    S = input()
    MOD = 998244353
    rs = RollingHash(S, MOD=MOD, BASE=37)
    h, p = rs.HASH, rs.POWER

    left, right = 0, N // 2 + 1
    D = [0] * N
    while abs(right - left) > 1:
        mid = (left + right) // 2
        # hash_to_left = defaultdict(list)
        hashes = set()
        L = mid
        P = p[L]
        for i in range(min(L, N-2*L+1)):
            D[i] = (h[L+i] - h[i]*P) % MOD
        hashes = set()
        ok = False
        for i in range(L, N-L+1):
            hashes.add(D[i-L])
            D[i] = v = (h[L+i] - h[i]*P) % MOD
            if v in hashes:
                ok = True
                break
        if ok:
            left = mid
        else:
            right = mid

    print(left)

if __name__ == '__main__':
    main()