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

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


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

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

s=[[0]*N for i in range(N)]
k=0
for k in range(N):
  s[k]= [0]*k + z_algo(S[k:])

ans=0
for i in range(N):
  for j in range(i+1,N):
    if s[i][j]+i > j:
      ans = max(ans,j - i)
    else:
      ans=max(s[i][j],ans)
    
print(ans)

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

s=[[0]*N for i in range(N)]
k=0
while(k<N-1):
  i=k+1
  j=0
  while(i<N):
    while(i+j<N and k+j < i):
      if S[i+j]==S[j+k]:
        j+=1
      else:
        break
    s[k][i]=j
    if j == 0:
      i+=1
      continue
    else:
      l = 1
      while(i+l < N and l + s[k][l] < j):
        s[k][i+l]=s[k][l]
        l+=1
      i += l
      j -= l
  k+=1
ans=0
for i in range(N):
  ans=max(ans,max(s[i]))
print(ans)
      
 


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

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

s=[[0]*N for i in range(N)]
k=0
for k in range(N):
  s[k]= [0]*k + z_algo(S[k:])

ans=0
for i in range(N):
  for j in range(i+1,N):
    if s[i][j]+i > j:
      ans = max(ans,j - i)
    else:
      ans=max(s[i][j],ans)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N = int(input())
S = input()
ans = 0
table = collections.defaultdict(list)
for i in range(1, N//2 + 1):
    for j in range(N-i+1):
        table[S[j:j+i]].append(j)

ans = 0
for x in table:
    n = len(x)
    if n <= ans:
        continue
    if table[x][-1] - table[x][0] >= n:
        ans = max(ans, n)

print(ans)


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

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

s=[[0]*N for i in range(N)]
k=0
for k in range(N):
  s[k]= [0]*k + z_algo(S[k:])

ans=0
for i in range(N):
  for j in range(i+1,N):
    if s[i][j]+i > j:
      ans = max(ans,j - i)
    else:
      ans=max(s[i][j],ans)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N = int(input())
S = input()
ans = 0
table = collections.defaultdict(list)
for i in range(1, N//2 + 1):
    for j in range(N-i+1):
        table[S[j:j+i]].append(j)
ans = 0
for x in table:
    n = len(x)
    if table[x][-1] - table[x][0] >= n:
        ans = max(ans, n)

print(ans)


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

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

s=[[0]*N for i in range(N)]
k=0
for k in range(N):
  s[k]= [0]*k + z_algo(S[k:])

ans=0
for i in range(N):
  for j in range(i+1,N):
    if s[i][j]+i > j:
      ans = max(ans,j - i)
    else:
      ans=max(s[i][j],ans)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = 0
for i in range(N):
    for j in reversed(range(i + 1, (N // 2) + 1)):
        k = S[i:j+1]
        if k in S[:i]:
            if len(k) > ans:
                ans = len(k)
        if k in S[j+1:]:
            if len(k) > ans:
                ans = len(k)
print(ans)


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

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

s=[[0]*N for i in range(N)]
k=0
for k in range(N):
  s[k]= [0]*k + z_algo(S[k:])

ans=0
for i in range(N):
  for j in range(i+1,N):
    if s[i][j]+i > j:
      ans = max(ans,j - i)
    else:
      ans=max(s[i][j],ans)
    
print(ans)