Buggy python submission (verdict: Time Limit Exceeded):
import collections
def main():

    N = int(input())
    S = input()
    d = collections.defaultdict(dict)
    ans = 0
    for l in range(N//2, 0, -1):
        t = 0
        for i in range(l):
            t |= 1 << (26*(l-i-1) + ord(S[i])-97)
        d[l][t] = [0, l-1]
        for i in range(1, N-l+1):
            t ^= 1 << (26*(l-1) + ord(S[i-1])-97)
            t = t << 26
            t |= 1 << (ord(S[i+l-1])-97)

            if t not in d[l]:
                d[l][t] = [i, i+l-1]
            else:
                if i > d[l][t][1]:
                    return l
    return ans

if __name__ == '__main__':
    print(main())

Fixed submission:
def main():

    N = int(input())
    S = input()
    dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
    ans = 0

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

if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
import collections
def main():

    N = int(input())
    S = input()
    d = collections.defaultdict(dict)
    ans = 0
    for l in range(1, N//2+1):
        for i in range(N-l+1):
            t = S[i:i+l]
            if t not in d[l]:
                d[l][t] = [i, i+l-1]
            else:
                if i > d[l][t][1]:
                    ans = l
                    break
    return ans

if __name__ == '__main__':
    print(main())

Fixed submission:
def main():

    N = int(input())
    S = input()
    dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
    ans = 0

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

if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
import collections
def main():

    N = int(input())
    S = input()
    d = collections.defaultdict(dict)
    for l in range(1, N//2+1):
        for i in range(N-l+1):
            if S[i:i+l] not in d[l]:
                d[l][S[i:i+l]] = [[i, i+l-1]]
            else:
                d[l][S[i:i+l]].append([i, i+l-1])


    for l in range(N//2, 0, -1):
        if l in d:
            for s in d[l]:
                if len(d[l][s]) > 1:
                    # print(d[l][s], l)
                    i, j = d[l][s][0]
                    k, m = d[l][s][-1]
                    if j < k:
                        return l
    return 0

if __name__ == '__main__':
    print(main())

Fixed submission:
def main():

    N = int(input())
    S = input()
    dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
    ans = 0

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

if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
import collections
def main():

    N = int(input())
    S = input()
    d = collections.defaultdict(list)
    for l in range(1, N+1):
        for i in range(N-l+1):
            d[S[i:i+l]].append([i, i+l-1])

    ans = 0
    for s in d:
        if len(d[s]) > 1:
            i, j = d[s][0]
            k, l = d[s][-1]
            if j < k:
                ans = max(ans, j-i+1)

    return ans

if __name__ == '__main__':
    print(main())

Fixed submission:
def main():

    N = int(input())
    S = input()
    dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
    ans = 0

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

if __name__ == '__main__':
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
import collections
def main():

    N = int(input())
    S = input()
    d = collections.defaultdict(list)
    for l in range(1, N+1):
        for i in range(N-l+1):
            d[S[i:i+l]].append([i, i+l-1])
    for s in d:
        d[s] = sorted(d[s], key = lambda x: x[0])

    ans = 0
    for s in d:
        if len(d[s]) > 1:
            i, j = d[s][0]
            k, l = d[s][-1]
            if j < k:
                ans = max(ans, j-i+1)
    return ans

if __name__ == '__main__':
    print(main())

Fixed submission:
def main():

    N = int(input())
    S = input()
    dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
    ans = 0

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

if __name__ == '__main__':
    print(main())