Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, = read_h()
    arr = sorted(read_h())

    cnt = 0
    for X in set(arr):
        tmp_cnt = 0
        for a in arr:
            if a > X + 1:
                break
            if X - 1 <= a <= X + 1:
                tmp_cnt += 1

        cnt = max(cnt, tmp_cnt)

    print(cnt)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, = read_h()
    arr = read_h()

    from collections import Counter
    c = Counter(arr)

    cnt = 0
    for X in c.keys():
        cnt = max(cnt, c.get(X - 1, 0) + c.get(X, 0) + c.get(X + 1, 0))

    print(cnt)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, = read_h()
    arr = read_h()

    cnt = 0
    for X in set(arr):
        tmp_cnt = 0
        for a in arr:
            if X - 1 <= a <= X + 1:
                tmp_cnt += 1

        cnt = max(cnt, tmp_cnt)

    print(cnt)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, = read_h()
    arr = read_h()

    from collections import Counter
    c = Counter(arr)

    cnt = 0
    for X in c.keys():
        cnt = max(cnt, c.get(X - 1, 0) + c.get(X, 0) + c.get(X + 1, 0))

    print(cnt)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, = read_h()
    arr = read_h()

    cnt = 0
    for X in set(arr):
        cnt = max(cnt, sum([1 for a in arr if X - 1 <= a <= X + 1]))

    print(cnt)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, = read_h()
    arr = read_h()

    from collections import Counter
    c = Counter(arr)

    cnt = 0
    for X in c.keys():
        cnt = max(cnt, c.get(X - 1, 0) + c.get(X, 0) + c.get(X + 1, 0))

    print(cnt)


if __name__ == '__main__':
    main()