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

def Z_algo(string):
    n = len(string)
    A = [0] * n
    A[0] = n
    i = 1
    j = 0
    while i < n:
        while i+j < n and string[j] == string[i+j]:
            j += 1
        A[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < n and k+A[k] < j:
            A[i+k] = A[k]
            k += 1
        i += k
        j -= k
    return A

ans = 0

for i in range(N):
    A = Z_algo(S[i:])
    res = 0
    for j, a in enumerate(A):
        res = max(res, min(a, j))
    ans = max(ans, res)
    
print(ans)

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

dp = [[0] * (N+1) for _ in range(N+1)]

for i in range(N-2, -1, -1):
    for j in range(N-1, i, -1):
        if S[i] == S[j]:
            dp[i][j] = min(dp[i+1][j+1] + 1, j-i)
        else:
            dp[i][j] = 0

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

print(ans)

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

dp = [[0] * (N+1) for _ in range(N+1)]
for i in range(N):
    dp[i][i] = 0
for i in range(N-1):
    if S[i] == S[N-1]:
        dp[i][N-1] = 1

for i in range(N-2, -1, -1):
    for j in range(N-1, i, -1):
        if S[i] == S[j] and i + dp[i+1][j+1] < j:
            dp[i][j] = max(dp[i][j], dp[i+1][j+1] + 1, dp[i+1][j], dp[i][j+1])
        else:
            dp[i][j] = max(dp[i][j], dp[i+1][j], dp[i][j+1])
    
ans = max(dp[i][j] for i in range(N) for j in range(N))
print(ans)

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

dp = [[0] * (N+1) for _ in range(N+1)]

for i in range(N-2, -1, -1):
    for j in range(N-1, i, -1):
        if S[i] == S[j]:
            dp[i][j] = min(dp[i+1][j+1] + 1, j-i)
        else:
            dp[i][j] = 0

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

print(ans)

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

dp = [[-1] * N for _ in range(N)]
for i in range(N):
    dp[i][i] = 0
for i in range(N-1):
    if S[i] == S[N-1]:
        dp[i][N-1] = 1

d = [(-1,-1), (-1, 0), (0, -1)]

for i in range(N-1, -1, -1):
    for j in range(N-1, i-1, -1):
        for di, dj in d:
            ni = i + di
            nj = j + dj
            if not(0 <= ni < nj < N):
                continue
            if (di, dj) == (-1, -1) and S[ni] == S[nj] and ni + dp[i][j] < nj:
                dp[ni][nj] = max(dp[ni][nj], dp[i][j] + 1)
            else:
                dp[ni][nj] = max(dp[ni][nj], dp[i][j])

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

print(ans)

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

dp = [[0] * (N+1) for _ in range(N+1)]

for i in range(N-2, -1, -1):
    for j in range(N-1, i, -1):
        if S[i] == S[j]:
            dp[i][j] = min(dp[i+1][j+1] + 1, j-i)
        else:
            dp[i][j] = 0

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)

inf = float('inf')

N = int(input())
S = input()

dp = [[-inf] * N for _ in range(N)]

def rec(i, j):
    if not (0 <= i < j < N):
        return 0
    if dp[i][j] != -inf:
        return dp[i][j]
    res = 0
    if S[i] == S[j] and i + rec(i+1, j+1) < j:
        res = max(res, rec(i+1, j+1) + 1, rec(i+1, j), rec(i, j+1))
    else:
        res = max(res, rec(i+1, j), rec(i+1, j))
    dp[i][j] = res
    return res

ans = 0

for i in range(N):
    for j in range(i+1, N):
        ans = max(ans, rec(i, j))

print(ans)

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

dp = [[0] * (N+1) for _ in range(N+1)]

for i in range(N-2, -1, -1):
    for j in range(N-1, i, -1):
        if S[i] == S[j]:
            dp[i][j] = min(dp[i+1][j+1] + 1, j-i)
        else:
            dp[i][j] = 0

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

print(ans)

Buggy python submission (verdict: Runtime Error):
inf = float('inf')

N = int(input())
S = input()

dp = [[-inf] * N for _ in range(N)]

def rec(i, j):
    if not (0 <= i < j < N):
        return 0
    if dp[i][j] != -inf:
        return dp[i][j]
    res = 0
    if S[i] == S[j] and i + rec(i+1, j+1) < j:
        res = max(res, rec(i+1, j+1) + 1, rec(i+1, j), rec(i, j+1))
    else:
        res = max(res, rec(i+1, j), rec(i+1, j))
    dp[i][j] = res
    return res

ans = 0

for i in range(N):
    for j in range(i+1, N):
        ans = max(ans, rec(i, j))

print(ans)

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

dp = [[0] * (N+1) for _ in range(N+1)]

for i in range(N-2, -1, -1):
    for j in range(N-1, i, -1):
        if S[i] == S[j]:
            dp[i][j] = min(dp[i+1][j+1] + 1, j-i)
        else:
            dp[i][j] = 0

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

print(ans)