n = int(eval(input()))

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

a.sort()

a.append(a[-1] + 1)



b = [a[0]]

c = [1]

ans = 0

for i in range(1, n+1):

    if a[i] == b[-1]:

        c[-1] += 1

    else:

        cand = c[-1]

        if len(b) >= 2 and b[-2] == b[-1] - 1:

            cand += c[-2]

        if len(b) >= 3 and b[-3] == b[-1] - 2:

            cand += c[-3]

        ans = max(ans, cand)

        b.append(a[i])

        c.append(1)



print(ans)

from collections import defaultdict

n = int(eval(input()))

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



d = defaultdict(int)

for i in range(n):

    d[a[i]] += 1



ans = 0

for x in d:

    cand = d[x]

    if x - 1 in d:

        cand += d[x - 1]

    if x + 1 in d:

        cand += d[x + 1]

    

    ans = max(ans, cand)



print(ans)

n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
a.append(a[-1] + 1)
b = [a[0]]
c = [1]
ans = 0
for i in range(1, n + 1):
    if a[i] == b[-1]:
        c[-1] += 1
    else:
        cand = c[-1]
        if len(b) >= 2 and b[-2] == b[-1] - 1:
            cand += c[-2]
        if len(b) >= 3 and b[-3] == b[-1] - 2:
            cand += c[-3]
        ans = max(ans, cand)
        b.append(a[i])
        c.append(1)
print(ans)

from collections import defaultdict

n = int(eval(input()))
a = list(map(int, input().split()))
d = defaultdict(int)
for i in range(n):
    d[a[i]] += 1
ans = 0
for x in d:
    cand = d[x]
    if x - 1 in d:
        cand += d[x - 1]
    if x + 1 in d:
        cand += d[x + 1]
    ans = max(ans, cand)
print(ans)

+from collections import defaultdict + -a.sort() -a.append(a[-1] + 1) -b = [a[0]] -c = [1] +d = defaultdict(int) +for i in range(n): +    d[a[i]] += 1 -for i in range(1, n + 1): -    if a[i] == b[-1]: -        c[-1] += 1 -    else: -        cand = c[-1] -        if len(b) >= 2 and b[-2] == b[-1] - 1: -            cand += c[-2] -        if len(b) >= 3 and b[-3] == b[-1] - 2: -            cand += c[-3] -        ans = max(ans, cand) -        b.append(a[i]) -        c.append(1) +for x in d: +    cand = d[x] +    if x - 1 in d: +        cand += d[x - 1] +    if x + 1 in d: +        cand += d[x + 1] +    ans = max(ans, cand)