Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
    N = int(input())
    S = input()

    dp = [[0] * 5005 for i in range(5005)]

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

    print(result)


Fixed submission:
if __name__ == "__main__":
    N = int(input())
    S = input()

    dp = [[0] * 5005 for i in range(5005)]

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

    print(result)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
    N = int(input())
    S = input()

    dp = [[0] * 5005 for i in range(5005)]

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

    print(result)


Fixed submission:
if __name__ == "__main__":
    N = int(input())
    S = input()

    dp = [[0] * 5005 for i in range(5005)]

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

    print(result)

Buggy python submission (verdict: Runtime Error):
if __name__ == "__main__":
    N = int(input())
    S = input()

    dp = [[0] * 5001 for i in range(5001)]

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

    print(result)


Fixed submission:
if __name__ == "__main__":
    N = int(input())
    S = input()

    dp = [[0] * 5005 for i in range(5005)]

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

    print(result)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
    N = int(input())
    S = input()

    min_val = 0
    if N > 26:
        min_val = 1
    elif N >= (26 ** 2 + 1) * 2:
        min_val = 2

    for i in range(N//2, 0, -1):
        if i == min_val:
            print(i)
            exit()
        if N-i*2 == 0:
            tmp = S[i:]
            if tmp.find(S[:i]) != -1:
                print(i)
                exit()
        else:
            for index in range(N-i*2):
                # 仮の文字列の生成
                tmp = S[index+i:]
                if tmp.find(S[index:index+i]) != -1:
                    print(i)
                    exit()

    print('0')


Fixed submission:
if __name__ == "__main__":
    N = int(input())
    S = input()

    dp = [[0] * 5005 for i in range(5005)]

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

    print(result)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
    N = int(input())
    S = input()

    for i in range(N//2, 0, -1):
        if N-i*2 == 0:
            tmp = S[i:]
            if tmp.find(S[:i]) != -1:
                print(i)
                exit()
        else:
            for index in range(N-i*2):
                # 仮の文字列の生成
                tmp = S[index+i:]
                if tmp.find(S[index:index+i]) != -1:
                    print(i)
                    exit()

    print('0')


Fixed submission:
if __name__ == "__main__":
    N = int(input())
    S = input()

    dp = [[0] * 5005 for i in range(5005)]

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

    print(result)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
    N = int(input())
    S = input()

    for i in range(N//2, 0, -1):
        if N-i*2 == 0:
            tmp = '0'*i + S[i:]
            if tmp.find(S[:i]) != -1:
                print(i)
                exit()
        else:
            for index in range(N-i*2):
                # 仮の文字列の生成
                tmp = S[:index] + '0'*i + S[index+i:]
                if tmp.find(S[index:index+i]) != -1:
                    print(i)
                    exit()

    print('0')


Fixed submission:
if __name__ == "__main__":
    N = int(input())
    S = input()

    dp = [[0] * 5005 for i in range(5005)]

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

    print(result)