N = int(eval(input()))

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

L.sort()

L.append(1000000)

M = [0]*((10**5)+1)

c = 0

d = 1

num = L[0]

if N == 1:

  print((1))

elif N == 2:

  if abs(L[0]-L[1]) <=1 :

    print((2))

  else:

    print((1))

else:

  while c <= N-1:

    if L[c] == L[c+1]:

      d += 1

      c += 1

    else:

      M[num] = d

      d = 1

      c += 1

      num = L[c]

  M.insert(0,0)

  M.append(0)

  ans = 0

  for i in range(len(M)-2):

    if M[i]+M[i+1]+M[i+2] >= ans:

      ans = M[i]+M[i+1]+M[i+2]

  print(ans)
N = int(eval(input()))

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

if N == 1:

  print((1))

elif N == 2:

  if abs(A[1]-A[0]) <= 2:

    print((2))

  else:

    print((1))

else:

  L = [0]*(10**5+1)

  for i in range(N):

    L[A[i]+1] += 1

  for j in range(1,len(L)):

    L[j] = L[j-1]+L[j]

  ans = 0

  for k in range(3,len(L)):

    S = L[k]-L[k-3]

    if ans <= S:

      ans = S

  print(ans)
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
L.append(1000000)
M = [0] * ((10**5) + 1)
c = 0
d = 1
num = L[0]
if N == 1:
    print((1))
elif N == 2:
    if abs(L[0] - L[1]) <= 1:
        print((2))
    else:
        print((1))
else:
    while c <= N - 1:
        if L[c] == L[c + 1]:
            d += 1
            c += 1
        else:
            M[num] = d
            d = 1
            c += 1
            num = L[c]
    M.insert(0, 0)
    M.append(0)
    ans = 0
    for i in range(len(M) - 2):
        if M[i] + M[i + 1] + M[i + 2] >= ans:
            ans = M[i] + M[i + 1] + M[i + 2]
    print(ans)

N = int(eval(input()))
A = list(map(int, input().split()))
if N == 1:
    print((1))
elif N == 2:
    if abs(A[1] - A[0]) <= 2:
        print((2))
    else:
        print((1))
else:
    L = [0] * (10**5 + 1)
    for i in range(N):
        L[A[i] + 1] += 1
    for j in range(1, len(L)):
        L[j] = L[j - 1] + L[j]
    ans = 0
    for k in range(3, len(L)):
        S = L[k] - L[k - 3]
        if ans <= S:
            ans = S
    print(ans)

-L = list(map(int, input().split())) -L.sort() -L.append(1000000) -M = [0] * ((10**5) + 1) -c = 0 -d = 1 -num = L[0] +A = list(map(int, input().split())) -    if abs(L[0] - L[1]) <= 1: +    if abs(A[1] - A[0]) <= 2: -    while c <= N - 1: -        if L[c] == L[c + 1]: -            d += 1 -            c += 1 -        else: -            M[num] = d -            d = 1 -            c += 1 -            num = L[c] -    M.insert(0, 0) -    M.append(0) +    L = [0] * (10**5 + 1) +    for i in range(N): +        L[A[i] + 1] += 1 +    for j in range(1, len(L)): +        L[j] = L[j - 1] + L[j] -    for i in range(len(M) - 2): -        if M[i] + M[i + 1] + M[i + 2] >= ans: -            ans = M[i] + M[i + 1] + M[i + 2] +    for k in range(3, len(L)): +        S = L[k] - L[k - 3] +        if ans <= S: +            ans = S