Problem:
 Score : 300 points    Problem Statement You are given an integer sequence of length N , a_1,a_2,...,a_N .  For each 1≤i≤N , you have three choices: add 1 to a_i , subtract 1 from a_i or do nothing.  After these operations, you select an integer X and count the number of i such that a_i=X .  Maximize this count by making optimal choices.      Constraints  1≤N≤10^5  0≤a_i<10^5 (1≤i≤N)  a_i is an integer.         Input The input is given from Standard Input in the following format:  N  a_1  a_2 .. a_N       Output Print the maximum possible number of i such that a_i=X .        Sample Input 1 7
3 1 4 1 5 9 2      Sample Output 1 4  For example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4 , the maximum possible count.       Sample Input 2 10
0 1 2 3 4 5 6 7 8 9      Sample Output 2 3       Sample Input 3 1
99999      Sample Output 3 1

Solution (Python):



import sys

from collections import Counter

N = int(input())

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

ls = []

for A in a:
    ls.append(A - 1)
    ls.append(A)
    ls.append(A + 1)

c = Counter(ls)

ans = max(c.values())

print(ans)

Solution (Python):
from collections import Counter

n = int(input())
counter_a = Counter(map(int, input().split()))
maxCnt = 0
for key, value in counter_a.items():
    cnt = counter_a[key-1] + counter_a[key] + counter_a[key+1]
    maxCnt = max(maxCnt, cnt)
print(maxCnt)

Solution (Python):
import numpy as np
import scipy.stats as stats
N = int(input())
A = list(map(int,input().split()))
A = np.array(A)
A_plus = A + 1
A_minus = A - 1
A = np.append(A, A_plus)
A = np.append(A, A_minus)
print(stats.mode(A).count[0])

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict 
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  
  
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  






d=defaultdict(int)
for i in A:
    d[i-1]+=1
    d[i]+=1
    d[i+1]+=1
print(max(d.values()))

Solution (Python):
import sys
from collections import Counter

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    ans = 0
    for i in range(10 ** 5 + 1):
        ans = max(ans, C[i - 1] + C[i] + C[i + 1])
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import collections

n=int(input())
A=list(map(int,input().split()))
A.sort()
md=0
j=0
for i in range(n-1):
    while j<n:
        if A[j]-A[i]<=2:
            md = max(j-i,md)
            j+=1
        else:
            break
print(md+1)

Solution (Python):
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n = ini()
a = inl()
ans = 0
b = [0] * (10**5 + 1)
for i in a:
    b[i] += 1
for i in range(10**5-1):
    ans = max(ans, b[i] + b[i+1] + b[i+2])
print(ans)

Solution (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = ni()
A = lma()
l = max(A)
cnts = [0 for i in range(l+3)]
for a in A:
    cnts[a]+=1
    cnts[a-1] +=1
    cnts[a+1] +=1
print(max(cnts))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = [0]*(10**6)
c = int()
ans = int(0)
for i in range(len(A)):
  B[A[i]] += 1

for i in range(1,len(B)-2):
  c = 0
  c += B[i-1]
  c += B[i]
  c += B[i+1]
  if ans <= c:
    ans = c
print(ans)

Solution (Python):
import math
from itertools import groupby


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def ilen(it):
    return sum(1 for _ in it)


def solve():
    N = read_int()
    A = read_ints()
    A.sort()
    grouped = [(a, ilen(v)) for a, v in groupby(A)]
    max_count = -math.inf
    for i in range(len(grouped)):
        count = grouped[i][1]
        if i > 0 and grouped[i][0]-1 == grouped[i-1][0]:
            count += grouped[i-1][1]
        if i < len(grouped)-1 and grouped[i][0]+1 == grouped[i+1][0]:
            count += grouped[i+1][1]
        max_count = max(max_count, count)
    return max_count


if __name__ == '__main__':
    print(solve())

Solution (Python):


import sys
read = sys.stdin.read
readline = sys.stdin.readline


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

from collections import Counter
d = Counter(a + [i+1 for i in a]+[i-1 for i in a])
print(max(d.values()))

Solution (Python):
from collections import Counter
N = int(input())

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

d = Counter(A)

ans = 0
for k in d.keys():
    tmp = d[k-1] + d[k] + d[k+1]
    ans = max(ans, tmp)
print(ans)

Solution (Python):
from collections import Counter
N = int(input())

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

d = Counter(A)

ans = 0
for i in range(1, 10**5+1):
    tmp = d[i-1] + d[i] + d[i+1]
    ans = max(tmp, ans)
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
m=[0]*(10**5+2)
for i in a:
  m[i]+=1
  m[i+1]+=1
  m[i+2]+=1
print(max(m))

Solution (Python):
import sys
import collections
input = lambda: sys.stdin.readline()
exec("try:sys.stdin=open('in.txt','r');sys.stdout=open('out.txt','w')\nexcept:pass")

N = int(input())
A = list(map(int, input().split()))
d = collections.Counter()
for i in range(N):
    d[A[i] + 1] += 1
    d[A[i]] += 1
    d[A[i] - 1] += 1
print(max(list(d.values())))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
d = [0] * (10**5 + 2)
neg_count = 0
for i in range(len(a)):
  d[a[i] - 1] += 1
  d[a[i]] += 1
  d[a[i] + 1] += 1
ans = max(d)
print(ans)

Solution (Python):
import sys
from itertools import accumulate


def main():
    n, *A = 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()

Solution (Python):
import sys
import bisect


def main():
    n, *a = 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()

Solution (Python):
import sys
from collections import Counter, defaultdict


def main():
  _, *a = map(int, sys.stdin.read().split())
  c = defaultdict(int, Counter(a))
  res = max(c[i - 1] + c[i] + c[i + 1] for i in range(max(a) + 1))
  print(res)


if __name__ == '__main__':
  main()

Solution (Python):

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

ans = [0] * 100000

for i in range(len(a)):
  if a[i] != 0:
    ans[a[i]-1] += 1
  ans[a[i]] += 1
  if a[i] != 99999:
    ans[a[i]+1] += 1
  
print(max(ans))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
from collections import Counter

c=Counter([j+i for i in (0,-1, 1) for j in a])
ans=c.most_common(1)
print(ans[0][1])

Solution (Python):
A=int(input())
n_l=list(map(int,input().split()))
import collections
ans=0
n_l=collections.Counter(n_l)
for i in range(0,100001):
   ans=max(ans,n_l[i]+n_l[i+1]+n_l[i+2])
print(ans)

Solution (Python):



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


def main():
    d = {i: 0 for i in range(-1, 10 ** 5 + 2)}
    for a in A:
        d[a] += 1

    ans = 0
    for i in range(max(A) + 1):
        s = d[i - 1] + d[i] + d[i + 1]
        ans = max(ans, s)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter
N = int(input())
a = map(int, input().split())
c = Counter(a)
ans = 0
for i in c:
  t = c[i-1] + c[i] + c[i+1]
  if ans < t:
    ans = t
print(ans)

Solution (Python):
import collections
N = int(input())
a = map(int, input().split())
c = collections.Counter(a)
ans = 0
for i in c:
  t = c[i-1] + c[i] + c[i+1]
  if ans < t:
    ans = t
print(ans)

Solution (Python):
input()
A = list( map(int, input().split()))
d = {}
for i in A:
  a,b,c = i-1,i,i+1
  for j in [a,b,c]:
    if j in d:
      d[j] +=1
    else:
      d[j] = 1
print(sorted(d.items(), key = lambda x:x[1])[-1][1])

Solution (Python):
import collections

N = int(input())
a = list(map(int, input().split()))
a.sort()
c = collections.Counter(a)

cnt = []
tmp = a[0]
cnt1 = 1
for i in range(1, N):
    if(abs(tmp-a[i]) <= 2):
        cnt1 += 1
    else:
        cnt.append(cnt1)
        if(a[i]-a[i-1] <= 1):
            cnt1 = c.get(a[i-1]-1, 0)+c.get(a[i-1], 0)+1
            tmp = a[i-1]-1
        else:
            cnt1 = 1
            tmp = a[i]
if(len(cnt) > 0):
    print(max(cnt1, max(cnt)))
else:
    print(cnt1)

Solution (Python):
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
cnt_dic=defaultdict(int)
for i in range(n):
  v=a[i]
  cnt_dic[v+1]+=1
  cnt_dic[v]+=1
  cnt_dic[v-1]+=1
ans=0
for key in cnt_dic.keys():
  ans=max(ans,cnt_dic[key])
print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
Acount = [0] * (max(A) + 1)
ans = 0

for i in range(n):
    Acount[A[i]] = Acount[A[i]] + 1

for i in range(1, max(A)):
    ans = max(ans, Acount[i - 1] + Acount[i] + Acount[i + 1])

if max(A) == 0 or max(A) == 1:
    ans = len(A)

print(ans)

Solution (Python):
import collections
n=int(input())
a=list(map(int,input().split()))
l=[]
for x in a:
    l.append(x-1)
    l.append(x)
    l.append(x+1)
print(collections.Counter(l).most_common()[0][1])

Solution (Python):
from collections import defaultdict
n = int(input())
ns = list(map(int, input().split()))
dic = defaultdict(int)
max_n = 0
for i in ns:
    dic[i] += 1
    max_n = max(max_n, i)
result = 0

for i in ns:
    result = max(result, dic[i]+dic[i+1]+dic[i-1])
print(result)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n=ii()
arr=limii()

a=max(arr)

mat=[0]*(a+3)

for i in range(n):
    mat[arr[i]]+=1
    mat[arr[i]+1]+=1
    mat[arr[i]+2]+=1
print(max(mat))

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n=ii()
mat=limii()

a=max(mat)



arr = [0] * (a+3)


for jj in range(n):
    l, r = mat[jj],mat[jj]+2  
    arr[l] += 1
    if r+1 != a+3:
        arr[r+1] -= 1


cum = [0] * (a+3)
for i in range( a+3):
    cum[i] += cum[i-1] + arr[i]


ans = max(cum[1:])
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))

ans=[0 for _ in range(10**5+3)]
for i in a:
    ans[i+1]+=1
    ans[i+2]+=1
    ans[i]+=1

print(max(ans))

Solution (Python):
from collections import defaultdict
N, = map(int, input().split())
X = list(map(int, input().split()))
d = defaultdict(int)
for x in X:
    d[x] += 1

r = 0
for i in range(10**6):
    r = max(r, d[i] + d[i-1] + d[i+1])
print(r)

Solution (Python):
import sys
import math
import fractions
import bisect
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

'''

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

can = [0]*(int(1e5+10))
for n in A:
    can[n] += 1
    can[n-1] += 1
    can[n+1] += 1

ans = 0
big = 0
for i in range(int(1e5+1)):
    if big < can[i]:
        big = can[i]
        ans = i

print(big)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
count_list = [0 for i in range(0, 10**5+1)]
for a in A:
    for i in range(-1, 2, 1):
        if a+i >= 0:
            count_list[a+i] += 1
print(max(count_list))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
B=[0]*(10**5+1)
for i in range(0,N):
    B[A[i]]=B[A[i]]+1
m=B[0]
for i in range(0,10**5):
    x=0
    if i==0:
        x=B[0]+B[1]
        if x>m:
            m=x
    else:
        x=B[i-1]+B[i]+B[i+1]
        if x>m:
            m=x
print(m)

Solution (Python):
import collections

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

nums = []
roll = [-1,0,1]

for i in range(N):
  for j in range(3):
    d = A[i] + roll[j]
    nums.append(d)

num = collections.Counter(nums).most_common()
print(num[0][1])

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
from _collections import defaultdict
from functools import lru_cache

class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def map_int():
        return [int(x) for x in Scanner.string().split()]
    def string_list(n):
        return [input() for i in range(n)]
    def int_list_list(n):
        return [Scanner.mapInt() for i in range(n)]
    def int_cols_list(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True

MOD = int(1e09) + 7

def main():
    N = Scanner.int()
    A = Scanner.map_int()
    M = defaultdict(int)
    for i in range(N):
        M[A[i]] +=1
        M[A[i] + 1]+=1
        M[A[i] - 1]+=1
    ans = 0
    for v in M.values():
        ans = max(ans,v)
    print(ans)
    return

if __name__ == "__main__":
    main()

Solution (Python):
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))
    C = defaultdict(int)
    for a in A:
        C[a] += 1

    ans = 0
    for i in range(10**5+1):
        ans = max(ans, C[i-1] + C[i] + C[i+1])
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
L = [0 for i in range(max(A)+1)]
for i in range(N):
  L[A[i]] += 1
mL = []
if len(L) >= 3:
  for j in range(len(L)-2):
    mL.append(L[j] + L[j+1] + L[j+2])
else:
  for j in range(3-len(L)):
    L.append(0)
  mL = [L[0]+L[1]+L[2]]
print(max(mL))

Solution (Python):
from collections import Counter
n=input()
a=[int(i) for i in input().split()]
num=a+[i+1 for i in a]+[i-1 for i in a]
print(Counter(num).most_common(1)[0][1])

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
t = [0] * (max(a) + 2)
for x in a:
  if x > 0: t[x - 1] += 1
  t[x] += 1
  t[x + 1] += 1
print(max(t))

Solution (Python):
n = int(input())
As = list(map(int,input().split()))

lst = [0 for i in range(100009)]
for a in As:
  lst[a-1] += 1
  lst[a] += 1
  lst[a+1] += 1
print(max(lst))

Solution (Python):
n = int(input())
dic = {}
for a in map(int, input().split()):
    for i in range(a-1, a+2):
        if i not in dic:
            dic[i] = 0
        dic[i] += 1
print(max(dic.values()))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
d={}
mina=min(a)
maxa=max(a)
for i in range(mina-1,maxa+2):
  d[i]=0
for i in a:
  d[i]+=1
ans=0
for i in range(mina,maxa+1):
  ans=max(ans,d[i-1]+d[i]+d[i+1])
print(ans)

Solution (Python):
input()
L = list(map(int, input().split()))
m = min(L)
M = max(L)
a = [0]*(M-m+3)
for i in L:
    a[i-m] += 1
    a[i-m+1] += 1
    a[i-m+2] += 1
print(max(a))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
d = [0 for _ in range(10 ** 5 + 10)]

for i in range(n):
    d[max(a[i] - 1, 0)] += 1
    d[a[i] + 2] -= 1
for i in range(1, n + 1):
    d[i] += d[i - 1]


print(max(d))

Solution (Python):
n = int(input())
dic = {}

for i in map(int, input().split()):
    for j in range(i-1, i+1+1):
        if j not in dic:
            dic[j] = 0
        dic[j] += 1

print(max(dic.values()))

Solution (Python):
import collections
n = int(input())
a = list(map(int, input().split()))
ls = []
for i in a:
    ls.append(i)
    ls.append(i + 1)
    ls.append(i - 1)
ls = collections.Counter(ls).most_common(1)
print(ls[0][1])

Solution (Python):
n=int(input())
A=sorted(list(map(int,input().split())))
L={}
if n==1:
        print(1)
elif n==2:
    if abs(A[0]-A[1])==1:
        print(2)
    else:
        print(1)
else:
    for i in A:
        if i not in L:
            L[i]=1
        else:
            L[i]+=1
    ans=[]
    for j in range(A[0],A[-1]+1):
        if (j in L) and (j-1 in L) and (j+1 in L):
            ans.append(L[j]+L[j+1]+L[j-1])
        elif (j in L) and (j-1 in L):
            ans.append(L[j-1]+L[j])
        elif (j in L) and (j+1 in L):
            ans.append(L[j+1]+L[j])
        elif (j-1 in L) and (j+1 in L):
            ans.append(L[j+1]+L[j-1])
        elif (j in L):
            ans.append(L[j])
    print(max(ans))

Solution (Python):


import copy
import sys
import math

n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

hoge.sort()
hoge.append(-1)
a=0
b=0
c=1
maxhoge=0
for i in range(0,n):
	if(hoge[i]!=hoge[i+1]):
		if(i!=n-1):
			if(hoge[i+1]-hoge[i]==1):
				a=b
				b=c
				c=1
			elif(hoge[i+1]-hoge[i]==2):
				a=c
				b=0
				c=1
			else:
				a=0
				b=0
				c=1
	else:
		c+=1


	maxhoge=max(maxhoge,a+b+c)




print(maxhoge)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

counts = {}

for a in A:
    if a in counts:
        counts[a] += 1
    else:
        counts[a] = 1
        
    if a - 1 in counts:
        counts[a - 1] += 1
    else:
        counts[a - 1] = 1
        
    if a + 1 in counts:
        counts[a + 1] += 1
    else:
        counts[a + 1] = 1
        
print(max(counts.values()))

Solution (Python):
a = int(input())
b = list(map(int, input().split()))
c = {}
for i in b:
    if i not in c:
        c[i] = 1
    else:
        c[i] += 1
    if i+1 not in c:
        c[i+1] = 1
    else:
        c[i+1] += 1
    if i-1 not in c:
        c[i-1] = 1
    else:
        c[i-1] += 1
c = sorted(c.items(), key=lambda x: x[1], reverse=True)
print(c[0][1])

Solution (Python):
N = int(input())
dic = {}
for i in range(10 ** 5):
    dic[i] = 0
dic[-1] = 0
dic[10 ** 5] = 0

A = list(map(int,input().split()))
for a in A:
    dic[a] += 1
    dic[a-1] += 1
    dic[a+1] += 1

ans = 0
for v in dic.values():
    ans = max(ans, v)
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
num = [0 for i in range(200000)]
for i in range(N):
    num[A[i]-1] += 1
    num[A[i]] += 1
    num[A[i]+1] += 1
print(str(max(num)))

Solution (Python):
from collections import Counter
n = int(input())
cnt = Counter(map(int, input().split()))
res = max(v + cnt.get(k - 1, 0) + cnt.get(k - 2, 0) for k, v in cnt.items())
print(res)

Solution (Python):

def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    ans = [0] * 100001
    for i in lst:
        ans[i] += 1
    print(max(map(sum, zip(ans, ans[1:], ans[2:]))))


if __name__ == "__main__":
    main()

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    return


def B():
    return


def C():
    return


def D():
    n = I()
    a = LI()
    f = defaultdict(int)
    for i in a:
        f[i-1] += 1
        f[i] += 1
        f[i+1] += 1
    print(max(f.values()))
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


def I_():
    return


def J():
    return


if __name__ == "__main__":
    D()

Solution (Python):
N = int(input())
li = [ int(it) for it in input().split() ]

dp=[0]*(100000+11)

for it in li:
  dp[it] += 1
  dp[it+1] += 1
  dp[it+2] += 1
  
ma = 0
for it in dp:
  ma = max(it,ma)

print ( ma )

Solution (Python):

n = int(input())
lst = list(map(int, input().rstrip().split()))
ans = [0] * 100001
for i in lst:
    ans[i] += 1
print(max(map(sum, zip(ans, ans[1:], ans[2:]))))

Solution (Python):
input();a=[0]*100000
for i in input().split():a[int(i)]+=1
print(max(map(sum,zip(a,a[1:],a[2:]))))

Solution (Python):
N = int(input())
A = map(int,input().split())

dic = {}
for a in A:
    for i in [-1,0,1]:
        dic[a+i] = dic.get(a+i,0) + 1

m = 0
ans = 0
for d in dic:
    if dic[d] > m:
        ans = d
        m = dic[d]
print(m)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))

cnt = [0]*(10**6)

for a in A:
    cnt[a] += 1
    cnt[a+1] += 1
    cnt[a+2] += 1

ans = max(cnt)
print(ans)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))

b = [0 for i in range(-1,max(a)+2)]
for x in a:
  b[x-1]+=1
  b[x]+=1
  b[x+1]+=1
print(max(b))

Solution (Python):
from collections import defaultdict

N = int(input())
As = map(int, input().split())

counts = defaultdict(int)
for a in As:
    counts[a-1] += 1
    counts[a] += 1
    counts[a+1] += 1

print(max(counts.values()))

Solution (Python):
import collections
N=int(input())
A=list(map(int,input().split(' ')))
counter=collections.Counter(A)
Y=sorted(list(counter.keys()))
ans=-1
if max(Y)-min(Y)<=2:
  ans=N
else:
  Y_all = [ counter[i] for i in range(min(Y),max(Y)+1) ]
  for i in range(len(Y_all)-2):
    ans = max(sum(Y_all[i:i+3]), ans)
print(ans)

Solution (Python):
N = int(input())
a = [int(_) for _ in input().split()]
ans = [0]*(10**5+1)

for i in a:
    if i != 0:
        ans[i-1] += 1
        ans[i] += 1
        ans[i+1] += 1
    else:
        ans[i] += 1
        ans[i+1] += 1

print(max(ans))

Solution (Python):
from collections import Counter
n = int(input())
d = Counter(map(int, input().split()))
cnt = 0
for i in d:
  new = d.get(i,0) + d.get(i-1,0) + d.get(i+1,0)
  if new > cnt:
    cnt = new
print(cnt)

Solution (Python):
input();a=[0]*100000
for i in input().split():a[int(i)]+=1
print(max(map(sum,zip(a,a[1:],a[2:]))))

Solution (Python):
input();a=[0]*100000
for i in input().split():a[int(i)]+=1
print(max(map(sum,zip(a,a[1:],a[2:]))))

Solution (Python):
input();a=[0]*100000
for i in map(int,input().split()):a[i]+=1
print(max(map(sum,zip(a,a[1:],a[2:]))))

Solution (Python):
from collections import Counter

if __name__ == '__main__':
    n = int(input())
    a = [int(s) for s in input().split()]
    print(max(Counter(a + [x - 1 for x in a] + [x + 1 for x in a]).values()))

Solution (Python):
N = int(input())

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

counter = [0] * 100001

for a in A:
  if a:
    counter[a-1]+=1
    counter[a]+=1
    counter[a+1]+=1
  else:
    counter[a]+=1
    counter[a+1]+=1

print(max(counter))

Solution (Python):
N = input()
d = {}
for a in map(int, raw_input().split()):
  d[a - 1] = d.get(a - 1, 0) + 1
  d[a] = d.get(a, 0) + 1
  d[a + 1] = d.get(a + 1, 0) + 1
print max(d.values())

Solution (Python):
N=input()
a=list(map(int,input().split()))

x=[0 for i in range(-1,10**5+10)]

for i in a:
        x[i-1]+=1
        x[i]+=1
        x[i+1]+=1

x=sorted(x)

for i in reversed(x):
        if(not i<0):
                print(i)
                exit()

Solution (Python):


"""
Created on Sun Feb 10 10:05:08 2019

@author: shinjisu
"""



def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def dmp(x):
    global debug
    if debug:
        print(x)
    return x


def probC():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    maxA = max(A)
    dmp(maxA)
    b = zeros(maxA+3)
    for i in range(N):
        b[A[i]] += 1
        b[A[i]+1] += 1
        b[A[i]+2] += 1
    dmp(b)
    return dmp(max(b))


debug = False  
print(probC())

def probCTLE2():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    hist = zeros(10**5)
    for i in range(N):
        if A[i] in hist:
            hist[A[i]] += 1
        else:
            hist[A[i]] = 1
    
    mxCnt = 1
    
    
    
    for k in range(10**5-2):
        cnt = hist[k] + hist[k+1] + hist[k+2]
        mxCnt = max(mxCnt, cnt)
    return mxCnt


def probCTLE():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    hist = {}
    for i in range(N):
        if A[i] in hist:
            hist[A[i]] += 1
        else:
            hist[A[i]] = 1
    dmp(hist)
    mxCnt = 1
    keylist = list(hist.keys())
    mxKey = max(keylist)
    dmp(mxKey)
    for k in hist.keys():
        cnt = 0
        if k-1 in keylist:
            cnt += hist[k-1]
        if k in keylist:
            cnt += hist[k]
        if k+1 in keylist:
            cnt += hist[k+1]
        mxCnt = max(mxCnt, cnt)
        dmp(('max',mxCnt))
    return mxCnt


def probCWA():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    hist = {}
    for i in range(N):
        if A[i] in hist:
            hist[A[i]] += 1
        else:
            hist[A[i]] = 1
    dmp(hist)
    mxCnt = 1
    keylist = list(hist.keys())
    mxKey = max(keylist)
    dmp(mxKey)
    for i in range(mxKey-1):
        cnt = 0
        if i in keylist:
            cnt += hist[i]
        if i+1 in keylist:
            cnt += hist[i+1]
        if i+2 in keylist:
            cnt += hist[i+2]
        mxCnt = max(mxCnt, cnt)
        dmp(('max',mxCnt))
    return mxCnt

Solution (Python):
s=[0]*(10**5+2)
n=int(input())
a=list(map(int,input().split()))
for i in a:
    s[i-1]+=1
    s[i]+=1
    s[i+1]+=1
print(max(s))

Solution (Python):


def main():
    N = int(input())
    a = list(map(int, input().split()))

    a.sort()
    r = 0
    i, j = 0, 0
    while i < N:
        while j < N:
            if a[j] - a[i] <= 2:
                j += 1
            else:
                break
        r = max(r, j - i)
        if j == N:
            break
        i += 1

    print(r)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

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

for i in A:
    l[i] += 1

ans = 0
for a, b, c in zip(l, l[1:], l[2:]):
    ans = max(ans, a+b+c)

print(ans)

Solution (Python):
import collections

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

counter = collections.defaultdict(int)
for b in a:
    counter[b - 1] += 1
    counter[b] += 1
    counter[b + 1] += 1

print(max(counter.values()))

Solution (Python):
import collections


N = int(input())
A = list(map(int, input().split(' ')))
A_plus = [A[i]+1 for i in range(len(A))]
A_minus = [A[i]-1 for i in range(len(A))]
ans = collections.Counter(A + A_plus + A_minus).most_common()[0][1]
print(ans)

Solution (Python):
N = int(input())
def inpl(): return [int(i) for i in input().split()]
ctr = [0 for _ in range(10**5+2)]
a = inpl()
for i in a:
     ctr[i] += 1
subsum = ctr[0] + ctr[1] + ctr[2]
ans = subsum
for i in range(2,10**5+1):
    subsum = subsum - ctr[i-2] + ctr[i+1]
    ans = max(ans, subsum)
print(ans)

Solution (Python):
lis=[0]*((10**5)+10)
N=int(input().strip())
a=list(map(int, input().split()))
for i in range(N):
    lis[a[i]-1]+=1
    lis[a[i]]+=1
    lis[a[i]+1]+=1
lis.sort(reverse=True)
print(lis[0])

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]

import collections

cnt = collections.Counter(A)

minval = min(A)
maxval = max(A)

ret = 0
for i in range(minval, maxval+1):
    s = cnt[i - 1] + cnt[i] + cnt[i + 1]
    ret = max([ret, s])

print(ret)

Solution (Python):
import collections
n=input()
counter=collections.Counter(map(int, raw_input().split()))
print max([counter[a-1]+counter[a]+counter[a+1] for a in counter])

Solution (Python):
import collections
n=input()
counter=collections.Counter(map(int, raw_input().split()))
print max([counter[a-1]+counter[a]+counter[a+1] for a in counter])

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

count = [0 for _ in range(10 ** 5 + 1)]
for a in A:
    count[a] += 1

ret = 0

for i in range(1, 10 ** 5):
    ret = max(ret, count[i - 1] + count[i] + count[i + 1])

print(ret)

Solution (Python):
N = int(input())
L = [0 for i in range(100003)]

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

for i in range(N):
	L[a[i] - 1] += 1
	L[a[i]] += 1
	L[a[i] + 1] += 1

print(max(L))

Solution (Python):
from collections import defaultdict,Counter
N=int(input())
A=[int(i) for i in input().split()]
dd=defaultdict(int)
for a in A:
    dd[a]+=1
    dd[a-1]+=1
    dd[a+1]+=1
print(Counter(dd).most_common(1)[-1][-1])

Solution (Python):
import collections

n = int(input())
a = list(map(int, input().split()))
ac = collections.Counter(a)
ans = 0
for i in range(min(a) - 1, max(a) + 2):
    ans = max(ans, ac[i - 1] + ac[i] + ac[i + 1])
print(ans)