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

ans = 1
for i in range(N):
    X = a[i]
    res = 1
    j = i+1
    while (j < N and a[j] - X <= 1):
        j += 1
        res += 1
    j = i-1
    while (j >= 0 and X - a[j] <= 1):
        j -= 1
        res += 1
    ans = max(res, ans)

print(ans)


Fixed submission:
from bisect import bisect_left, bisect_right

N = int(input())
a = sorted(list(map(int, input().split())))

ans = 1
for i in range(N):
    X = a[i]
    res = bisect_right(a, X+1) - bisect_left(a, X-1)
    ans = max(res, ans)

print(ans)

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

ans = 1
for i in range(N):
    X = a[i]
    res = 1
    j = i+1
    while (j < N and a[j] - X <= 1):
        j += 1
        res += 1
    j = i-1
    while (j >= 0 and X - a[j] <= 1):
        j -= 1
        res += 1
    ans = max(res, ans)

print(ans)


Fixed submission:
from bisect import bisect_left, bisect_right

N = int(input())
a = sorted(list(map(int, input().split())))

ans = 1
for i in range(N):
    X = a[i]
    res = bisect_right(a, X+1) - bisect_left(a, X-1)
    ans = max(res, ans)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
b = set(a)
ans = 0
for k in b:
	ans = max(ans, a.count(k) + a.count(k + 1) + a.count(k - 1))
print(ans)


Fixed submission:
from bisect import bisect_left, bisect_right

N = int(input())
a = sorted(list(map(int, input().split())))

ans = 1
for i in range(N):
    X = a[i]
    res = bisect_right(a, X+1) - bisect_left(a, X-1)
    ans = max(res, ans)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
s = []

for k in range(min(a), max(a) + 1):
	tmp = 0
	for x in a:
		if x in [k - 1, k, k + 1]:
			tmp += 1
	s.append(tmp)
print(max(s))


Fixed submission:
from bisect import bisect_left, bisect_right

N = int(input())
a = sorted(list(map(int, input().split())))

ans = 1
for i in range(N):
    X = a[i]
    res = bisect_right(a, X+1) - bisect_left(a, X-1)
    ans = max(res, ans)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
s = []

for k in range(min(a), max(a) + 1):
	s.append(a.count(k) + a.count(k + 1) + a.count(k - 1))
print(max(s))


Fixed submission:
from bisect import bisect_left, bisect_right

N = int(input())
a = sorted(list(map(int, input().split())))

ans = 1
for i in range(N):
    X = a[i]
    res = bisect_right(a, X+1) - bisect_left(a, X-1)
    ans = max(res, ans)

print(ans)

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

for k in range(min(a), max(a) + 1):
	ans = max(ans, a.count(k) + a.count(k + 1) + a.count(k - 1))
print(ans)


Fixed submission:
from bisect import bisect_left, bisect_right

N = int(input())
a = sorted(list(map(int, input().split())))

ans = 1
for i in range(N):
    X = a[i]
    res = bisect_right(a, X+1) - bisect_left(a, X-1)
    ans = max(res, ans)

print(ans)

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

for k in range(min(a) - 1, max(a) + 2):
	ans = max(ans, a.count(k) + a.count(k + 1) + a.count(k - 1))
	ans = max(ans, a.count(k - 1) + a.count(k) + a.count(k - 2))
	ans = max(ans, a.count(k + 1) + a.count(k + 2) + a.count(k))

print(ans)


Fixed submission:
from bisect import bisect_left, bisect_right

N = int(input())
a = sorted(list(map(int, input().split())))

ans = 1
for i in range(N):
    X = a[i]
    res = bisect_right(a, X+1) - bisect_left(a, X-1)
    ans = max(res, ans)

print(ans)

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

for k in set(a):
	ans = max(ans, a.count(k) + a.count(k + 1) + a.count(k - 1))
	ans = max(ans, a.count(k - 1) + a.count(k) + a.count(k - 2))
	ans = max(ans, a.count(k + 1) + a.count(k + 2) + a.count(k))

print(ans)


Fixed submission:
from bisect import bisect_left, bisect_right

N = int(input())
a = sorted(list(map(int, input().split())))

ans = 1
for i in range(N):
    X = a[i]
    res = bisect_right(a, X+1) - bisect_left(a, X-1)
    ans = max(res, ans)

print(ans)