Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    N = int(input())
    Ss = input().rstrip()

    dp = [[0]*(N+1) for _ in range(N+1)]
    for i in reversed(range(N)):
        for j in reversed(range(N)):
            if Ss[i] == Ss[j]:
                dp[i][j] = dp[i+1][j+1] + 1
            else:
                dp[i][j] = 0

    ans = 0
    for i in range(N):
        for j in range(N):
            L = j-i if j-i <= dp[i][j] else dp[i][j]
            if L > ans:
                ans = L

    print(ans)


solve()


Fixed submission:
N = int(input())
Ss = input()

def isOK(k):
    strAs = ['' for _ in range(N)]
    strBs = ['' for _ in range(N)]
    for L in range(N-k+1):
        R = L+k-1
        ss = Ss[L:R+1]
        strAs[R] = ss
        strBs[L] = ss

    strCands = set()
    for iEn in range(N-1):
        if strAs[iEn] != '':
            strCands.add(strAs[iEn])
        if strBs[iEn+1] != '' and strBs[iEn+1] in strCands:
            return True

    return False


ng, ok = N//2 + 1, 0
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    N = int(input())
    Ss = input().rstrip()

    for L in reversed(range(1, N//2+1)):
        setCand = set()
        RHs = []
        for i in range(N-L+1):
            if i <= N-2*L or L <= i:
                RH = hash(Ss[i:i+L])
            if i <= N-2*L:
                RHs.append(RH)
            if L <= i:
                setCand.add(RHs[i-L])
                if RH in setCand:
                    print(L)
                    break
        else:
            continue
        break
    else:
        print(0)


solve()


Fixed submission:
N = int(input())
Ss = input()

def isOK(k):
    strAs = ['' for _ in range(N)]
    strBs = ['' for _ in range(N)]
    for L in range(N-k+1):
        R = L+k-1
        ss = Ss[L:R+1]
        strAs[R] = ss
        strBs[L] = ss

    strCands = set()
    for iEn in range(N-1):
        if strAs[iEn] != '':
            strCands.add(strAs[iEn])
        if strBs[iEn+1] != '' and strBs[iEn+1] in strCands:
            return True

    return False


ng, ok = N//2 + 1, 0
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    N = int(input())
    Ss = input().rstrip()

    for L in reversed(range(1, N//2+1)):
        setCand = set()
        RHs = []
        for i in range(N-L+1):
            if i <= N-2*L or L <= i:
                RH = hash(Ss[i:i+L])
            if i <= N-2*L:
                RHs.append(RH)
            if L <= i:
                setCand.add(RHs[i-L])
                if RH in setCand:
                    print(L)
                    break
        else:
            continue
        break
    else:
        print(0)


solve()


Fixed submission:
N = int(input())
Ss = input()

def isOK(k):
    strAs = ['' for _ in range(N)]
    strBs = ['' for _ in range(N)]
    for L in range(N-k+1):
        R = L+k-1
        ss = Ss[L:R+1]
        strAs[R] = ss
        strBs[L] = ss

    strCands = set()
    for iEn in range(N-1):
        if strAs[iEn] != '':
            strCands.add(strAs[iEn])
        if strBs[iEn+1] != '' and strBs[iEn+1] in strCands:
            return True

    return False


ng, ok = N//2 + 1, 0
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    N = int(input())
    Ss = input().rstrip()

    for L in reversed(range(1, N//2+1)):
        setCand = set()
        RHs = []
        for i in range(N-L+1):
            RH = hash(Ss[i:i+L])
            RHs.append(RH)
            if i-L >= 0:
                setCand.add(RHs[i-L])
            if RH in setCand:
                print(L)
                break
        else:
            continue
        break
    else:
        print(0)


solve()


Fixed submission:
N = int(input())
Ss = input()

def isOK(k):
    strAs = ['' for _ in range(N)]
    strBs = ['' for _ in range(N)]
    for L in range(N-k+1):
        R = L+k-1
        ss = Ss[L:R+1]
        strAs[R] = ss
        strBs[L] = ss

    strCands = set()
    for iEn in range(N-1):
        if strAs[iEn] != '':
            strCands.add(strAs[iEn])
        if strBs[iEn+1] != '' and strBs[iEn+1] in strCands:
            return True

    return False


ng, ok = N//2 + 1, 0
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    BASE = 10**9 + 7
    MOD = 2**61 - 1  # メルセンヌ素数
    ordA = ord('a')

    N = int(input())
    Ss = input().rstrip()

    As = [ord(S)-ordA for S in Ss]

    def genRollingHash_AllRight(As, lenInit, BASE, MOD):
        hashA = 0
        for A in As[:lenInit]:
            hashA = (hashA*BASE + A) % MOD
        yield hashA

        powB_L = pow(BASE, lenInit, MOD)
        for Aadd, Asub in zip(As[lenInit:], As[:len(As)-lenInit]):
            hashA = (hashA*BASE + Aadd - Asub*powB_L) % MOD
            yield hashA

    for L in reversed(range(1, N//2+1)):
        setCand = set()
        RHs = []
        for i, RH in enumerate(genRollingHash_AllRight(As, L, BASE, MOD)):
            RHs.append(RH)
            if i-L >= 0:
                setCand.add(RHs[i-L])
            if RH in setCand:
                print(L)
                break
        else:
            continue
        break
    else:
        print(0)


solve()


Fixed submission:
N = int(input())
Ss = input()

def isOK(k):
    strAs = ['' for _ in range(N)]
    strBs = ['' for _ in range(N)]
    for L in range(N-k+1):
        R = L+k-1
        ss = Ss[L:R+1]
        strAs[R] = ss
        strBs[L] = ss

    strCands = set()
    for iEn in range(N-1):
        if strAs[iEn] != '':
            strCands.add(strAs[iEn])
        if strBs[iEn+1] != '' and strBs[iEn+1] in strCands:
            return True

    return False


ng, ok = N//2 + 1, 0
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Ss = input()

def getZArray(Ss):
    lenS = len(Ss)
    As = [lenS] * lenS
    i, j = 1, 0
    while i < lenS:
        while i+j < lenS and Ss[j] == Ss[i+j]:
            j += 1
        As[i] = j
        if j == 0:
            i += 1
        else:
            k = 1
            while i+k < lenS and k+As[k] < j:
                As[i+k] = As[k]
                k += 1
            i += k
            j -= k
    return As

ans = 0
for i in range(N):
    ZArray = getZArray(Ss[i:])
    for i, Z in enumerate(ZArray):
        L = min(Z, i)
        ans = max(ans, L)

print(ans)


Fixed submission:
N = int(input())
Ss = input()

def isOK(k):
    strAs = ['' for _ in range(N)]
    strBs = ['' for _ in range(N)]
    for L in range(N-k+1):
        R = L+k-1
        ss = Ss[L:R+1]
        strAs[R] = ss
        strBs[L] = ss

    strCands = set()
    for iEn in range(N-1):
        if strAs[iEn] != '':
            strCands.add(strAs[iEn])
        if strBs[iEn+1] != '' and strBs[iEn+1] in strCands:
            return True

    return False


ng, ok = N//2 + 1, 0
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    N = int(input())
    Ss = input()

    for k in reversed(range(1, N//2+1)):
        strs = []
        for L in range(N-k+1):
            R = L+k-1
            ss = Ss[L:R+1]
            strs.append((ss, L, R))

        ds = dict()
        for ss, L, R in strs:
            if ss not in ds:
                ds[ss] = [(L, R)]
            else:
                ds[ss] += [(L, R)]

        for ss, LRs in ds.items():
            maxL = -1
            minR = N
            for L, R in LRs:
                if L > maxL:
                    maxL = L
                if R < minR:
                    minR = R
            if minR+1 <= maxL:
                return k

    return 0

print(solve())


Fixed submission:
N = int(input())
Ss = input()

def isOK(k):
    strAs = ['' for _ in range(N)]
    strBs = ['' for _ in range(N)]
    for L in range(N-k+1):
        R = L+k-1
        ss = Ss[L:R+1]
        strAs[R] = ss
        strBs[L] = ss

    strCands = set()
    for iEn in range(N-1):
        if strAs[iEn] != '':
            strCands.add(strAs[iEn])
        if strBs[iEn+1] != '' and strBs[iEn+1] in strCands:
            return True

    return False


ng, ok = N//2 + 1, 0
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    N = int(input())
    Ss = input()

    for k in reversed(range(1, N//2+1)):
        strs = []
        for L in range(N-k+1):
            R = L+k-1
            ss = Ss[L:R+1]
            strs.append((ss, L, R))

        ds = dict()
        for ss, L, R in strs:
            if ss not in ds:
                ds[ss] = [(L, R)]
            else:
                ds[ss] += [(L, R)]

        for ss, LRs in ds.items():
            maxL = -1
            minR = N
            for L, R in LRs:
                if L > maxL:
                    maxL = L
                if R < minR:
                    minR = R
            if minR+1 <= maxL:
                return k

    return 0

print(solve())


Fixed submission:
N = int(input())
Ss = input()

def isOK(k):
    strAs = ['' for _ in range(N)]
    strBs = ['' for _ in range(N)]
    for L in range(N-k+1):
        R = L+k-1
        ss = Ss[L:R+1]
        strAs[R] = ss
        strBs[L] = ss

    strCands = set()
    for iEn in range(N-1):
        if strAs[iEn] != '':
            strCands.add(strAs[iEn])
        if strBs[iEn+1] != '' and strBs[iEn+1] in strCands:
            return True

    return False


ng, ok = N//2 + 1, 0
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    N = int(input())
    Ss = input()

    strAs = [set() for _ in range(N)]
    for L in range(N-1):
        maxLen = (N-L)//2
        for R in range(L, L+maxLen):
            ss = Ss[L:R+1]
            strAs[R].add(ss)
    strBs = [set() for _ in range(N)]
    for R in reversed(range(1, N)):
        maxLen = (R+1)//2
        for L in range(R-maxLen+1, R+1):
            ss = Ss[L:R+1]
            strBs[L].add(ss)

    ans = 0
    strCands = set()
    for iEn in range(N-1):
        for strA in strAs[iEn]:
            strCands.add(strA)
        for strB in strBs[iEn+1]:
            if strB in strCands:
                lenB = len(strB)
                if lenB > ans:
                    ans = lenB

    print(ans)

solve()


Fixed submission:
N = int(input())
Ss = input()

def isOK(k):
    strAs = ['' for _ in range(N)]
    strBs = ['' for _ in range(N)]
    for L in range(N-k+1):
        R = L+k-1
        ss = Ss[L:R+1]
        strAs[R] = ss
        strBs[L] = ss

    strCands = set()
    for iEn in range(N-1):
        if strAs[iEn] != '':
            strCands.add(strAs[iEn])
        if strBs[iEn+1] != '' and strBs[iEn+1] in strCands:
            return True

    return False


ng, ok = N//2 + 1, 0
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    N = int(input())
    Ss = input()

    strAs = [set() for _ in range(N)]
    for L in range(N-1):
        maxLen = (N-L)//2
        for R in range(L, L+maxLen):
            ss = Ss[L:R+1]
            strAs[R].add(ss)
    strBs = [set() for _ in range(N)]
    for R in reversed(range(1, N)):
        maxLen = (R+1)//2
        for L in range(R-maxLen+1, R+1):
            ss = Ss[L:R+1]
            strBs[L].add(ss)

    ans = 0
    strCands = set()
    for iEn in range(N-1):
        for strA in strAs[iEn]:
            strCands.add(strA)
        for strB in strBs[iEn+1]:
            if strB in strCands:
                lenB = len(strB)
                if lenB > ans:
                    ans = lenB

    print(ans)

solve()


Fixed submission:
N = int(input())
Ss = input()

def isOK(k):
    strAs = ['' for _ in range(N)]
    strBs = ['' for _ in range(N)]
    for L in range(N-k+1):
        R = L+k-1
        ss = Ss[L:R+1]
        strAs[R] = ss
        strBs[L] = ss

    strCands = set()
    for iEn in range(N-1):
        if strAs[iEn] != '':
            strCands.add(strAs[iEn])
        if strBs[iEn+1] != '' and strBs[iEn+1] in strCands:
            return True

    return False


ng, ok = N//2 + 1, 0
while abs(ok-ng) > 1:
    mid = (ng+ok) // 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

print(ok)