import numpy as np

N = int(eval(input()))

A = np.array(list(map(int, input().split())))

counter = np.append(0, np.bincount(A, minlength=10**5 + 10))

# print(counter)

cumsum = counter.cumsum()

# print(cumsum)

# print((cumsum[3:] - cumsum[:-3]))

print(((cumsum[3:] - cumsum[:-3]).max()))

from collections import Counter



N = int(eval(input()))

A = list(map(int, input().split()))

c = Counter(A)



# print('C', c)



ans = 0

for key in list(c.keys()):

    v = c[key]

    v += c.get(key - 1, 0)

    v += c.get(key + 1, 0)

    ans = max(ans, v)

print(ans)

import numpy as np

N = int(eval(input()))
A = np.array(list(map(int, input().split())))
counter = np.append(0, np.bincount(A, minlength=10**5 + 10))
# print(counter)
cumsum = counter.cumsum()
# print(cumsum)
# print((cumsum[3:] - cumsum[:-3]))
print(((cumsum[3:] - cumsum[:-3]).max()))

from collections import Counter

N = int(eval(input()))
A = list(map(int, input().split()))
c = Counter(A)
# print('C', c)
ans = 0
for key in list(c.keys()):
    v = c[key]
    v += c.get(key - 1, 0)
    v += c.get(key + 1, 0)
    ans = max(ans, v)
print(ans)

-import numpy as np +from collections import Counter -A = np.array(list(map(int, input().split()))) -counter = np.append(0, np.bincount(A, minlength=10**5 + 10)) -# print(counter) -cumsum = counter.cumsum() -# print(cumsum) -# print((cumsum[3:] - cumsum[:-3])) -print(((cumsum[3:] - cumsum[:-3]).max())) +A = list(map(int, input().split())) +c = Counter(A) +# print('C', c) +ans = 0 +for key in list(c.keys()): +    v = c[key] +    v += c.get(key - 1, 0) +    v += c.get(key + 1, 0) +    ans = max(ans, v) +print(ans)