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

ans = 0
i = 0
j = 1
c = 1
while j <= N-c:
    c = 1
    for k in range(j, N):
        cnt = 0
        while k+cnt < N and i+cnt < j and S[i+cnt] == S[k+cnt]:
            cnt += 1
        c = max(c, cnt)
    if j-i > c:
        i += 1
        j = i+c
    else:
        j += 1
    ans = max(c, ans)
    
if N <= 26:
    L = []
    for i in range(N):
        L.append(S[i])
    L = set(L)
    if len(L) == N:
        ans = 0
    
print(ans)

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

def z_algo(S):
    N = len(S)
    Z = [0]*N
    i = 1
    j = 0
    Z[0] = N
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        if j == 0:
            i += 1
            continue
        Z[i] = j
        k = 1
        while i+k < N and k < j-Z[k]:
            Z[i+k] = Z[k]
            k += 1
        i += k
        j -= k
    return Z

ans = 0
l = 0
while l < N:
    temp = S[l:]
    z = z_algo(temp)
    for i in range(1, len(temp)):
        ans = max(ans, min(i, z[i]))
    l += 1
    
print(ans)

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

ans = 0
i = 0
j = 1
c = 0
while j < N:
    c = 0
    for k in range(j, N):
        cnt = 0
        while k+cnt < N and i+cnt < j and S[i+cnt] == S[k+cnt]:
            cnt += 1
        c = max(c, cnt)
    if j-i > c:
        i += 1
        j = i+c
    else:
        j += 1
    ans = max(c, ans)
    
print(ans)

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

def z_algo(S):
    N = len(S)
    Z = [0]*N
    i = 1
    j = 0
    Z[0] = N
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        if j == 0:
            i += 1
            continue
        Z[i] = j
        k = 1
        while i+k < N and k < j-Z[k]:
            Z[i+k] = Z[k]
            k += 1
        i += k
        j -= k
    return Z

ans = 0
l = 0
while l < N:
    temp = S[l:]
    z = z_algo(temp)
    for i in range(1, len(temp)):
        ans = max(ans, min(i, z[i]))
    l += 1
    
print(ans)

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

ans = 0
i = 0
j = 1
while j < N:
    c = 0
    for k in range(j, N):
        cnt = 0
        while k+cnt < N and i+cnt < j and S[i+cnt] == S[k+cnt]:
            cnt += 1
        c = max(c, cnt)
    if j-i > c:
        i += 1
        if i == j:
            j += 1
    else:
        j += 1
    ans = max(c, ans)
    
print(ans)

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

def z_algo(S):
    N = len(S)
    Z = [0]*N
    i = 1
    j = 0
    Z[0] = N
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        if j == 0:
            i += 1
            continue
        Z[i] = j
        k = 1
        while i+k < N and k < j-Z[k]:
            Z[i+k] = Z[k]
            k += 1
        i += k
        j -= k
    return Z

ans = 0
l = 0
while l < N:
    temp = S[l:]
    z = z_algo(temp)
    for i in range(1, len(temp)):
        ans = max(ans, min(i, z[i]))
    l += 1
    
print(ans)

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

ans = 0
i = 0
j = 1
while j < N:
    c = 0
    for k in range(j, N):
        cnt = 0
        while k+cnt < N and i+cnt < j and S[i+cnt] == S[k+cnt]:
            cnt += 1
        c = max(c, cnt)
    if j-i > c:
        i += 1
        if i == j:
            j += 1
    else:
        j += 1
    ans = max(c, ans)
    
print(ans)

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

def z_algo(S):
    N = len(S)
    Z = [0]*N
    i = 1
    j = 0
    Z[0] = N
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        if j == 0:
            i += 1
            continue
        Z[i] = j
        k = 1
        while i+k < N and k < j-Z[k]:
            Z[i+k] = Z[k]
            k += 1
        i += k
        j -= k
    return Z

ans = 0
l = 0
while l < N:
    temp = S[l:]
    z = z_algo(temp)
    for i in range(1, len(temp)):
        ans = max(ans, min(i, z[i]))
    l += 1
    
print(ans)