import sys

import itertools

sys.setrecursionlimit(1000000000)

from heapq import heapify,heappop,heappush,heappushpop

import math

import collections



n = int(eval(input()))

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

c = collections.Counter(a)

item = []

for key,Value in list(c.items()):

    item.append([key,Value])

koho = []

if len(item) == 1:

    print((item[0][1]))

    sys.exit()

if item[1][0] - item[0][0] == 1:

    cnt = item[1][1] + item[0][1]

else:

    cnt = item[0][1]

koho.append(cnt)

cnt = 0

for i in range(1,len(item)-1):

    cnt = 0

    if item[i][0] - item[i-1][0] == 1:

        cnt += item[i-1][1] + item[i][1]

    if item[i+1][0] - item[i][0] == 1:

        cnt += item[i+1][1]

    koho.append(cnt)

cnt = 0

if item[-1][0] - item[-2][0] == 1:

    cnt += item[-1][1] + item[-2][1]

else:

    cnt += item[-1][1]

koho.append(cnt)

print((max(koho)))



import sys

import itertools

sys.setrecursionlimit(1000000000)

from heapq import heapify,heappop,heappush,heappushpop

import math

import collections



n = int(eval(input()))

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

x = [0]*100002

for i in range(n):

    x[a[i]]+=1

ans = 0

for i in range(100000):

    c = x[i] + x[i+1] + x[i+2]

    ans = max(ans,c)

print(ans)
import sys
import itertools

sys.setrecursionlimit(1000000000)
from heapq import heapify, heappop, heappush, heappushpop
import math
import collections

n = int(eval(input()))
a = sorted(list(map(int, input().split())))
c = collections.Counter(a)
item = []
for key, Value in list(c.items()):
    item.append([key, Value])
koho = []
if len(item) == 1:
    print((item[0][1]))
    sys.exit()
if item[1][0] - item[0][0] == 1:
    cnt = item[1][1] + item[0][1]
else:
    cnt = item[0][1]
koho.append(cnt)
cnt = 0
for i in range(1, len(item) - 1):
    cnt = 0
    if item[i][0] - item[i - 1][0] == 1:
        cnt += item[i - 1][1] + item[i][1]
    if item[i + 1][0] - item[i][0] == 1:
        cnt += item[i + 1][1]
    koho.append(cnt)
cnt = 0
if item[-1][0] - item[-2][0] == 1:
    cnt += item[-1][1] + item[-2][1]
else:
    cnt += item[-1][1]
koho.append(cnt)
print((max(koho)))

import sys
import itertools

sys.setrecursionlimit(1000000000)
from heapq import heapify, heappop, heappush, heappushpop
import math
import collections

n = int(eval(input()))
a = sorted(list(map(int, input().split())))
x = [0] * 100002
for i in range(n):
    x[a[i]] += 1
ans = 0
for i in range(100000):
    c = x[i] + x[i + 1] + x[i + 2]
    ans = max(ans, c)
print(ans)

-c = collections.Counter(a) -item = [] -for key, Value in list(c.items()): -    item.append([key, Value]) -koho = [] -if len(item) == 1: -    print((item[0][1])) -    sys.exit() -if item[1][0] - item[0][0] == 1: -    cnt = item[1][1] + item[0][1] -else: -    cnt = item[0][1] -koho.append(cnt) -cnt = 0 -for i in range(1, len(item) - 1): -    cnt = 0 -    if item[i][0] - item[i - 1][0] == 1: -        cnt += item[i - 1][1] + item[i][1] -    if item[i + 1][0] - item[i][0] == 1: -        cnt += item[i + 1][1] -    koho.append(cnt) -cnt = 0 -if item[-1][0] - item[-2][0] == 1: -    cnt += item[-1][1] + item[-2][1] -else: -    cnt += item[-1][1] -koho.append(cnt) -print((max(koho))) +x = [0] * 100002 +for i in range(n): +    x[a[i]] += 1 +ans = 0 +for i in range(100000): +    c = x[i] + x[i + 1] + x[i + 2] +    ans = max(ans, c) +print(ans)