Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

num_list = [0] * (max(a) + 2)

for i in range(n):
    num_list[a[i]] += 1
    if i == n:
        continue
    elif a[i] == 0:
        continue
    else:
        num_list[a[i]-1] += 1
    if i == 0 or a[i] == max(a):
        continue
    else:
        num_list[a[i]+1] += 1

print(max(num_list))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

t = max(a)
num_list = [0] * (t + 2)

for i in range(n):
    num_list[a[i]] += 1
    if a[i] == 0:
        continue
    else:
        num_list[a[i]-1] += 1
    if a[i] == t:
        continue
    else:
        num_list[a[i]+1] += 1

print(max(num_list))

Buggy python submission (verdict: Runtime Error):
import collections

n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0

c = collections.Counter(a)
d = list(c.keys())
e = list(c.values())

if n == 1:
    print(1)
    exit()
elif n == 2:
    if a[0] == a[1] or abs(a[0] - a[1]) == 1:
        print(2)
        exit()
    else:
        print(1)
        exit()
elif len(d) == 1:
    print(e[0])
    exit()
elif len(d) == 2:
    if d[0] == d[1] or abs(d[0] - d[1]) == 1:
        print(e[0] + e[1])
        exit()
    else:
        print(max(e[0], e[1]))


for i in range(n-2):
    if abs(d[i] - d[i+1]) == 1 and abs(d[i] - d[i+2]) == 2:
        num = e[i] + e[i+1] + e[i+2]
    elif abs(d[i] -d[i+1]) == 1:
        num = e[i] + e[i+1]
    else:
        num = e[i]
    if num > ans:
        ans = num

if d[-2] == d[-1] or abs(d[-2] - d[-1]) == 1:
    num = e[-2] + e[-1]
else:
    num = max(e[-2], e[-1])

if num > ans:
    ans = num

print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

t = max(a)
num_list = [0] * (t + 2)

for i in range(n):
    num_list[a[i]] += 1
    if a[i] == 0:
        continue
    else:
        num_list[a[i]-1] += 1
    if a[i] == t:
        continue
    else:
        num_list[a[i]+1] += 1

print(max(num_list))

Buggy python submission (verdict: Runtime Error):
import collections

n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0

c = collections.Counter(a)
d = list(c.keys())
e = list(c.values())

if n == 1:
    print(1)
    exit()
elif n == 2:
    if a[0] == a[1] or abs(a[0] - a[1]) == 1:
        print(2)
        exit()
    else:
        print(1)
        exit()


for i in range(n-2):
    if abs(d[i] - d[i+1]) == 1 and abs(d[i] - d[i+2]) == 2:
        num = e[i] + e[i+1] + e[i+2]
    elif abs(d[i] -d[i+1]) == 1:
        num = e[i] + e[i+1]
    else:
        num = e[i]
    if num > ans:
        ans = num

if d[-2] == d[-1] or abs(d[-2] - d[-1]) == 1:
    num = e[-2] + e[-1]
else:
    num = max(e[-2], e[-1])

if num > ans:
    ans = num

print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

t = max(a)
num_list = [0] * (t + 2)

for i in range(n):
    num_list[a[i]] += 1
    if a[i] == 0:
        continue
    else:
        num_list[a[i]-1] += 1
    if a[i] == t:
        continue
    else:
        num_list[a[i]+1] += 1

print(max(num_list))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
if n == 1:
    print(1)
    exit()

a.sort()
li = []
count = 1
for i in range(n-1):
    if a[i] == a[i+1]:
        count += 1
    else:
        li.append(count)
        count = 1

li.sort()
count2 = 0

if len(li) == 1:
    print(li[0])
    exit()
elif len(li) == 2:
    if abs(a[0] - a[-1]) <= 2:
        print(li[0] + li[1])
    else:
        print(max(li[0], li[1]))
else:

    for i in range(len(li)-2):
        x = li[i] + li[i+1] + li[i+2]
        if x >= count2:
            count2 = x

    print(x)



Fixed submission:
n = int(input())
a = list(map(int, input().split()))

t = max(a)
num_list = [0] * (t + 2)

for i in range(n):
    num_list[a[i]] += 1
    if a[i] == 0:
        continue
    else:
        num_list[a[i]-1] += 1
    if a[i] == t:
        continue
    else:
        num_list[a[i]+1] += 1

print(max(num_list))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
if n == 1:
    print(1)
    exit()

a.sort()
li = []
count = 1
for i in range(n-1):
    if a[i] == a[i+1]:
        count += 1
    else:
        li.append(count)
        count = 1

li.sort()
count2 = 0
for i in range(len(li)-2):
    x = li[i] + li[i+1] + li[i+2]
    if x >= count2:
        count2 = x

print(x)



Fixed submission:
n = int(input())
a = list(map(int, input().split()))

t = max(a)
num_list = [0] * (t + 2)

for i in range(n):
    num_list[a[i]] += 1
    if a[i] == 0:
        continue
    else:
        num_list[a[i]-1] += 1
    if a[i] == t:
        continue
    else:
        num_list[a[i]+1] += 1

print(max(num_list))