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

    dp = [[0] * (N + 1) for _ in range(N + 1)]
    result = 0
    l = list(range(N - 1, -1, -1))
    for i in l:
        dpi = dp[i]
        dpi1 = dp[i + 1]
        for j in l:
            if S[i] == S[j]:
                t = dpi1[j + 1] + 1
                dpi[j] = t
                ji = j - i
                if t > ji:
                    t = ji
                if t > result:
                    result = t
    print(result)


main()


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

result = 0
for i in range(N - 1, 0, -1):
    if i <= result:
        break
    t = 0
    for j in range(N - i):
        if S[j] == S[j+i]:
            t += 1
            if t > result:
                result = t
            if result == i:
                break
        else:
            t = 0

print(result)

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

result = 0
for i in range(N - 1, 0, -1):
    if i < result:
        break
    t = 0
    for j in range(N - i):
        if S[j] == S[j+i]:
            t += 1
            if t > result:
                result = t
            if t == i:
                break
        else:
            t = 0

print(result)


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

result = 0
for i in range(N - 1, 0, -1):
    if i <= result:
        break
    t = 0
    for j in range(N - i):
        if S[j] == S[j+i]:
            t += 1
            if t > result:
                result = t
            if result == i:
                break
        else:
            t = 0

print(result)

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

ms = 0
for i in range(1, N):
    ts = 0
    for j in range(N - i):
        if S[j] == S[j+i]:
            ts += 1
            if ts > ms:
                ms = ts
            if ts == i:
                break
        else:
            ts = 0
print(ms)


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

result = 0
for i in range(N - 1, 0, -1):
    if i <= result:
        break
    t = 0
    for j in range(N - i):
        if S[j] == S[j+i]:
            t += 1
            if t > result:
                result = t
            if result == i:
                break
        else:
            t = 0

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    S = input()
    dp = [[0] * (N + 1) for _ in range(N + 1)]
    for i in range(N - 1, -1, -1):
        dpi = dp[i]
        dpi1 = dp[i + 1]
        for j in range(N - 1, -1, -1):
            if S[i] != S[j]:
                dpi[j] = 0
            else:
                dpi[j] = dpi1[j + 1] + 1
    result = 0
    for i in range(N):
        dpi = dp[i]
        for j in range(i + 1, N):
            t1 = dpi[j]
            t2 = j - i
            if t1 > t2:
                t1 = t2
            if t1 > result:
                result = t1
    print(result)


main()


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

result = 0
for i in range(N - 1, 0, -1):
    if i <= result:
        break
    t = 0
    for j in range(N - i):
        if S[j] == S[j+i]:
            t += 1
            if t > result:
                result = t
            if result == i:
                break
        else:
            t = 0

print(result)

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 - 1, -1, -1):
    for j in range(N - 1, -1, -1):
        if S[i] != S[j]:
            dp[i][j] = 0
        else:
            dp[i][j] = dp[i + 1][j + 1] + 1
result = 0
for i in range(N):
    for j in range(i + 1, N):
        t = min(dp[i][j], j - i)
        result = max(result, t)
print(result)


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

result = 0
for i in range(N - 1, 0, -1):
    if i <= result:
        break
    t = 0
    for j in range(N - i):
        if S[j] == S[j+i]:
            t += 1
            if t > result:
                result = t
            if result == i:
                break
        else:
            t = 0

print(result)