def inpl():

    return input().split()



n = int(eval(input()))

a = list(map(int, inpl()))

d = {}

for i in range(n):

    d[a[i]] = d.get(a[i], 0) + 1



ans = 0

for k in list(d.keys()):

    b = 0

    b += d.get(k - 1, 0)

    b += d.get(k, 0)

    b += d.get(k + 1, 0)

    ans = max(ans, b)

print(ans)
def main():

    from collections import deque



    N = int(eval(input()))

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



    b = [0] * (10 ** 5 + 10)

    for x in a:

        b[x] += 1



    dq = deque()

    b_iter = iter(b)

    dq.append(next(b_iter))

    dq.append(next(b_iter))

    dq.append(next(b_iter))

    t = sum(dq)

    ans = t

    for x in b:

        dq.append(x)

        y = dq.popleft()

        t = t + x - y

        if ans < t:

            ans = t

    print(ans)





if __name__ == '__main__':

    main()

def inpl():
    return input().split()


n = int(eval(input()))
a = list(map(int, inpl()))
d = {}
for i in range(n):
    d[a[i]] = d.get(a[i], 0) + 1
ans = 0
for k in list(d.keys()):
    b = 0
    b += d.get(k - 1, 0)
    b += d.get(k, 0)
    b += d.get(k + 1, 0)
    ans = max(ans, b)
print(ans)

def main():
    from collections import deque

    N = int(eval(input()))
    (*a,) = list(map(int, input().split()))
    b = [0] * (10**5 + 10)
    for x in a:
        b[x] += 1
    dq = deque()
    b_iter = iter(b)
    dq.append(next(b_iter))
    dq.append(next(b_iter))
    dq.append(next(b_iter))
    t = sum(dq)
    ans = t
    for x in b:
        dq.append(x)
        y = dq.popleft()
        t = t + x - y
        if ans < t:
            ans = t
    print(ans)


if __name__ == "__main__":
    main()

-def inpl(): -    return input().split() +def main(): +    from collections import deque + +    N = int(eval(input())) +    (*a,) = list(map(int, input().split())) +    b = [0] * (10**5 + 10) +    for x in a: +        b[x] += 1 +    dq = deque() +    b_iter = iter(b) +    dq.append(next(b_iter)) +    dq.append(next(b_iter)) +    dq.append(next(b_iter)) +    t = sum(dq) +    ans = t +    for x in b: +        dq.append(x) +        y = dq.popleft() +        t = t + x - y +        if ans < t: +            ans = t +    print(ans) -n = int(eval(input())) -a = list(map(int, inpl())) -d = {} -for i in range(n): -    d[a[i]] = d.get(a[i], 0) + 1 -ans = 0 -for k in list(d.keys()): -    b = 0 -    b += d.get(k - 1, 0) -    b += d.get(k, 0) -    b += d.get(k + 1, 0) -    ans = max(ans, b) -print(ans) +if __name__ == "__main__": +    main()