Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from itertools import combinations
 
 
def p_e():
    N = int(input())
    S = input()
 
    S_idx = defaultdict(list)
 
    for i in range(N):
        S_idx[S[i]].append(i)
 
    max_ans = 0
    for c in S_idx.keys():
        if len(S_idx[c]) <= 1:
            continue
 
        comb_list = list(combinations(S_idx[c], 2))
        i = 1
 
        f = True
        while f:
            i += 1
            f = False
            for comb in comb_list:
                a = comb[0]
                b = comb[1]
                if a + i - 1 >= N or b + i - 1 >= N:
                    comb_list.remove(comb)
                    continue
 
                if a + i - 1 >= b:
                    comb_list.remove(comb)
                    continue
 
                if S[a + i - 1] == S[b + i - 1]:
                    f = True
                else:
                    comb_list.remove(comb)
 
        if max_ans < i - 1:
            max_ans = i - 1
 
    print(max_ans)
 
 
if __name__ == '__main__':
    p_e()

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

    l, r, ans = 0, 0, 0

    while r < N:
        if S[l:r] in S[r:N]:
            ans = max(ans, r - l)
            r += 1
        else:
            l += 1

    print(ans)


if __name__ == '__main__':
    p_e()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from itertools import combinations


def p_e():
    N = int(input())
    S = input()

    S_idx = defaultdict(list)

    for i in range(N):
        S_idx[S[i]].append(i)

    max_ans = 0
    for c in S_idx.keys():
        if len(S_idx[c]) <= 1:
            continue

        comb_list = list(combinations(S_idx[c], 2))
        i = 1

        f = True
        while f:
            i += 1
            f = False
            for comb in comb_list:
                a = comb[0]
                b = comb[1]
                if a + i - 1 >= N or b + i - 1 >= N:
                    comb_list.remove(comb)
                    continue

                if a + i - 1 >= b:
                    comb_list.remove(comb)
                    continue

                if S[a + i - 1] == S[b + i - 1]:
                    f = True
                else:
                    comb_list.remove(comb)

        if max_ans < i - 1:
            max_ans = i - 1

    print(max_ans)


if __name__ == '__main__':
    p_e()


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

    l, r, ans = 0, 0, 0

    while r < N:
        if S[l:r] in S[r:N]:
            ans = max(ans, r - l)
            r += 1
        else:
            l += 1

    print(ans)


if __name__ == '__main__':
    p_e()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from itertools import combinations


def p_e():
    N = int(input())
    S = input()

    S_idx = defaultdict(list)

    for i in range(N):
        S_idx[S[i]].append(i)

    ans = []

    for c in S_idx.keys():
        if len(S_idx[c]) <= 1:
            continue

        comb_list = list(combinations(S_idx[c], 2))
        i = 1

        f = True
        while f:
            i += 1
            f = False
            for comb in comb_list:
                a = comb[0]
                b = comb[1]
                if a + i - 1 >= N or b + i - 1 >= N:
                    comb_list.remove(comb)
                    continue

                if a + i - 1 >= b:
                    comb_list.remove(comb)
                    continue

                if S[a + i - 1] == S[b + i - 1]:
                    f = True
                else:
                    comb_list.remove(comb)

        ans.append(i - 1)

    if ans:
        print(max(ans))
    else:
        print(0)


if __name__ == '__main__':
    p_e()


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

    l, r, ans = 0, 0, 0

    while r < N:
        if S[l:r] in S[r:N]:
            ans = max(ans, r - l)
            r += 1
        else:
            l += 1

    print(ans)


if __name__ == '__main__':
    p_e()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
from itertools import combinations


def p_e():
    N = int(input())
    S = input()

    S_idx = defaultdict(list)

    for i in range(N):
        S_idx[S[i]].append(i)

    ans = []

    for c in S_idx.keys():
        if len(S_idx[c]) <= 1:
            continue

        comb_list = list(combinations(S_idx[c], 2))
        i = 1

        f = True
        while f:
            i += 1
            f = False
            for comb in comb_list:
                a = comb[0]
                b = comb[1]
                if a + i - 1 >= N or b + i - 1 >= N:
                    comb_list.remove(comb)
                    continue

                if a + i - 1 >= b:
                    comb_list.remove(comb)
                    continue

                if S[a + i - 1] == S[b + i - 1]:
                    f = True
                else:
                    comb_list.remove(comb)

        ans.append(i - 1)

    if ans:
        print(max(ans))
    else:
        print(0)


if __name__ == '__main__':
    p_e()


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

    l, r, ans = 0, 0, 0

    while r < N:
        if S[l:r] in S[r:N]:
            ans = max(ans, r - l)
            r += 1
        else:
            l += 1

    print(ans)


if __name__ == '__main__':
    p_e()

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from itertools import combinations


def p_e():
    N = int(input())
    S = input()

    S_idx = defaultdict(list)

    for i in range(N):
        S_idx[S[i]].append(i)

    ans = []

    for c in S_idx.keys():
        if len(S_idx[c]) <= 1:
            continue

        comb_list = list(combinations(S_idx[c], 2))
        i = 1

        f = True
        while f:
            i += 1
            f = False
            for comb in comb_list:
                a = comb[0]
                b = comb[1]
                if S[a: a + i] == S[b: b + i]:
                    f = True

        ans.append(i - 1)

    print(max(ans))


if __name__ == '__main__':
    p_e()


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

    l, r, ans = 0, 0, 0

    while r < N:
        if S[l:r] in S[r:N]:
            ans = max(ans, r - l)
            r += 1
        else:
            l += 1

    print(ans)


if __name__ == '__main__':
    p_e()