Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N = int(input())
S = input().strip()
kmax = 0
for k in range(1,N//2+1):
    C = {}
    a = deque(list(S[:k]))
    C[tuple(a)]=[0]
    for i in range(1,N-k+1):
        a.popleft()
        a.append(S[i+k-1])
        if tuple(a) not in C:
            C[tuple(a)] = []
        C[tuple(a)].append(i)
    for a in C:
        if len(C[a])>=2:
            flag = 0
            for i in range(1,len(C[a])):
                if C[a][i]-C[a][i-1]>=k:
                    flag = 1
                    break
            if flag==1:
                kmax = k
                break
print(kmax)

Fixed submission:
N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N):
    X = S[:N-k]
    Y = S[k:]
    cur = 0
    cnt = 0
    for i in range(N-k):
        if X[i]!=Y[i]:
            cmax = max(cmax,min(cnt,k))
            cur = i
            cnt = 0
        else:
            cnt += 1
    cmax = max(cmax,min(cnt,k))
print(cmax)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input().strip()
kmax = 0
for k in range(1,N//2+1):
    C = {}
    for i in range(N-k+1):
        if S[i:i+k] not in C:
            C[S[i:i+k]] = []
        C[S[i:i+k]].append(i)
    for a in C:
        if len(C[a])>=2:
            flag = 0
            for i in range(1,len(C[a])):
                if C[a][i]-C[a][i-1]>=k:
                    flag = 1
                    break
            if flag==1:
                kmax = k
                break
print(kmax)

Fixed submission:
N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N):
    X = S[:N-k]
    Y = S[k:]
    cur = 0
    cnt = 0
    for i in range(N-k):
        if X[i]!=Y[i]:
            cmax = max(cmax,min(cnt,k))
            cur = i
            cnt = 0
        else:
            cnt += 1
    cmax = max(cmax,min(cnt,k))
print(cmax)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N//2+1):
    C = {}
    x = S[:k]
    C[x]=[0]
    for i in range(1,N-k+1):
        x = x[1:]+S[i+k-1]
        if x not in C:
            C[x]=[]
        C[x].append(i)
    for a in C:
        if len(C[a])>1 and C[a][-1]-C[a][0]>=k:
            cmax = max(cmax,k)
            break
print(cmax)

Fixed submission:
N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N):
    X = S[:N-k]
    Y = S[k:]
    cur = 0
    cnt = 0
    for i in range(N-k):
        if X[i]!=Y[i]:
            cmax = max(cmax,min(cnt,k))
            cur = i
            cnt = 0
        else:
            cnt += 1
    cmax = max(cmax,min(cnt,k))
print(cmax)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N//2+1):
    C = {}
    for i in range(N-k+1):
        x = S[i:i+k]
        if x not in C:
            C[x]=[]
        C[x].append(i)
    for a in C:
        if len(C[a])>1 and C[a][-1]-C[a][0]>=k:
            cmax = max(cmax,k)
            break
print(cmax)

Fixed submission:
N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N):
    X = S[:N-k]
    Y = S[k:]
    cur = 0
    cnt = 0
    for i in range(N-k):
        if X[i]!=Y[i]:
            cmax = max(cmax,min(cnt,k))
            cur = i
            cnt = 0
        else:
            cnt += 1
    cmax = max(cmax,min(cnt,k))
print(cmax)

Buggy python submission (verdict: Runtime Error):
= int(input())
S = input().strip()
cmax = 0
for k in range(1,N//2+1):
    C = {}
    x = S[:k]
    C[x]=[0]
    for i in range(1,N-k+1):
        x = x[1:]+S[i+k-1]
        if x not in C:
            C[x]=[]
        C[x].append(i)
    flag = 0
    for a in C:
        if len(C[a])>1:
            if C[a][0]-C[a][-1]>=k:
                cmax = max(cmax,k)
                flag = 1
                break
            if flag==1:break
print(cmax)

Fixed submission:
N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N):
    X = S[:N-k]
    Y = S[k:]
    cur = 0
    cnt = 0
    for i in range(N-k):
        if X[i]!=Y[i]:
            cmax = max(cmax,min(cnt,k))
            cur = i
            cnt = 0
        else:
            cnt += 1
    cmax = max(cmax,min(cnt,k))
print(cmax)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N//2+1):
    C = {}
    x = S[:k]
    C[x]=[0]
    for i in range(1,N-k+1):
        x = x[1:]+S[i+k-1]
        if x not in C:
            C[x]=[]
        C[x].append(i)
    flag = 0
    for a in C:
        if len(C[a])>1:
            for j in range(1,len(C[a])):
                if C[a][j]-C[a][j-1]>=k:
                    cmax = max(cmax,k)
                    flag = 1
                    break
            if flag==1:break
print(cmax)

Fixed submission:
N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N):
    X = S[:N-k]
    Y = S[k:]
    cur = 0
    cnt = 0
    for i in range(N-k):
        if X[i]!=Y[i]:
            cmax = max(cmax,min(cnt,k))
            cur = i
            cnt = 0
        else:
            cnt += 1
    cmax = max(cmax,min(cnt,k))
print(cmax)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N//2+1):
    C = {}
    for i in range(N-k+1):
        if S[i:i+k] not in C:
            C[S[i:i+k]]=[]
        C[S[i:i+k]].append(i)
    flag = 0
    for a in C:
        if len(C[a])>1:
            for j in range(1,len(C[a])):
                if C[a][j]-C[a][j-1]>=k:
                    cmax = max(cmax,k)
                    flag = 1
                    break
            if flag==1:break
print(cmax)

Fixed submission:
N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N):
    X = S[:N-k]
    Y = S[k:]
    cur = 0
    cnt = 0
    for i in range(N-k):
        if X[i]!=Y[i]:
            cmax = max(cmax,min(cnt,k))
            cur = i
            cnt = 0
        else:
            cnt += 1
    cmax = max(cmax,min(cnt,k))
print(cmax)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
N = int(input())
S = input().strip()
G = {chr(i):[] for i in range(97,123)}
for i in range(N):
    G[S[i]].append(i)
cmax = 0
for a in G:
    for x in combinations(G[a],2):
        i,j = x[0],x[1]
        if i>j:
            i,j = j,i
        cnt = 0
        for k in range(j-i):
            if j+k<N and S[i+k] == S[j+k]:
                cnt += 1
            else:break
        cmax = max(cmax,cnt)
        
print(cmax)

Fixed submission:
N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N):
    X = S[:N-k]
    Y = S[k:]
    cur = 0
    cnt = 0
    for i in range(N-k):
        if X[i]!=Y[i]:
            cmax = max(cmax,min(cnt,k))
            cur = i
            cnt = 0
        else:
            cnt += 1
    cmax = max(cmax,min(cnt,k))
print(cmax)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input().strip()
k = 0
D = {chr(i):[] for i in range(97,123)}
D[S[0]].append(0)
for i in range(1,N):
    a = S[i]
    if len(D[a])>0:
        if k==0:
            k += 1
        else:
            for j in D[a]:
                if j-k>=0 and S[j-k:j]==S[i-k:i] and i-j>=k+1:
                    k += 1
                    break
    D[a].append(i)
print(k)

Fixed submission:
N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N):
    X = S[:N-k]
    Y = S[k:]
    cur = 0
    cnt = 0
    for i in range(N-k):
        if X[i]!=Y[i]:
            cmax = max(cmax,min(cnt,k))
            cur = i
            cnt = 0
        else:
            cnt += 1
    cmax = max(cmax,min(cnt,k))
print(cmax)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input().strip()
cnt = 0
for k in range(N//2,0,-1):
    A = []
    for i in range(N-k+1):
        A.append((S[i:i+k],i))
    A = sorted(A,key=lambda x:x[0])
    cur = 0
    for i in range(1,N-k+1):
        if A[i][0]!=A[i-1][0]:
            cur = i
        else:
            if A[i][1]-A[cur][1]>=k:
                cnt = k
                break
            else:
                continue
    if A[N-k][1]-A[cur][1]>=k:
        cnt = k
    if cnt>0:break
print(cnt)

Fixed submission:
N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N):
    X = S[:N-k]
    Y = S[k:]
    cur = 0
    cnt = 0
    for i in range(N-k):
        if X[i]!=Y[i]:
            cmax = max(cmax,min(cnt,k))
            cur = i
            cnt = 0
        else:
            cnt += 1
    cmax = max(cmax,min(cnt,k))
print(cmax)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input().strip()
D = {}
for i in range(N):
    a = S[i]
    if a not in D:
        D[a] = []
    D[a].append(i)
dp = [0 for _ in range(N)]
if S[0]==S[1]:
    dp[1]=1
else:
    dp[1] = 0
for i in range(2,N):
    a = S[i]
    cntmax = 0
    for j in D[a]:
        cnt = 1
        while 1:
            if i-j>=cnt+1 and j-cnt>=0 and S[j-cnt:j+1]==S[i-cnt:i+1]:
#                 print("i,j,cnt={},{},{}".format(i,j,cnt))
                cntmax = max(cntmax,cnt+1)
            else:break
            cnt += 1
    dp[i] = max(dp[i-1],cntmax)
print(dp[N-1])   

Fixed submission:
N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N):
    X = S[:N-k]
    Y = S[k:]
    cur = 0
    cnt = 0
    for i in range(N-k):
        if X[i]!=Y[i]:
            cmax = max(cmax,min(cnt,k))
            cur = i
            cnt = 0
        else:
            cnt += 1
    cmax = max(cmax,min(cnt,k))
print(cmax)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input().strip()
cntmax = 0
for w in range(1,N//2+1):
    D = {}
    for i in range(N-w+1):
        a = S[i:i+w]
        if a not in D:
            D[a] = []
        D[a].append(i)
    for a in D:
        cur = D[a][0]
        cnt = 10**8
        for i in range(1,len(D[a])):
            cnt = min(cnt,D[a][i]-cur)
            cur = D[a][i]
        if 10**8>cnt>=w:
            cntmax=w
print(cntmax)

Fixed submission:
N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N):
    X = S[:N-k]
    Y = S[k:]
    cur = 0
    cnt = 0
    for i in range(N-k):
        if X[i]!=Y[i]:
            cmax = max(cmax,min(cnt,k))
            cur = i
            cnt = 0
        else:
            cnt += 1
    cmax = max(cmax,min(cnt,k))
print(cmax)