Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()[::-1]

    res = 0
    dp = [[0] * n for _ in range(n)]
    for i in range(n):
        for j in range(i + 1, n):
            if s[i] == s[j]:
                dp[i][j] = dp[i - 1][j - 1] + 1
                res = max(res, min(j - i, dp[i][j]))

    print(res)


if __name__ == '__main__':
    resolve()

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()

    dp = [[0] * (n + 1) for _ in range(n + 1)]
    for i in reversed(range(n)):
        for j in reversed(range(n)):
            if s[i] == s[j]:
                dp[i][j] = dp[i + 1][j + 1] + 1

    res = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                now = min(dp[i][j], j - i)
                res = max(res, now)
    print(res)


if __name__ == '__main__':
    resolve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()

    dp = [[0] * (n + 1) for _ in range(n + 1)]
    for i in reversed(range(n)):
        for j in reversed(range(n)):
            if s[i] == s[j]:
                dp[i][j] = dp[i + 1][j + 1] + 1

    res = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                now = min(dp[i][j], j - i)
                res = max(res, now)
    print(res)


if __name__ == '__main__':
    resolve()


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()

    dp = [[0] * (n + 1) for _ in range(n + 1)]
    for i in reversed(range(n)):
        for j in reversed(range(n)):
            if s[i] == s[j]:
                dp[i][j] = dp[i + 1][j + 1] + 1

    res = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                now = min(dp[i][j], j - i)
                res = max(res, now)
    print(res)


if __name__ == '__main__':
    resolve()

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

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()
    D = Counter(s)
    idx = [[] for _ in range(26)]
    for k, v in D.items():
        if v >= 2:
            for i in range(n):
                if s[i] == k:
                    idx[ord(k) - 97].append(i)

    res = 0
    for i in idx:
        if not i:
            continue
        tmp = 0
        for pattern in combinations(i, 2):
            left_init, right_init = pattern
            left, right = left_init, right_init
            length = 0
            while right < n and left < right_init:
                if s[left] == s[right]:
                    length += 1
                    left += 1
                    right += 1
                else:
                    break
            tmp = max(tmp, length)
        res = max(res, tmp)
    print(res)


if __name__ == '__main__':
    resolve()


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()

    dp = [[0] * (n + 1) for _ in range(n + 1)]
    for i in reversed(range(n)):
        for j in reversed(range(n)):
            if s[i] == s[j]:
                dp[i][j] = dp[i + 1][j + 1] + 1

    res = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                now = min(dp[i][j], j - i)
                res = max(res, now)
    print(res)


if __name__ == '__main__':
    resolve()

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

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()
    D = Counter(s)
    idx = [[] for _ in range(26)]
    for k, v in D.items():
        if v >= 2:
            for i in range(n):
                if s[i] == k:
                    idx[ord(k) - 97].append(i)

    res = 0
    for i in idx:
        if not i:
            continue
        tmp = 0
        for pattern in combinations(i, 2):
            left_init, right_init = pattern
            left, right = left_init, right_init
            length = 0
            while right < n and left < right_init:
                if s[left] == s[right]:
                    length += 1
                    left += 1
                    right += 1
                else:
                    break
            tmp = max(tmp, length)
        res = max(res, tmp)
    print(res)


if __name__ == '__main__':
    resolve()


Fixed submission:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()

    dp = [[0] * (n + 1) for _ in range(n + 1)]
    for i in reversed(range(n)):
        for j in reversed(range(n)):
            if s[i] == s[j]:
                dp[i][j] = dp[i + 1][j + 1] + 1

    res = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                now = min(dp[i][j], j - i)
                res = max(res, now)
    print(res)


if __name__ == '__main__':
    resolve()