from sys import stdin

def main():

    #入力

    readline=stdin.readline

    n=int(readline())

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



    d=dict()

    for i in range(n):

        if a[i] not in d:

            d[a[i]]=1

        else:

            d[a[i]]+=1



    cnt=0

    for x in range(1,10**5+1):

        if x-1 in d: s=d[x-1]

        else: s=0



        if x in d: t=d[x]

        else: t=0



        if x+1 in d: u=d[x+1]

        else: u=0



        cnt=max(cnt,s+t+u)



    print(cnt)



if __name__=="__main__":

    main()
from sys import stdin

def main():

    #入力

    readline=stdin.readline

    n=int(readline())

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



    li=[0]*(10**5+2)

    for i in range(n):

        li[a[i]]+=1



    cnt=0

    for x in range(1,10**5+1):

        cnt=max(cnt,li[x-1]+li[x]+li[x+1])



    print(cnt)



if __name__=="__main__":

    main()
from sys import stdin


def main():
    # 入力
    readline = stdin.readline
    n = int(readline())
    a = list(map(int, readline().split()))
    d = dict()
    for i in range(n):
        if a[i] not in d:
            d[a[i]] = 1
        else:
            d[a[i]] += 1
    cnt = 0
    for x in range(1, 10**5 + 1):
        if x - 1 in d:
            s = d[x - 1]
        else:
            s = 0
        if x in d:
            t = d[x]
        else:
            t = 0
        if x + 1 in d:
            u = d[x + 1]
        else:
            u = 0
        cnt = max(cnt, s + t + u)
    print(cnt)


if __name__ == "__main__":
    main()

from sys import stdin


def main():
    # 入力
    readline = stdin.readline
    n = int(readline())
    a = list(map(int, readline().split()))
    li = [0] * (10**5 + 2)
    for i in range(n):
        li[a[i]] += 1
    cnt = 0
    for x in range(1, 10**5 + 1):
        cnt = max(cnt, li[x - 1] + li[x] + li[x + 1])
    print(cnt)


if __name__ == "__main__":
    main()

-    d = dict() +    li = [0] * (10**5 + 2) -        if a[i] not in d: -            d[a[i]] = 1 -        else: -            d[a[i]] += 1 +        li[a[i]] += 1 -        if x - 1 in d: -            s = d[x - 1] -        else: -            s = 0 -        if x in d: -            t = d[x] -        else: -            t = 0 -        if x + 1 in d: -            u = d[x + 1] -        else: -            u = 0 -        cnt = max(cnt, s + t + u) +        cnt = max(cnt, li[x - 1] + li[x] + li[x + 1])