from collections import Counter

from operator import itemgetter



n = int(eval(input()))

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



c = Counter(a)



def num(n):

	if n in list(c.keys()):

		return c[n]

	else:

		return 0



ans = 0



for i in range(99998):

	candidate = num(i) + num(i+1) + num(i+2)

	if candidate > ans:

		ans = candidate



print(ans)
from collections import Counter

from operator import itemgetter



n = int(eval(input()))

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



c = Counter(a)



def num(n):

	if n in list(c.keys()):

		return c[n]

	else:

		return 0



candidate = num(0) + num(1) + num(2)

ans = candidate



for i in range(1, 99998):

	candidate -= num(i-1)

	candidate += num(i+2)

	if candidate > ans:

		ans = candidate



print(ans)
from collections import Counter
from operator import itemgetter

n = int(eval(input()))
a = list(map(int, input().split()))
c = Counter(a)


def num(n):
    if n in list(c.keys()):
        return c[n]
    else:
        return 0


ans = 0
for i in range(99998):
    candidate = num(i) + num(i + 1) + num(i + 2)
    if candidate > ans:
        ans = candidate
print(ans)

from collections import Counter
from operator import itemgetter

n = int(eval(input()))
a = list(map(int, input().split()))
c = Counter(a)


def num(n):
    if n in list(c.keys()):
        return c[n]
    else:
        return 0


candidate = num(0) + num(1) + num(2)
ans = candidate
for i in range(1, 99998):
    candidate -= num(i - 1)
    candidate += num(i + 2)
    if candidate > ans:
        ans = candidate
print(ans)

-ans = 0 -for i in range(99998): -    candidate = num(i) + num(i + 1) + num(i + 2) +candidate = num(0) + num(1) + num(2) +ans = candidate +for i in range(1, 99998): +    candidate -= num(i - 1) +    candidate += num(i + 2)