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

arr = [0] * (10**5 + 2)
for i in range(n):
    arr[a[i]] += 1
ans = []
for x in range(1,10**5):
    ans.append(arr[x-1] + arr[x] + arr[x+1])

print(max(ans))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
L=[0 for i in range(100001)]
result=0

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

for i in range(100001-2):
    if L[i]+L[i+1]+L[i+2]>result:
        result=L[i]+L[i+1]+L[i+2]

print(result)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = [int(i) for i in input().split()]
aa = a[:]
aaa = a[:]
for i in range(N) :
    aa[i] -=1
for i in range(N) :
    aaa[i] += 1
A = a + aa + aaa
import collections
c = collections.Counter(A)
li = list(c.values())
li.sort()
print(li[-1])

Solution (Python):
N = int(input())
alist = list(map(int, input().split()))
from collections import Counter
acounter = Counter(alist)
ans = 0
for num in acounter.keys():
    ans = max(ans, acounter[num - 1] + acounter[num] + acounter[num + 1])
print(ans)

Solution (Python):
from collections import Counter
input()
A = list(map(int, input().split()))
C = Counter(A)
def get(i): return C[i] if i in C else 0
print(max(sum(get(x) for x in range(i-1,i+2)) for i in range(10**5)))

Solution (Python):
from collections import Counter

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

ans = []
for i in a:
    ans.append(i)
    ans.append(i-1)
    ans.append(i+1)

mc = Counter(ans).most_common()[0][1]
print(mc)

Solution (Python):
from collections import defaultdict
N = int(input())
actions = [int(i) for i in input().split()]

d = defaultdict(int)
for a in actions:
    d[a-1] += 1
    d[a] += 1
    d[a+1] += 1
print(sorted(d.items(), key=lambda x: -x[1])[0][1])

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

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

main()

Solution (Python):
from collections import defaultdict

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

hoge = defaultdict(int)
for ai in a:
  hoge[ai+1] += 1
  hoge[ai] += 1
  hoge[ai-1] +=1
print(max(hoge.values()))

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

from collections import Counter
Z = []

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

print(Counter(Z).most_common()[0][1])

Solution (Python):
import sys
from collections import Counter
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(a_ls)
_max = max(a_ls)
_min = min(a_ls)
best = 0
for i in range(_min, _max + 1):
    best = max(ct[i] + ct[i+1] + ct[i-1], best)
print(best)

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

Solution (Python):
import collections

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

x = []
x_append = x.append

for a in A:
    x_append(a-1)
    x_append(a)
    x_append(a+1)
    
X = collections.Counter(x)

print(X.most_common()[0][1])

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

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
cnt = [0]*(max(a)+1)

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

if len(cnt) < 3:
    ans = sum(cnt)
else:
    for i in range(len(cnt)-2):
        ans = max(ans,cnt[i]+cnt[i+1]+cnt[i+2])

print(ans)

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

li=[]
for i in a:
  li+=[i-1,i,i+1]

from collections import Counter
c=Counter(li)
print(c.most_common()[0][1])

Solution (Python):
n = int(input())
as_ = map(int, input().strip().split())

data = [0] * 100002

for a in as_:
    data[a] += 1

max_count = 0
for i in range(1, 100001):
    count = data[i - 1] + data[i] + data[i + 1]
    max_count = max(count, max_count)

print(max_count)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
m,M=min(A),max(A)
from collections import Counter
A=Counter(A)
ans = 0
for _ in range(m,M+1):
  ans = max(ans,A[_-1]+A[_]+A[_+1])
print(ans)

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

l = [0 for _ in range(mx+4)]


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

lmax = max(l)

print(lmax)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()

cnt = [0]*10**5

for n in a:
	cnt[n] += 1

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

print(ans)

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

Solution (Python):
from bisect import bisect_left,bisect_right
N = int(input())
A = sorted(list(map(int,input().split())))
G = {i:0 for i in range(10**5)}
cntmax = 0
for i in range(10**5):
    ind0 = bisect_left(A,i-1)
    ind1 = bisect_right(A,i+1)
    cntmax = max(cntmax,ind1-ind0)
print(cntmax)

Solution (Python):
import collections
N=int(input())
s=list(map(int,input().split(' ')))
cand = []
for i in s:
    cand.append(i+1)
    cand.append(i-1)
cand += s
ans = max(collections.Counter(cand).values())
print(ans)

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

ans = [0]*(max(A)+3)
for a in A:
  ans[a-1] += 1
  ans[a] += 1
  ans[a+1] += 1
  
print(max(ans))

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

Solution (Python):
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import fractions
from functools import reduce
from operator import mul
import bisect
import sys
import logging
import heapq
import itertools

logging.basicConfig(level=logging.ERROR)

input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	n = int(input())
	a = list(map(int,input().split()))
	d = defaultdict(int)
	for i in a:
		d[i-1] += 1
		d[i]   += 1
		d[i+1] += 1
	ans = -1
	for i in range(-1,max(a)+3):
		if(d[i] > ans):
			ans = d[i]
	print(ans)

main()

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
l=[]
for i in range(N):
    l.extend([a[i]-1,a[i],a[i]+1])

import collections
c=collections.Counter(l)

print(c.most_common()[0][1])

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

tmp = [0] * (max(a)+3)

for i in a:
    for j in range(i-1,i+2):
        tmp[j+1] += 1

print(max(tmp))

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

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

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

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


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

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

for i in range(len(A)):
    up = A[i]+1
    down = A[i]-1
    no = A[i]
    L[up]=L[up]+1
    L[down]=L[down]+1
    L[no] = L[no]+1

print(max(L))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = LI()
    freq = [0] * (10**5)
    for a in A:
        freq[a] += 1
    ans = -1
    for i in range(len(freq)):
        if i == 0:
            l = 0
        else:
            l = freq[i-1]

        m = freq[i]

        if i == len(freq)-1:
            r = 0
        else:
            r = freq[i+1]
        ans = max(ans, l + m + r)
    print(ans)
main()

Solution (Python):
N=int(input())
a=list(map(int, input().split()))
a.sort()
nums=[0]*(10**5+1)
for i in range(N):
  nums[a[i]]+=1
maxsum=0
for x in range(1, 10**5-1):
  tmp=nums[x-1]+nums[x]+nums[x+1]
  if maxsum<tmp:
    maxsum=tmp
print(maxsum)

Solution (Python):




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

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

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

print(x)

Solution (Python):
import collections

n = int(input())
A=list(map(int, input().split()))
C = collections.Counter(A)

ans = 0
for k,v in C.items():
    ans = max(ans,C[k]+C[k-1]+C[k+1])

print(ans)

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

cc = collections.Counter(a)
cc = dict(sorted(cc.items(), key=lambda x: x[1], reverse=True))

ans = 0
for k, v in cc.items():
    t = cc[k]
    if k+1 in cc:
        t += cc[k+1]
    if k-1 in cc:
        t += cc[k-1]

    ans = max(ans, t)

print(ans)

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

dic={}
for v in al:
    if not v in dic.keys():
        dic[v]=1
    else:
        dic[v]=dic[v]+1
count_l=[]
for v in range(min(al)-1,max(al)+2):
    count=0
    count=dic.get(v-1,0)+dic.get(v,0)+dic.get(v+1,0)
    count_l.append(count)
print(max(count_l))

Solution (Python):
import bisect
n=int(input())
a=[int(i) for i in input().split()]
b=[0]*(10**5)
for i in range(n):
    b[a[i]]+=1
ma=0
for i in range(1,10**5-1):
    ma=max(b[i-1]+b[i]+b[i+1],ma)
print(ma)

Solution (Python):
import bisect
n=int(input())
a=sorted([int(i) for i in input().split()])

ma=0
for i in range(10**5):
    ma=max(bisect.bisect_right(a,i+1)-bisect.bisect_left(a,i-1),ma)
print(ma)

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

t = max(a)
num_list = [0] * (t + 2)

for i in range(n):
    num_list[a[i]] += 1
    if a[i] == 0:
        continue
    else:
        num_list[a[i]-1] += 1
    if a[i] == t:
        continue
    else:
        num_list[a[i]+1] += 1

print(max(num_list))

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

N = int(input())
A = [int(_) for _ in input().split()]

dict = defaultdict(int)
for n in range(N):
    dict[A[n]] += 1
    dict[A[n] + 1] += 1
    if A[n] - 1 >= 1:
        dict[A[n] - 1] += 1

count = sorted(dict.items(), key=lambda x: -x[1])
print(count[0][1])


"""A = Counter(sorted([int(_) for _ in input().split()])).items()
if N == 1:
    print(1)
    sys.exit()

A = list(A)
ans = 0
for n in range(1, len(A) - 1):
    tmp = A[n][1]
    if A[n - 1][0] + 1 == A[n][0]:
        tmp += A[n - 1][1]
    if A[n][0] + 1 == A[n + 1][0]:
        tmp += A[n + 1][1]
    ans = max(ans, tmp)
print(ans)
"""

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
X = [0]*(10**5+2)
for x in A:
  X[x-1] += 1
  X[x] += 1
  X[x+1] += 1
answer = max(X)
print(answer)

Solution (Python):
import sys
input = sys.stdin.readline
import collections
N = int(input())
a = [int(x) for x in input().split()]
c = collections.Counter(a)
X = -100
X_c = 0
for i in range(min(a) - 1, max(a) + 2):
    temp = c[i-1] + c[i] + c[i+1]
    if temp >= X_c:
        X = i
        X_c = temp
print(X_c)

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

Solution (Python):
import sys
from collections import defaultdict

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

def main():
    res = defaultdict(int)
    for i in a:
        res[i-1] += 1
        res[i] += 1
        res[i+1] += 1

    return max(res.values()) 
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
n,*a=map(int,open(0).read().split())
b,c=[],[]
for i in a:
  b.append(i-1)
  c.append(i+1)
d=a+b+c
from collections import Counter
e=Counter(d)
f=e.most_common()
print(f[0][1])

Solution (Python):
import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  
rs = lambda: stdin.readline().rstrip()  

N = ri()
A = np.array(rl())
c = np.bincount(A)
if len(c) == 1:
    answer = c[0]
else:
    answer = c[0] + c[1]

for i in range(1, len(c)-1):
    result = c[i-1] + c[i] + c[i+1]
    if result > answer:
        answer = result

print(answer)

Solution (Python):
import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  
rs = lambda: stdin.readline().rstrip()  

N = ri()
A = np.array(rl())
c = np.bincount(A)
answer = c[0]

for i in range(1, len(c)-1):
    result = c[i-1] + c[i] + c[i+1]
    if result > answer:
        answer = result

print(answer)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
f = [0 for i in range(100000 + 10)]
for x in a:
	f[x] = f[x] + 1
mx = f[0] + f[1]
for i in range(1, 100000 + 1):
	mx = max(mx, f[i - 1] + f[i] + f[i + 1])
print(mx)

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

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

Memory = {}


for i in a:
  p = i + 1
  q = i
  r = -1
  if i >= 0: 
    r = i-1 
  
  
  if p in Memory:
    Memory[p] += 1
  else:
    Memory[p] = 1
  if q in Memory:
    Memory[q] += 1
  else:
    Memory[q] = 1
  if r != -1:
    if r in Memory:
      Memory[r] += 1
    else:
      Memory[r] = 1
  

  
max = 0
maxVal = 0
for k,i in Memory.items():
  if max < i:
    max = i
    maxVal = k

print(max)

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

a_dic = dict()
for i in range(N):
    if a[i] + 1 in a_dic:
        a_dic[a[i] + 1] += 1
    else:
        a_dic[a[i] + 1] = 1
    if a[i] in a_dic:
        a_dic[a[i]] += 1
    else:
        a_dic[a[i]] = 1
    if a[i] - 1 in a_dic:
        a_dic[a[i] - 1] += 1
    else:
        a_dic[a[i] - 1] = 1
        
ans = 0
for v in a_dic.values():
    if ans < v:
        ans = v
        
print(ans)

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

b = [0]*(max_a + 2)

for i in a:
    b[i] += 1

ans = 0
for i in range(max_a + 1):
    tmp = b[i-1] + b[i] + b[i+1]
    ans = max(ans, tmp)

print(ans)

Solution (Python):
def list_count(my_list):
    dic={} 
    for num in my_list:
        if num in dic: 
            dic[num]+=1 
        else: 
            dic[num]=1 
    return dic
n=int(input())
a=list(map(int,input().split()))
b=[0]*(3*n)
for i in range(3):
    for j in range(n):
        b[i*n+j]=a[j]+i-1
dict=list_count(b)
print(max(dict.values()))

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

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

Solution (Python):
import sys


def main()->None:
    N = int(sys.stdin.readline())
    a = list(map(int, sys.stdin.readline().split()))
    max_a = max(a)
    
    l = [0 for _ in range(max_a+2)] 
    for i in a:
        l[i] += 1
    res = 0
    for i in range(0, max_a+1):
        tmp = l[i-1]+l[i]+l[i+1]
        res = max(res, tmp)
    print(res)


if __name__ == "__main__":
    main()

Solution (Python):

import sys
n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
maxA = max(A)
L = [0 for _ in range(maxA+2)]

for a in A:
    L[a]+=1

ans = 0
for i in range(0, maxA+1):
    tmp = L[i-1] + L[i] + L[i+1]
    ans = max(ans, tmp)
print(ans)

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

Solution (Python):
import collections
n = int(input())
a = list(map(int, input().split()))
ans = 0
dd = collections.defaultdict(int)
for i in range(n):
    dd[str(a[i])] += 1
for i in range(1, 10 ** 5 - 1):
    tmp = dd[str(i - 1)] + dd[str(i)] + dd[str(i + 1)]
    ans = max(ans, tmp)
print(ans)

Solution (Python):
import collections

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

A_plus = [x+1 for x in A]
A_minus = [x-1 for x in A]

A_all = A_minus + A_plus + A

Count = collections.Counter(A_all)
ans = Count.most_common()[0][1]

print(ans)

Solution (Python):
import bisect
N = int(input())
a = sorted(list(map(int,input().split())))
amin = a[0]
amax = a[-1]
suma = []
for i in range(amin,amax+1):
    sumb = bisect.bisect_right(a,i+1) - bisect.bisect_left(a,i-1)
    suma.append(sumb)
print(max(suma))

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
a.sort()
p = 1
q = 0
r = 0
ans = 1
for i in range(N-1):
    if a[i+1] == a[i]+1:
        r = q
        q = p
        p = 1
    elif a[i+1] == a[i]:
        p += 1
    elif a[i+1] == a[i] + 2:
        r = p
        q = 0
        p = 1
    elif a[i+1] != a[i]:
        r = 0
        q = 0
        p = 1
    if p+q+r > ans:
        ans = p+q+r
print(ans)

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

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

Solution (Python):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

from collections import defaultdict
dicts = defaultdict(int)

N=one_int()
X=many_int()

sorted_X = sorted(X)

for i in sorted_X:
    if i in dicts:
        dicts[i] += 1
    else:
        dicts[i] = 1

max_num = 1
for j in range(sorted_X[0]-1,sorted_X[-1]+1):
    temp_sum = dicts[j-1] + dicts[j] + dicts[j+1]
    
    if max_num < temp_sum:
        max_num = temp_sum

print(max_num)

Solution (Python):
import collections
n = int(input())
a = list(map(int,input().split()))
c = dict(collections.Counter(a))
c = dict(sorted(c.items(),key = lambda x:x[0]))

ans = 0
for i in range(1,10**5):
  cnt = 0
  try:
    cnt += c[i-1]
  except KeyError:
    pass
  
  try:
    cnt += c[i]
  except KeyError:
    pass
    
  try:
    cnt += c[i+1]
  except KeyError:
    pass
    
  ans = max(ans,cnt)  
  
print(ans)

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

al = sorted(al)

import bisect

ans = 0
for i in range(-2,max(al)+2):
    a = bisect.bisect_right(al,i+2) -  bisect.bisect_left(al,i)
    ans = max(ans, a)

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
dct = {}
for i in range(-1,10**5+1):
  dct[i] = 0
for i in A:
  dct[i-1] += 1
  dct[i] += 1
  dct[i+1] += 1

sorted_dct = sorted(dct.items(), key=lambda x:-x[1])
print(sorted_dct[0][1])

Solution (Python):
import collections
n = int(input())
a = list(map(int,input().split()))
c = dict(collections.Counter(a))
c = dict(sorted(c.items(),key = lambda x:x[0]))

ans = 0
for i in range(1,10**5):
  cnt = 0
  try:
    cnt += c[i-1]
  except KeyError:
    pass
  
  try:
    cnt += c[i]
  except KeyError:
    pass
    
  try:
    cnt += c[i+1]
  except KeyError:
    pass
    
  ans = max(ans,cnt)  
  
print(ans)

Solution (Python):
from bisect import *
N = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 0
min_a = min(a)
max_a = max(a)
for x in range(min_a , max_a + 1):
    r = bisect_right(a , x + 1)
    l = bisect_left(a , x - 1)
    tmp_max = r - l
    if tmp_max > ans:
        ans = tmp_max
print(ans)

Solution (Python):
from bisect import bisect_left,bisect_right
N = int(input())
A = list(map(int,input().split()))
A.sort()
ans = 0
for i in range(A[0]-1,A[-1]+1):
    value = bisect_right(A,i+1)-bisect_left(A,i-1)
    if value > ans:
        ans = value
print(ans)

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())))
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
b=groupby(a)
l=len(b)
if l==1:
    print(b[0][1])
elif l==2:
    if b[1][0]-b[0][0]>1:
        print(max(b[1][1],b[0][1]))
    else:
        print(b[1][1]+b[0][1])
else:
    m=0
    for i in range(l-2):
        x=b[i+1][1]
        if b[i+1][0]-b[i][0]==1:
            x+=b[i][1]
        if b[i+2][0]-b[i+1][0]==1:
            x+=b[i+2][1]
        m=max(m,x)
    print(m)

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

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

Solution (Python):
n = int(input())
l = [int(i) for i in input().split()]

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

for i in l:
  ans[i] += 1
  ans[i-1] += 1
  ans[i+1] += 1
  

print(max(ans))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n = int(input())
    aa = LI()
    cnt = [0] * 100005
    for a in aa:
        cnt[a] += 1

    ans = s = sum(cnt[:3])
    for x in range(100000):
        s += cnt[x + 3] - cnt[x]
        if s > ans: ans = s

    print(ans)

main()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
X = [0]*(10**5+2)
for a in A:
    X[a-1] += 1
    X[a] += 1

    X[a+1] += 1
maxx = 0
print(max(X))

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

xs = []
for ai in a:
  xs.append(ai)
  xs.append(ai+1)
  xs.append(ai-1)

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

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

import bisect
li = []
for i in range(n):
    li.append(bisect.bisect(L,L[i]+2)-i)
print(max(li))

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

tmp = []
for i in range(n):
    tmp.extend([a[i], a[i] - 1, a[i] + 1])

from collections import Counter
c = Counter(tmp)
print(max(list(c.values())))

Solution (Python):
import sys
from collections import defaultdict

cnt = defaultdict(int)

def main():
    n, *a = map(int, sys.stdin.read().split())
    a.sort()
    l = a[0]
    r = a[-1]

    for val in a:
        cnt[val] += 1
    
    ans = 0
    for i in range(l, r+1):
        ans = max(ans, cnt[i-1] + cnt[i] + cnt[i+1])

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import defaultdict

cnt = defaultdict(int)

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

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

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import collections
N = int(input())
a = list(map(int,input().split()))
b = [a[i]-1 for i in range(len(a))]
c = [a[i]+1 for i in range(len(a))]
a.extend(b)
a.extend(c)
X = collections.Counter(a)
print(X.most_common()[0][1])

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

L = []
for i in range(N):
    L.append(A[i]-1)
    L.append(A[i])
    L.append(A[i]+1)
    
L.sort()
num = L[0]
cnt = 0
ans = 0
for i in range(len(L)+1):
    if i < len(L) and num == L[i]:
        cnt += 1
    else:
        ans = max(ans, cnt)
        cnt = 1
        num = L[min(i, len(L)-1)]
        
print(ans)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
num = list(range(10**5+1))
val = [0]*(10**5+1)
dic = dict(zip(num,val))
for i in a:
    if i == 0:
        dic[i] += 1
        dic[i+1] += 1
    elif i == 10**5:
        dic[i-1] += 1
        dic[i] += 1
    else:
        dic[i-1] += 1
        dic[i] += 1
        dic[i+1] += 1
print(max(dic.values()))

Solution (Python):
from collections import Counter

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

array = []
for li in [-1,0,1]:
  for ai in aa:
    array.append(ai+li)

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

Solution (Python):
from collections import defaultdict as dd
n = int(input())
A = list(map(int, input().split()))
dic = dd(lambda: 0)
for a in A:
  dic[a-1] += 1
  dic[a] += 1
  dic[a+1] += 1
print(max(dic.values()))

Solution (Python):
from sys import stdin
import bisect

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

li.sort()

ma = 0

if len(li) == 1:
    print(1)
elif len(li) == 2:
    if abs(li[0] - li[1]) <= 1:
        print(2)
    else:
        print(1)
else:
    for i in range(1,n-1):
        ma = max(ma,bisect.bisect(li,i+1)-bisect.bisect_left(li,i-1))

    print(ma)

Solution (Python):
N =input()
As = [int(x) for x in input().split()]
count = {}
for a in As:
    for a_ in [a-1, a, a+1]:
        if count.get(a_):
            count[a_] += 1
        else:
            count[a_] = 1
max_count = 0
for key, value in count.items():
    if value > max_count:
        max_count = value
        
print(max_count)

Solution (Python):
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
ans = 0
nom = defaultdict(int)
for i in range(n):
    nom[a[i]]+=1
ans = 0
a = set(a)
a = list(a)
m = len(a)
for i in range(m):
    b = nom[a[i]] + nom[a[i]-1]+ nom[a[i]+1]
    ans = max(ans,b)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    M=10**5
    n=int(input())
    C=[0]*M
    for a in map(int,input().split()):
        C[a]+=1
    print(max(*(C[i-1]+C[i]+C[i+1] for i in range(1,M-1))))
resolve()

Solution (Python):
import sys
from collections import Counter

input = sys.stdin.readline

def main():
    N = int(input())
    a = Counter(list(map(int, input().split())))
    
    ans = 0
    
    for n, c in a.items(): ans = max(ans, c + a[n-1] + a[n+1])
        
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import collections as col
n = int(input())
li = list(map(int,input().split()))

li1 = []
for i in range(n):
  li1.append(li[i])
  li1.append(li[i]+1)
  li1.append(li[i]-1)
c = col.Counter(li1)
print(max(list(c.values())))

Solution (Python):
n = int(input())
A = map(int, input().split())
D = [0]*10**6
for i in A:
  for j in range(3):
    D[i+j] += 1
print(max(D))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
import collections
c=collections.Counter(a)
d=sorted(c)
maxi=0
if n>=3 and len(d)>=3:
    for i in range(len(d)-2):
        total=c[d[i]]+c[d[i+1]]+c[d[i+2]]
        maxi=max(maxi,total)
    print(maxi)
if n>=3 and len(d)==2:
    print(n if abs(d[0]-d[1])<=2 else 2)
if n>=3 and len(d)==1:
    print(n)
if n==2:
    print(2 if abs(a[0]-a[1])<=2 else 1)
if n==1:
    print(1)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
    b.append(a[i])
    b.append(a[i]+1)
    b.append(a[i]-1)
import heapq
cnt=0
c=1000000
d=0
ans=[]
heapq.heapify(b)

while len(b)>0:
    d=heapq.heappop(b)
    if c==1000000:
        c=d
        cnt+=1
    elif c!=d:
        ans.append(cnt)
        cnt=1
        c=d
    else:
        cnt+=1
print(max(ans))

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
X = [0] * 101010
for a in A:
    X[a] += 1

ma = 0
for i in range(100001):
    ma = max(ma, X[i-1] + X[i] + X[i+1])
print(ma)

Solution (Python):
import collections

n = int(input())
a = list(map(str, input().split()))
x1 = []
x2 = []
x3 = []
for i in range(n):
    tmp = str(int(a[i]) + 1)
    x1.append(tmp)
    tmp = a[i]
    x2.append(tmp)
    tmp = str(int(a[i]) - 1)
    x3.append(tmp)

x1.extend(x2)
x1.extend(x3)
x1.sort()
set_x1 = set(x1)
c = collections.Counter(x1)
Max = 0
for i in set_x1:
    if int(c[str(i)]) > Max:
        Max = int(c[str(i)])
print(Max)

Solution (Python):
N = int(input())
arr = list(map(int, input().split()))
arr2 = [0]*(max(arr)+1)
if max(arr) < 4:
    print(len(arr))
    exit()
for i in range(N):
    arr2[arr[i]] += 1
ans = arr2[1] + arr2[2] + arr2[3]
tmp = ans
for i in range(4,len(arr2)):
    tmp = tmp - arr2[i-3] + arr2[i]
    if ans < tmp:
        ans = tmp
print(ans)

Solution (Python):
from collections import defaultdict

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

a_li.sort()
a_count = defaultdict(int)
for x in a_li:
    a_count[x] += 1

ans = 0

a_set = set(a_li)

for i in a_set:
    s = a_count[i] + a_count[i-1] + a_count[i+1]
    ans = max(ans,s)

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
X = [0] * 10 ** 5

for i in range(N):
    X[A[i]] += 1

ans = 0
X_count = 0

if N == 1:
    print(1)
elif N == 2:
    if abs(A[1] - A[0]) <= 1:
        print(2)
    else:
        print(1)
else:
    for i in range(N-2):
        X_count = X[i] + X[i+1] + X[i+2]
        ans = max(ans,X_count)
        X_count = 0
    print(ans)

Solution (Python):
def examC():
    N = I()
    A = LI()
    d = defaultdict(int)
    for i in A:
        d[i] +=1;d[i-1] +=1; d[i+1] +=1
    ans = max(d.values())
    print(ans)

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Solution (Python):
import collections
n = int(input())
a = [int(x) for x in input().split()]

c = collections.Counter(a)
max_counts = 0

for i in c.keys():
    
    count = c[i] + c[i-1] + c[i+1]
    max_counts = count if count > max_counts else max_counts

print(max_counts)