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):
N = int(input())
A = list(map(int, input().split()))

num = [0] * (max(A) + 1)
for i in range(N):
    num[A[i]] += 1

ans = 0
M = len(num)
for i in range(M):
    m = num[i]
    if i > 0:
        m += num[i - 1]
    if i < M - 1:
        m += num[i + 1]
    ans = max(ans, m)
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
c=Counter(a)
a=set(a)
ans=0
for aa in a:
  t=0
  t+=c[aa-1]
  t+=c[aa]
  t+=c[aa+1]
  ans=max(ans,t)
print(ans)

Solution (Python):
import collections

N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
M=collections.Counter(L)
M=sorted(M.items())
ans=max(M[i][1] for i in range(len(M)))
if len(M)==2:
	if M[0][0]+1==M[1][0] or M[0][0]+2==M[1][0]:
		ans=M[0][1]+M[1][1]
for i in range(1,len(M)-1):
	tmp=0
	tmp+=M[i][1]
	if M[i-1][0]==M[i][0]-1:
		tmp+=M[i-1][1]
	if M[i+1][0]==M[i][0]+1:
		tmp+=M[i+1][1]
	ans=max(ans,tmp)
print(ans)

Solution (Python):



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


nums = [0]*(10**5 + 1)
max_count = 0


for a in a_nums:
    nums[a] += 1


for i in range(10**5 + 1):
    if i==0 or i==10**5:
        continue

    tmp_count = nums[i-1] + nums[i] + nums[i+1]
    max_count = max(max_count, tmp_count)


print(max_count)

Solution (Python):




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


alist = list()

for i in range(n):
    alist.append(a[i]-1)
    alist.append(a[i])
    alist.append(a[i]+1)

tlist = [0] * 100002
for i in range(len(alist)):
    tlist[alist[i]] = tlist[alist[i]] + 1


print(max(tlist))

Solution (Python):
import numpy as np
import collections

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

b = a - 1
c = a + 1

x = np.concatenate([a, b, c])

y = collections.Counter(x)
print(y.most_common()[0][1])

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
C = {}
for i in range(N):
    a = A[i]
    if a not in C:
        C[a] = 0
    C[a] += 1
C = sorted(list(C.items()),key=lambda x:x[0])
cmax = 0
for i in range(len(C)):
    if i==0:
        c1 = C[0][0]
        cnt = C[0][1]
        if len(C)>1 and C[1][0]==c1+1:
            cnt += C[1][1]
        cmax = max(cmax,cnt)
    elif i==len(C)-1:
        c1 = C[-1][0]
        cnt = C[-1][1]
        if len(C)>1 and C[-2][0]==c1-1:
            cnt += C[-2][1]
        cmax = max(cmax,cnt)
    else:
        c1 = C[i][0]
        cnt = C[i][1]
        if C[i-1][0]==c1-1:
            cnt += C[i-1][1]
        if C[i+1][0]==c1+1:
            cnt += C[i+1][1]
        cmax = max(cmax,cnt)
print(cmax)

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

ans = 0
p = 0
for x, y in a.items():
    p = y
    if x-1 in a: p += a[x-1]
    if x+1 in a: p += a[x+1]
    if p > ans: ans = p
print(ans)

Solution (Python):
N=int(input())
*A,=map(int, input().split())
B=[0]*(10**5+3)
for a in A:
    a+=1
    B[a-1]+=1
    B[a]+=1
    B[a+1]+=1
print(max(B))

Solution (Python):
from sys import stdin
import sys
import math

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

dict_count = {}
for i in a:
    dict_count[i] = 0

for j in a:
    dict_count[j] += 1



max_count = 0

for key in dict_count.keys():
    max_count = max(max_count, dict_count.get(key - 1, 0) + dict_count.get(key, 0) + dict_count.get(key + 1, 0))

print(max_count)

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

cnt = {}
for i, ai in enumerate(a):
    cnt.setdefault(ai, 0)
    cnt.setdefault(ai + 1, 0)
    cnt.setdefault(ai - 1, 0)
    
    cnt[ai] += 1
    cnt[ai + 1] += 1
    cnt[ai - 1] += 1

ans = max(cnt.values())
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ret = [0] * (max(A) + 3) 

for i in range(N):
    cur = A[i]
    ret[A[i]] += 1
    ret[A[i] + 1] += 1
    ret[A[i] + 2] += 1

print(max(ret))

Solution (Python):

from collections import Counter, deque 












import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

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

    AA=Counter(A)

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


resolve()

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

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

Solution (Python):
from sys import stdin
import sys
import math

n = int(input())

a = sorted(list(map(int, stdin.readline().rstrip().split())))


count_max = 1

count_prev = 0
count_curr = 1
count_next = 0

current_value = a[0]
for i in range(1, n):
    if a[i] == current_value:
        count_curr += 1
    elif a[i] == current_value + 1:
        count_next += 1
    elif a[i] == current_value + 2:
        count_max = max(count_max, (count_prev + count_curr + count_next))
        current_value = current_value + 1
        count_prev = count_curr
        count_curr = count_next
        count_next = 1
    elif a[i] >= current_value + 3:
        count_max = max(count_max, (count_prev + count_curr + count_next))
        current_value = a[i]
        count_prev = 0
        count_curr = 1
        count_next = 0
    else:
        print("Error")

count_max = max(count_max, (count_prev + count_curr + count_next))

print(count_max)

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

ans = Counter() 
for i in range(n):
    ans[a[i]-1]+=1
    ans[a[i]]+=1
    ans[a[i]+1]+=1
print(ans.most_common(1)[0][1])

Solution (Python):
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    d = {}
    for a in A:
        for i in [-1, 0, 1]:
            if not a+i in d:
                d[a+i] = 1
            else:
                d[a+i] += 1
    print(max(d.values()))

if '__main__' == __name__:
    resolve()

Solution (Python):
import sys

def input():
    return sys.stdin.readline().strip()

def main():
    N = int(input())
    a = list(map(int,input().split()))
    cnt = [0] * (max(a) + 2)

    for i in a:
        if i != 0:
            cnt[i-1] += 1
        cnt[i] += 1
        cnt[i+1] += 1
    print(max(cnt))

if __name__ == "__main__":
    main()

Solution (Python):









import numpy as np






N = int(input())
arrA = np.array(input().split(),dtype=np.int64)

arr = np.bincount(arrA)
ans = 0
if len(arr)<=2:
    ans = sum(arr)
else:
    for i in range(len(arr)):
        if i+3>len(arr):
            break
        num = sum(arr[i:i+3])
        ans = max(ans,num)

print(ans)

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

a_l_dict = {}
for val in a_l:
    a_l_dict[val] = 0
for val in a_l:
    a_l_dict[val] += 1

ans = 0
for key in a_l_dict.keys():
    ans = max(ans, a_l_dict[key] + a_l_dict.get(key-1,0) + a_l_dict.get(key+1,0))

print(ans)

Solution (Python):


from collections import deque,Counter













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

cnt = Counter(arrA)
maxnum = max(arrA)
ans = 0
for i in range(maxnum+1):
    num = cnt[i-1] + cnt[i] + cnt[i+1]
    ans = max(ans,num)
    

print(ans)

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

Solution (Python):

import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    a=list(map(int,input().split()))
    d=defaultdict(int)
    for x in a:
        d[x]+=1
        d[x-1]+=1
        d[x+1]+=1
    ans=0
    for i in range(10**5+1):
        ans=max(ans,d[i])
    print(ans)
    
if __name__ == '__main__':
    main()

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

Solution (Python):
def myAnswer(N:int,A:list) -> int:
   if(N == 1): return 1
   dic ={}
   for a in A:
      if(a == 0):
         for i in range(2):
            if(i in dic.keys()):
               dic[i]+=1
            else:
               dic[i]=1
      else:
         for i in range(a-1,a+2):
            if(i in dic.keys()):
               dic[i]+=1
            else:
               dic[i] = 1
   return max(list(dic.values()))

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()
ans = 0

l = [0]*(max(A)+2)

for i in A:
    if i != 0:
        l[i-1] += 1
    l[i] += 1
    l[i+1] += 1

print(max(l))

Solution (Python):
import collections
N = int(input())
A = list(map(int,input().split()))
Am = [a-1 for a in A]
Ap = [a+1 for a in A]
A.extend(Am)
A.extend(Ap)

c = collections.Counter(A)
print(c.most_common()[0][1])

Solution (Python):

import sys
import collections


readline = sys.stdin.readline

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

    count = [0] * (max(A) + 3)
    for a in A:
        count[a+1] += 1
        count[a] += 1
        count[a+2] += 1

    print(max(count))


if __name__ == "__main__":
    main()

Solution (Python):
def resolve():
    '''
    code here
    '''
    import collections
    N = int(input())
    A_list = [int(item) for item in input().split()]

    new_list = []

    for item in A_list:
        new_list += [item + i for i in [-1, 0, 1]]

    item_dict = collections.Counter(new_list)
    print(max(item_dict.values()))

if __name__ == "__main__":
    resolve()

Solution (Python):
n=int(input())
g=list(map(int,input().split()))
f=max(g)
l=[0]*(f+2)
for i in g:
  for j in range(max(0,i-1),min(i+2,f+1)):
    l[j]+=1
print(max(l))

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
A_count = [0] * (max(A)+1)

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

max_count = 0
if len(A_count) < 4:
    print(sum(A_count))
else:
    for X in range(1, len(A_count)-1):
        count = A_count[X-1] + A_count[X] + A_count[X+1]
        if count > max_count:
            max_count = count
    print(max_count)

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

for i in range(n):
    cnt[a[i] - 1] += 1
    cnt[a[i] + 1] += 1
    cnt[a[i]] += 1

print(max(cnt.values()))

Solution (Python):
def ABC072C(d,i):
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
    return d


n=int(input())
a=map(int,input().split())
d=dict()
for i in a:
    d=ABC072C(d,i-1)
    d=ABC072C(d,i)
    d=ABC072C(d,i+1)
print(max(d.values()))

Solution (Python):
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
d = defaultdict(int)
for i in A:
    d[i] += 1
ans = 0
for i in range(10 ** 5):
    ans = max(ans, d[i-1] + d[i] + d[i+1])
print(ans)

Solution (Python):

from collections import defaultdict
n = int(input())
nums = [int(i) for i in input().split()]

c = defaultdict(int)
for num in nums:
    c[num - 1] += 1
    c[num] += 1
    c[num + 1] += 1

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

Solution (Python):
import sys
readline = sys.stdin.readline
from collections import Counter

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    c = Counter(A)
    mi = min(A)+1
    m = c[mi-1] + c[mi] + c[mi+1]
    ans = m
    for i in range(mi+1, max(A)):
        m -= c[i-2]
        m += c[i+1]
        ans = max(ans, m)
    
    print(ans)


if __name__ == '__main__':
    main()

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

cand = [0] * 10**5

for i in range(len(A)):
    cand[A[i]] += 1
    if A[i] < len(A)-1:
        cand[A[i]+1] += 1
    if A[i] > 0:
        cand[A[i]-1] += 1

print(max(cand))

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

cand = [0] * 10**5

for i in range(len(A)):
    cand[A[i]] += 1
    if A[i] < len(A)-1:
        cand[A[i]+1] += 1
    if A[i] > 0:
        cand[A[i]-1] += 1

print(max(cand))

Solution (Python):

import io
import math

data = int(input())
array = list(map(int,input().split()))
l = [0] * (10**5 + 2)
for x in array:
  l[x-1] += 1
  l[x] += 1
  l[x+1] += 1
print(max(l))

Solution (Python):
n = int(input())
a = sorted(list(map(int,input().split())))
d = {}

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

for v in a:
    d[v] += 1

ans = 0
for i in range(min(a),max(a)+1):
    tmp = d[i-1]+d[i]+d[i+1]
    if ans < tmp:
        ans = tmp
print (ans)

Solution (Python):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
counter = np.append(0, np.bincount(A, minlength=10**5 + 10))

cumsum = counter.cumsum()


print((cumsum[3:] - cumsum[:-3]).max())

Solution (Python):
from collections import Counter
N = int(input())
a = [int(i) for i in input().split()]
ans = dict(Counter(a))
ans1 = []
for i in range(min(a),max(a)+1):
    count = 0
    if i-1 in ans:
        count += ans[i-1]
    if i in ans:
        count += ans[i]
    if i+1 in ans:
        count += ans[i+1]
    ans1.append(count)
print(max(ans1))

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

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

for i in A:
    C[i-1] += 1
    C[i] += 1
    C[i+1] += 1

print(max(C))

Solution (Python):
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    C = [0]*10**5
    for i in range(N):
        C[A[i]] += 1
    ma = 0
    for i in range(1, len(C)-1):
        count = C[i-1] + C[i] + C[i+1]
        if count > ma:
            ma = count    
    print(ma)
if __name__ == "__main__":
    main()

Solution (Python):
import sys
input=sys.stdin.readline
















import collections
N = int(input())
A = list(map(int,input().split()))
Min = min(A)
Max = max(A)
d = {i:0 for i in range(Min,Max+1)}
for ii in A:
    d[ii] += 1
s = [0] * (Max-Min+1)
n = len(s)
s[0] = d[Min]
for k in range(1,n):
    s[k] = s[k-1] + d[Min+k]
ss = 0
if n <= 3:
    ss = s[n-1]
    print(ss)
else:
    mmax = s[2]
    for i in range(3,n):
        mmm = s[i] - s[i-3]
        mmax = max(mmm,mmax)
    print(mmax)

Solution (Python):


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

d={}

for i in range(n):
    if str(a[i]-1) in d:
        d[str(a[i]-1)]+=1
    else:
        d[str(a[i]-1)]=1
    if str(a[i]) in d:
        d[str(a[i])]+=1
    else:
        d[str(a[i])]=1
    if str(a[i]+1) in d:
        d[str(a[i]+1)]+=1
    else:
        d[str(a[i]+1)]=1

print(max(d.values()))

Solution (Python):
c = [0]*100002
input()
for x in map(int, input().split()):
  c[x] += 1
  c[x+1] += 1
  c[x+2] += 1
print(max(c))

Solution (Python):
from collections import defaultdict
N=int(input())
a_list=list(map(int,input().split()))

count = defaultdict(int)

for a in a_list:
    if a > 0:
        count[a-1] += 1
    count[a] += 1
    count[a+1] += 1

print(max(count.values()))

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

dp = [0]*(10**5+10)
for i in a:
    if i-1 >= 0:
        dp[i-1] += 1
    dp[i] += 1
    dp[i+1] += 1
print(max(dp))

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = Counter(a)
count = 1
for i in range(min(a)-1, max(a)+1):
    count = max(count, b.get(i-1,0)+b.get(i, 0)+b.get(i+1, 0))
print(count)

Solution (Python):
n=int(input());A = list(map(int,input().split(' ')))
x = [0]*100001
for a in A:
    if a != 0:
        x[a-1]+=1;x[a]+=1;x[a+1]+=1
    else:
        x[a]+=1;x[a+1]+=1
print(max(x))

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

Solution (Python):
from collections import Counter
n,*a = map(int,open(0).read().split())
c= Counter(a)
print(max([c[i]+c[i+1]+c[i+2] for i in range(min(a),max(max(a)-1,min(a)+1))]))

Solution (Python):
import collections

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

c = collections.Counter(A)
ans = 0
for i in range(min(A), max(A)+1):
    ans = max(c[i-1] + c[i] + c[i+1], ans)

print(ans)

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

def cnt(a):
    ans.setdefault(a,0)
    ans[a]+=1

ans={}
for a in an:
    cnt(a-1)
    cnt(a)
    cnt(a+1)

print(max(ans.values()))

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

i_a = list(map(lambda x: x+1, a))
d_a = list(map(lambda x: x-1, a))

new_a = a + i_a + d_a
c = collections.Counter(new_a)

sorted_c = sorted(c.values())
print(sorted_c[-1])

Solution (Python):

import sys  
import numpy as np
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
k = [0] * max(3,(max(a)+1))

for p in a:
    k[p] += 1
ans = 0
for q,r,s in zip(k, k[1:] , k[2:]):
    ans = max(ans, q+r+s)

print(ans)

Solution (Python):
import collections

n=int(input())
a=list(map(int,input().split()))
a_s=sorted(a)
a_s_p=[]
a_s_m=[]
for i in range(n):
    a_s_p.append(a_s[i]+1)
    a_s_m.append(a_s[i]-1)

all_a=a_s+a_s_p+a_s_m

mode=collections.Counter(all_a).most_common()[0][1]
print(mode)

Solution (Python):
n = int(input())
a = sorted(list(map(int, input().split())))
l = [0] * (a[-1] + 3)
for i in a:
    l[i] += 1
c = 0
for i in range(2, a[-1] + 3):
    c = max(c, l[i - 2] + l[i - 1] + l[i])
print(c)

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


count = defaultdict(int)
for n in a:
    for i in range(-1, 2):
        count[n + i] += 1

print(max(count.values()))

Solution (Python):
import collections
n=int(input())
a=list(map(int,input().split()))
a=collections.Counter(a)
ans=a[0]+a[1]

for i in range(max(a)+1):
    ans=max(ans,a[i]+a[i+1]+a[i+2])

print(ans)

Solution (Python):
import collections
n = int(input())
a = list(map(int,input().split()))
p = [0 for i in range(max(a)+3)]

for i in range(n):
    p[a[i]] += 1
    p[a[i] + 1] += 1
    p[a[i] + 2] += 1

print(max(p))

Solution (Python):
n, *A = map(int, open(0).read().split())
B = [0] * max(3, (max(A) + 1))
for a in A:
  B[a] += 1
ans = 0
for b0, b1, b2 in zip(B, B[1:], B[2:]):
  ans = max(ans, b0 + b1 + b2)
print(ans)

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    a.append(a[i]+1)
    if a[i]!=0:
        a.append(a[i]-1)
b=[0]*(1+max(a))
for ai in a:
    b[ai]+=1
print(max(b))

Solution (Python):
from collections import Counter

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

l = Counter(A)
count = [0] * (10**5 + 1)
for c in l.items():
  count[c[0]] = c[1]

ans = 0
for i in range(10**5-1):
  tmp = count[i] + count[i+1] + count[i+2]
  if tmp > ans:
    ans = tmp
print(ans)

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

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

cnt = [0 for _ in range(100005)]
for a in A:
    cnt[a] += 1

ans = 0
for i in range(1, len(cnt) - 1):
    ans = max(ans, cnt[i - 1] + cnt[i] + cnt[i + 1])

print(ans)

Solution (Python):
from collections import defaultdict

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

for i in a:
    d[i] += 1
    d[i-1] += 1
    d[i+1] += 1
d = sorted(d.items(), key=lambda x:x[1], reverse=True)
print(d[0][1])

Solution (Python):
from collections import defaultdict

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

for i in a:
    d[i] += 1
    d[i-1] += 1
    d[i+1] += 1
d = sorted(d.items(), key=lambda x:x[1], reverse=True)
print(d[0][1])

Solution (Python):
from sys import stdin
import collections

lines = stdin.readlines()
n = int(lines[0])
a_s = [int(x) for x in lines[1].rstrip().split()]


def inc(x): return x + 1


def dec(x): return x - 1


a_s_p = [inc(x) for x in a_s]
a_s_n = [dec(x) for x in a_s]

a_s = a_s + a_s_p + a_s_n
c = collections.Counter(a_s)
print(max(list(c.values())))

Solution (Python):
import sys

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

def main():
    m = 10 ** 5
    cnt = [0] * (m + 1)
    for x in a:
        cnt[x] += 1
        if x > 0: cnt[x-1] += 1
        if x < m: cnt[x+1] += 1
    print(max(cnt))

if __name__ ==  '__main__':
    main()

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

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

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

r = [0] * (10**5+2)
for i in range(N):
    r[a[i]] += 1
    r[a[i]+1] += 1
    r[a[i]+2] += 1

print(max(r))

Solution (Python):
import bisect
N = int(input())
A = sorted(list(map(int,input().split())))
ans = 1

for i in range(A[-1]+1):
    ans = max(ans,bisect.bisect_right(A,i+1) - bisect.bisect_left(A,i-1))
print(ans)

Solution (Python):
import bisect
N = int(input())
A = sorted(list(map(int,input().split())))
ans = 1

def search(A,a,b):
    import bisect
    ans = bisect.bisect_right(A,b) - bisect.bisect_left(A,a)
    return ans

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

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
ac = Counter(A)
ans = 0
for i in range(max(A)+1):
    now = 0
    if i-1 in ac:
        now += ac[i-1]
    if i in ac:
        now += ac[i]
    if i+1 in ac:
        now += ac[i+1]
    ans = max(ans,now)
print(ans)

Solution (Python):
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd



import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    n = int(input().strip())
    a = list(map(int, input().strip().split()))
    C = Counter()
    ans = 0
    for i in range(n):
        C[a[i]] += 1
        C[a[i]+1] += 1
        C[a[i]-1] += 1
        ans = max([C[a[i]], C[a[i]+1], C[a[i]-1], ans ])
    print(ans)

if __name__ == '__main__':
    main()

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

numbers = [0] * (max(a)+1)
for i in range(N):
    numbers[a[i]] += 1

ans = 0

if len(numbers) < 3:
    print(sum(numbers))
    exit()

for i in range(len(numbers)-2):
    ans = max(ans,sum(numbers[i:i+3]))

print(ans)

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

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

print(max(num))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
C = {}
for a in A:
    for k in range(-1, 2, 1):
        if a + k in C:
            C[a+k] += 1
        else:
            C[a+k] = 1
print(max(C.values()))

Solution (Python):
import numpy as np
n = int(input())
a_ls = list(map(int, input().split()))


updown_ls = [0] * (10**5 + 3)

for i in range(n):
    left = a_ls[i] 
    right = a_ls[i] + 3
    updown_ls[left] += 1
    updown_ls[right] -= 1

updown_ls.pop()
num_ls = list(np.cumsum(updown_ls))
print(max(num_ls))

Solution (Python):










"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:
    return a
  return gcd_(a,a % b) 
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""

"""def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def lcm(a,b):
  g = gcd(a,b)
  return (a * b) // g"""

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7

def main():
  n = int(input())
  LIST = readInts()
  MAX_ = [0] * (10**5 + 10) 
  for a in LIST:
    for i in range(3):
      MAX_[a+i]+=1 
  print(max(MAX_))
if __name__ == '__main__':
  main()

Solution (Python):
def main():
    N = int(input())
    a = map(int, input().split())
    d = {i: 0 for i in range(-1, 100001)}

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

    print(max(d.values()))

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = [0]*pow(10,6)
for a in A:
    B[a]+=1
    B[a+1]+=1
    B[a+2]+=1
print(max(B))

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

ans = [0 for i in range(2*10**5+2)]

for i in a:
    ans[i-1] += 1
    ans[i] += 1
    ans[i+1] += 1
    
print(max(ans))

Solution (Python):
n = int(input())
list_N = list(map(int, input().split()))
ans = [0]*2*pow(10, 5)
for num in list_N:
    ans[num-1] += 1
    ans[num] += 1
    ans[num+1] += 1

print(max(ans))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a1 = [i+1 for i in a]
a2 = [i-1 for i in a]
a3 = a+a1+a2
d = {}
for i in range(3*n):
  if a3[i] in d:
    d[a3[i]] += 1
  else:
    d[a3[i]] = 1
print(max(d.values()))

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a1 = [i+1 for i in a]
a2 = [i-1 for i in a]
a3 = Counter(a+a1+a2)
print(max(a3.values()))

Solution (Python):

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

l = [0]*(10**5+10)
for i in range(n):
    l[a[i]] += 1
    
s = 0
for j in range(1, len(l)-1):
    if  s < l[j-1] + l[j] + l[j+1]:
        s = l[j-1] + l[j] + l[j+1]
        
print(s)

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    h = [0] * (max(a) + 2)
    minus = 0
    for i in a:
        h[i] += 1
        h[i + 1] += 1
        if i == 0:
            minus += 1
        else:
            h[i - 1] += 1

    print(max(minus, max(h)))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
 
cnt = [0] * 100010
for a in A:
    if a > 0:
        cnt[a - 1] += 1
    cnt[a] += 1
    cnt[a + 1] += 1

print(max(cnt))

Solution (Python):
import collections
def solve(n, a):
    a_list = [int(i) for i in a.split()]
    count = collections.Counter()

    for i in a_list:
        count[i] += 1
        count[i+1] += 1
        count[i-1] += 1

    return max(count.values())

if __name__ == "__main__":
    n = int(input())
    a = input()
    print(solve(n, a))

Solution (Python):
from collections import Counter

N = int(input())
a = list(map(int, input().split()))
c = Counter(a)
ans = 0
for k, v in c.items():
    tmp = v + c.get(k - 1, 0) + c.get(k + 1, 0)
    if tmp > ans:
        ans = tmp

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(max(a) + 2)]

for num in a:
    if num != 0:
        b[num - 1] += 1
    b[num] += 1
    b[num + 1] += 1

print(max(b))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
cnt = [0] * ((10**5) + 1)
for i in range(n):
         cnt[a[i]] += 1
sumcnt = [0]
for i in range(len(cnt)):
         sumcnt.append(sumcnt[i]+cnt[i])
ans = 0
for i in range(len(sumcnt) - 3):
         if ans < sumcnt[i+3] - sumcnt[i]:
                  ans = sumcnt[i+3] - sumcnt[i]
print(ans)

Solution (Python):
n = int(input())
ary = list(map(int,input().split()))
counter = [0]*100000

for i in ary:
  counter[i] += 1
  
sum = 0
max = 0
for i in range(100000):
  if i == 0:
    sum = counter[i] + counter[i+1]
  elif i == 1:
    sum += counter[i+1]
  elif i == 99999:
    sum += -counter[i-2] 
  else:
    sum += counter[i+1] - counter[i-2]
  if sum > max:
    max = sum
print(max)

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

cnt = [0] * 100010
for a in A:
    if a > 0:
        cnt[a - 1] += 1
    cnt[a] += 1
    cnt[a + 1] += 1

print(max(cnt))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
b = {}
for i in a:
    if i in b.keys():
        b[i] += 1
    else:
        b[i] = 1
c = sorted(b.items())
m = len(c)
if m == 1:
    print(c[0][1])
elif m == 2:
    if c[1][0] - c[0][0] < 3:
        print(c[0][1] + c[1][1])
    else:
        print(max(c[0][1],c[1][1]))
else:
    s = 0
    for i in range(m-2):
        t = c[i][1]
        if c[i+2][0] - c[i][0] < 3:
            t += (c[i+1][1] + c[i+2][1])
        elif  c[i+1][0] - c[i][0] < 3:
            t += c[i+1][1]
        if t > s:
            s = t
    print(s)