import sys

import bisect





def main():

    n, *a = list(map(int, sys.stdin.read().split()))

    lr = [[i - 1,i + 1] for i in a]

    lr.sort(key=lambda x: x[0])

    l = [i[0] for i in lr]

    res = 0

    for i in range(n):

        right = bisect.bisect(l, lr[i][1])

        left = bisect.bisect_left(l, l[i])

        res = max(res, right - left)

    print(res)





if __name__ == '__main__':

    main()
import sys

from itertools import accumulate





def main():

    n, *A = list(map(int, sys.stdin.read().split()))

    minA = min(A) - 1

    lr = [[i - 1 - minA, i + 1 - minA] for i in A]

    lst = [0] * (max(A) - minA + 3)

    for i, j in lr:

        lst[i] += 1

        lst[j + 1] -= 1

    lst = list(accumulate(lst))

    print((max(lst)))





if __name__ == '__main__':

    main()
import sys
import bisect


def main():
    n, *a = list(map(int, sys.stdin.read().split()))
    lr = [[i - 1, i + 1] for i in a]
    lr.sort(key=lambda x: x[0])
    l = [i[0] for i in lr]
    res = 0
    for i in range(n):
        right = bisect.bisect(l, lr[i][1])
        left = bisect.bisect_left(l, l[i])
        res = max(res, right - left)
    print(res)


if __name__ == "__main__":
    main()

import sys
from itertools import accumulate


def main():
    n, *A = list(map(int, sys.stdin.read().split()))
    minA = min(A) - 1
    lr = [[i - 1 - minA, i + 1 - minA] for i in A]
    lst = [0] * (max(A) - minA + 3)
    for i, j in lr:
        lst[i] += 1
        lst[j + 1] -= 1
    lst = list(accumulate(lst))
    print((max(lst)))


if __name__ == "__main__":
    main()

-import bisect +from itertools import accumulate -    n, *a = list(map(int, sys.stdin.read().split())) -    lr = [[i - 1, i + 1] for i in a] -    lr.sort(key=lambda x: x[0]) -    l = [i[0] for i in lr] -    res = 0 -    for i in range(n): -        right = bisect.bisect(l, lr[i][1]) -        left = bisect.bisect_left(l, l[i]) -        res = max(res, right - left) -    print(res) +    n, *A = list(map(int, sys.stdin.read().split())) +    minA = min(A) - 1 +    lr = [[i - 1 - minA, i + 1 - minA] for i in A] +    lst = [0] * (max(A) - minA + 3) +    for i, j in lr: +        lst[i] += 1 +        lst[j + 1] -= 1 +    lst = list(accumulate(lst)) +    print((max(lst)))