from sys import stdin

import sys

import math



n = int(eval(input()))

#a = list(map(int, stdin.readline().rstrip().split()))

a = sorted(list(map(int, stdin.readline().rstrip().split())))





count_max = 1



count_prev = 0

count_curr = 1

count_next = 0



current_value = a[0]

for i in range(1, n):

    if a[i] == current_value:

        count_curr += 1

    elif a[i] == current_value + 1:

        count_next += 1

    elif a[i] == current_value + 2:

        count_max = max(count_max, (count_prev + count_curr + count_next))

        current_value = current_value + 1

        count_prev = count_curr

        count_curr = count_next

        count_next = 1

    elif a[i] >= current_value + 3:

        count_max = max(count_max, (count_prev + count_curr + count_next))

        current_value = a[i]

        count_prev = 0

        count_curr = 1

        count_next = 0

    else:

        print("Error")



count_max = max(count_max, (count_prev + count_curr + count_next))



print(count_max)

from sys import stdin

import sys

import math



n = int(eval(input()))

a = list(map(int, stdin.readline().rstrip().split()))



dict_count = {}

for i in a:

    dict_count[i] = 0



for j in a:

    dict_count[j] += 1



#print(dict_count)



max_count = 0



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

    max_count = max(max_count, dict_count.get(key - 1, 0) + dict_count.get(key, 0) + dict_count.get(key + 1, 0))



print(max_count)

from sys import stdin
import sys
import math

n = int(eval(input()))
# a = list(map(int, stdin.readline().rstrip().split()))
a = sorted(list(map(int, stdin.readline().rstrip().split())))
count_max = 1
count_prev = 0
count_curr = 1
count_next = 0
current_value = a[0]
for i in range(1, n):
    if a[i] == current_value:
        count_curr += 1
    elif a[i] == current_value + 1:
        count_next += 1
    elif a[i] == current_value + 2:
        count_max = max(count_max, (count_prev + count_curr + count_next))
        current_value = current_value + 1
        count_prev = count_curr
        count_curr = count_next
        count_next = 1
    elif a[i] >= current_value + 3:
        count_max = max(count_max, (count_prev + count_curr + count_next))
        current_value = a[i]
        count_prev = 0
        count_curr = 1
        count_next = 0
    else:
        print("Error")
count_max = max(count_max, (count_prev + count_curr + count_next))
print(count_max)

from sys import stdin
import sys
import math

n = int(eval(input()))
a = list(map(int, stdin.readline().rstrip().split()))
dict_count = {}
for i in a:
    dict_count[i] = 0
for j in a:
    dict_count[j] += 1
# print(dict_count)
max_count = 0
for key in list(dict_count.keys()):
    max_count = max(
        max_count,
        dict_count.get(key - 1, 0)
        + dict_count.get(key, 0)
        + dict_count.get(key + 1, 0),
    )
print(max_count)

-# a = list(map(int, stdin.readline().rstrip().split())) -a = sorted(list(map(int, stdin.readline().rstrip().split()))) -count_max = 1 -count_prev = 0 -count_curr = 1 -count_next = 0 -current_value = a[0] -for i in range(1, n): -    if a[i] == current_value: -        count_curr += 1 -    elif a[i] == current_value + 1: -        count_next += 1 -    elif a[i] == current_value + 2: -        count_max = max(count_max, (count_prev + count_curr + count_next)) -        current_value = current_value + 1 -        count_prev = count_curr -        count_curr = count_next -        count_next = 1 -    elif a[i] >= current_value + 3: -        count_max = max(count_max, (count_prev + count_curr + count_next)) -        current_value = a[i] -        count_prev = 0 -        count_curr = 1 -        count_next = 0 -    else: -        print("Error") -count_max = max(count_max, (count_prev + count_curr + count_next)) -print(count_max) +a = list(map(int, stdin.readline().rstrip().split())) +dict_count = {} +for i in a: +    dict_count[i] = 0 +for j in a: +    dict_count[j] += 1 +# print(dict_count) +max_count = 0 +for key in list(dict_count.keys()): +    max_count = max( +        max_count, +        dict_count.get(key - 1, 0) +        + dict_count.get(key, 0) +        + dict_count.get(key + 1, 0), +    ) +print(max_count)