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

def search(n):
    if n == 0:
        return False
    for i in range(N-n):
        if i <= n:
            if S[i:i+n] in S[i+n:]:
                return True
        else:
            if S[i:i+n] in S[:i] + "|" + S[i+n:]:
                return True
    return False

l = 1
r = N//2+1

while l<r:
    mid = (l+r)//2
    if search(mid):
        l = mid+1
    else:
        r = mid

print(l-1)


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

maxL = 0

for i in range(1, N-1):
    cnt = 0
    left = 0
    for j in range(0, N-i):
        if S[j]==S[j+i]:
            cnt+=1
            if maxL < cnt:
                maxL = cnt
            if cnt == i:
                break
        else:
            cnt = 0
            left = j + 1

print(maxL)

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

def search(n):
    if n == 0:
        return False
    for i in range(N-n):
        if S[i:i+n] in S[:i] + "|" + S[i+n:]:
            return True
    return False

l = 1
r = N//2+1

while l<r:
    mid = (l+r)//2
    if search(mid):
        l = mid+1
    else:
        r = mid

print(l-1)


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

maxL = 0

for i in range(1, N-1):
    cnt = 0
    left = 0
    for j in range(0, N-i):
        if S[j]==S[j+i]:
            cnt+=1
            if maxL < cnt:
                maxL = cnt
            if cnt == i:
                break
        else:
            cnt = 0
            left = j + 1

print(maxL)

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

maxL = 0

for i in range(1, N-1):
    cnt = 0
    left = 0
    for j in range(0, N-i):
        if S[j]==S[j+i]:
            cnt+=1
            if maxL < cnt:
                maxL = cnt
            if cnt == i:
                break
        else:
            cnt = 0
            left = j + 1

print(maxL)

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

maxL = 0

for i in range(1, N-1):
    cnt = 0
    left = 0
    for j in range(0, N-i):
        if S[j]==S[j+i]:
            cnt+=1
            if maxL < cnt:
                maxL = cnt
            if cnt == i:
                break
        else:
            cnt = 0
            left = j + 1

print(maxL)

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

def search(n):
    if n == 0:
        return False
    for i in range(N):
        for j in range(i+n, N):
            if j+n <= N:
                if S[i:i+n] == S[j:j+n]:
                    return True
    return False

l = 1
r = N//2+1

while l<r:
    mid = (l+r)//2
    if search(mid):
        l = mid+1
    else:
        r = mid

print(l-1)


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

maxL = 0

for i in range(1, N-1):
    cnt = 0
    left = 0
    for j in range(0, N-i):
        if S[j]==S[j+i]:
            cnt+=1
            if maxL < cnt:
                maxL = cnt
            if cnt == i:
                break
        else:
            cnt = 0
            left = j + 1

print(maxL)

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

def lcs(a, b):
    L = []
    for bk in b:
        bgn_idx = 0
        for i, cur_idx in enumerate(L):
            chr_idx = a.find(bk, bgn_idx) + 1
            if not chr_idx:
                break
            L[i] = min(cur_idx, chr_idx)
            bgn_idx = cur_idx
        else:
            chr_idx = a.find(bk, bgn_idx) + 1
            if chr_idx:
                L.append(chr_idx)
    return len(L)

ans = 0
for i in range(N):
    ans = max(ans, lcs(S[:i+1], S[i+1:]))

print(ans)


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

maxL = 0

for i in range(1, N-1):
    cnt = 0
    left = 0
    for j in range(0, N-i):
        if S[j]==S[j+i]:
            cnt+=1
            if maxL < cnt:
                maxL = cnt
            if cnt == i:
                break
        else:
            cnt = 0
            left = j + 1

print(maxL)

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

def lcs(a, b):
    L = []
    for bk in b:
        bgn_idx = 0
        for i, cur_idx in enumerate(L):
            chr_idx = a.find(bk, bgn_idx) + 1
            if not chr_idx:
                break
            L[i] = min(cur_idx, chr_idx)
            bgn_idx = cur_idx
        else:
            chr_idx = a.find(bk, bgn_idx) + 1
            if chr_idx:
                L.append(chr_idx)
    return len(L)

ans = 0
for i in range(N):
    ans = max(ans, lcs(S[:i+1], S[i+1:]))

print(ans)


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

maxL = 0

for i in range(1, N-1):
    cnt = 0
    left = 0
    for j in range(0, N-i):
        if S[j]==S[j+i]:
            cnt+=1
            if maxL < cnt:
                maxL = cnt
            if cnt == i:
                break
        else:
            cnt = 0
            left = j + 1

print(maxL)