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

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

from collections import defaultdict
d = defaultdict(int)
for a in A:
    lower = a - 1
    upper = a + 1
    if lower >= 0:
        d[lower] += 1
    d[a] += 1
    d[upper] += 1

ans = 0
for k, v in d.items():
    ans = max(ans, v)
print(ans)

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

l = [0]*100001

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

for i in range(len(l)-2):
  ans = max(ans,l[i]+l[i+1]+l[i+2])
  
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
dict = {}
ans = 0

for i in range(n):
  if a[i] not in dict:
    dict[a[i]] = 1
  else:
    dict[a[i]] += 1

l = sorted(dict.items())
l += [(-1,0),(-2,0)]

for j in range(len(l)-2):
  if l[j][0]+1 == l[j+1][0] and l[j][0]+2 == l[j+2][0]:
     ans = max(ans,l[j][1]+l[j+1][1]+l[j+2][1])
  elif l[j][0]+1 == l[j+1][0] and l[j][0]+2 != l[j+2][0]:
     ans = max(ans,l[j][1]+l[j+1][1])
  elif l[j][0]+1 != l[j+1][0] and l[j][0]+2 != l[j+2][0]:
     ans = max(ans,l[j][1])
   
  
print(ans)

Solution (Python):
import collections
N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
keys = sorted(C.keys())
MAX = 0
for i in keys:
    MAX = max(MAX,C[i-1]+C[i]+C[i+1])
print(MAX)

Solution (Python):
from collections import defaultdict

N = int(input())
d = defaultdict(int)
for a in map(int, input().split()):
    d[a] += 1
    d[a - 1] += 1
    d[a + 1] += 1

print(max(d.values()))

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

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

l = [0]*100005 

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

print(ans)

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

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

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

Solution (Python):
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = 1
for c in C.keys():
    for i in range(-1, 2):
        j = c + i
        ans = max(ans, sum([C[j - 1], C[j], C[j + 1]]))
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = 1
for c in C.keys():
    for i in range(-1, 2):
        j = c + i
        ans = max(ans, sum([C[j - 1], C[j], C[j + 1]]))
print(ans)

Solution (Python):
import collections

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

zen = m
cou = 0

for x in range(n):
    zen.append(m[x]-1)

for x in range(n):
    zen.append(m[x]+1)

a = collections.Counter(zen)





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

Solution (Python):

N=int(input())
A=list(map(int,input().split()))
ans=[0 for i in range(10**5+1)]

for i in range(N):
    ans[A[i]-1]+=1
    if A[i]-2>=0:
        ans[A[i]-2]+=1
    if A[i]<=N-1:
        ans[A[i]]+=1

print(max(ans))

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

plus_list = []
minus_list = []
for a in a_list:
    plus_list.append(a+1)
    minus_list.append(a-1)

a_list.extend(plus_list)
a_list.extend(minus_list)

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

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

Solution (Python):
from collections import Counter

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

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

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

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N = I()
A = IL()

d = DD(int)
for a in A:
  d[a] += 1
keys = [k for k in d]
P(max(d[k-1] + d[k] + d[k+1] for k in keys))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
for i in range(N):
    A.append(A[i]+1)
    A.append(A[i]-1)
import collections 
C = collections.Counter(A)
ans = 0
for k,v in C.items():
    if v>ans:
        ans = v
print(ans)

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

c=[0 for i in range(100003)]

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

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

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

ans=0
if len(l)>3:
    for i in range(len(l)-2):
        if ans<l[i]+l[i+1]+l[i+2]:
            ans=l[i]+l[i+1]+l[i+2]
else:
    ans=sum(l)
print(ans)

Solution (Python):
from collections import defaultdict

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

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

MIN=min(A)
MAX=max(A)

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

Solution (Python):
def resolve():
    
    n = int(input())
    
    
    
    
    
    A = list(map(int, input().split()))
    
    

    A = sorted(A)

    Cnt = [0] * 100002
    for a in A:
        Cnt[a] += 1
        Cnt[a+1] += 1
        Cnt[a+2] += 1

    print(max(Cnt))
resolve()

Solution (Python):
from collections import Counter

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

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

ans = max(Counter(x).values())
print(ans)

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

new_list = list()

for x in range(n):
    num = a[x]
    num_plus = num + 1
    num_minus = num - 1
    new_list.append(num_plus)
    new_list.append(num_minus)
    new_list.append(num)

d = dict(Counter(new_list))

print(max(d.values()))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mina = min(a)
maxa = max(a)
w = maxa - mina + 3
abucket = [0] * w
for i in range(n):
  abucket[a[i] - mina] += 1
  abucket[a[i] - 1 - mina] += 1
  abucket[a[i] + 1 - mina] += 1
print(max(abucket))

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

lcnt = [0] * (max(la) + 3)

for i in range(N):
    lcnt[la[i]+2] += 1
    lcnt[la[i]+1] += 1
    lcnt[la[i]] += 1

print(max(lcnt))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
memo = {}
for a in A:
    try:
        memo[a] += 1
    except:
        memo[a] = 1
    try:
        memo[a+1] += 1
    except:
        memo[a+1] = 1
    try:
        memo[a-1] += 1
    except:
        memo[a-1] = 1

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

Solution (Python):

n = int(input())
a = list(map(int,input().split()))
b = [0]*(max(a)+2)

for i in range(n):
  b[a[i]] += 1
  b[a[i]+1] += 1
  if a[i] > 0:
    b[a[i]-1] += 1

print(max(b))

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
m=max(a)
table=[0]*(m+2)
cnt=0

for num in a:
    if num==0:
        cnt+=1
        table[0]+=1
        table[1]+=1
    else:
        table[num-1]+=1
        table[num]+=1
        table[num+1]+=1

tmp=max(table)
ans=max(tmp, cnt)
print(ans)

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



b=np.zeros(n,dtype=int)
c=np.zeros(n,dtype=int)

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



mylist=[]
mylist.extend(a)
mylist.extend(b)
mylist.extend(c)



d=collections.Counter(mylist)

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

Solution (Python):
import collections
N = int(input())
a = list(map(int,input().split()))
cnt = 0
ans = []
item = []
for i in range(N):
    ans.append(a[i]-1)
    ans.append(a[i])
    ans.append(a[i]+1)

c = collections.Counter(ans)
d = c.most_common()







print(d[0][1])

Solution (Python):
from collections import Counter

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

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

ans = Counter(a)

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

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

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

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

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

Solution (Python):



import itertools

n = int(input())
a = [int(i) for i in input().split()]

a.sort()
gr = itertools.groupby(a)
hoge_list = [0]*100001
ans = 0

for key, group in gr:
    hoge_list[key] = len(list(group))

for i in range(1,100000,1):
    _tmp = hoge_list[i-1] + hoge_list[i] + hoge_list[i+1]
    if ans < _tmp:
        ans = _tmp

print(ans)

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

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

X = [0]*(10**5+4)

op = [-1,0,1]

for i in range(N):
    for j in range(3):
        X[a[i]+op[j]+1] +=1

print(max(X))

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
ad=dict()
ans=0
for i in range(len(a)):
	if a[i] in ad:
		ad[a[i]]+=1
	else:
		ad[a[i]]=1
for i in range(min(ad),max(ad)+1):
	tmp=0
	if i in ad:
		tmp+=ad[i]
	if i-1 in ad:
		tmp+=ad[i-1]
	if i+1 in ad:
		tmp+=ad[i+1]
	if tmp>ans:
		ans=tmp
print(ans)

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

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

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

    print(cnt)

if __name__=="__main__":
    main()

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

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

    cnt=0
    for x in range(1,10**5+1):
        if x-1 in d: s=d[x-1]
        else: s=0

        if x in d: t=d[x]
        else: t=0

        if x+1 in d: u=d[x+1]
        else: u=0

        cnt=max(cnt,s+t+u)

    print(cnt)

if __name__=="__main__":
    main()

Solution (Python):



import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
l=LI()
lis=[]
for i in range(n):
    lis.append(l[i]-1)
    lis.append(l[i]+1)
    lis.append(l[i])
c=Counter(lis)
u=c.most_common()[0]
print(u[1])

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

Solution (Python):
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
B = []
for i in A:
    B.append(i-1)
    B.append(i)
    B.append(i+1)

C = Counter(B).values()
print(max(C))

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

Solution (Python):

import re
import math
from collections import defaultdict
from collections import deque
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache

readline=sys.stdin.readline
sys.setrecursionlimit(2000000)

alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_pow(a,b):
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def get_primes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
    return ret
def seifu(x):
    return x//abs(x)

def main():
    n=int(input())
    A=list(map(int,input().split()))
    D=defaultdict(int)
    for a in A:
        D[a]+=1
    mmax=0
    for a in A:
        mmax=max(mmax,D[a]+D[a-1]+D[a+1])
    print(mmax)
main()

Solution (Python):
from collections import Counter

input()
values = tuple(map(int, input().split(' ')))
counter = Counter(values)

max_count = 0
best_x = None

for x in counter:
    count = counter[x - 1] + counter[x] + counter[x + 1]
    if count > max_count:
        max_count = count
        best_x = x

print(max_count)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
maxim = max(A)
counter = [0]*(maxim+1)
dif = [-1, 0, 1]
for i in A:
    for d in dif:
        j = i + d
        if j < 0 or maxim < j:
            continue
        else:
            counter[j] += 1
print(max(counter))

Solution (Python):
import math
import queue
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): 
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): 
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} 
def bitArr(n):
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): 
			k = i-a*j
			if k%b==0:
				return i
	return -1

n = readInt()
a = readInts()

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

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

ans = 1

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

print(ans)

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

dictA = {}

for x in a:
    dictA.setdefault(x, 0)
    dictA[x] += 1
    if x - 1 > 0:
        dictA.setdefault(x - 1, 0)
        dictA[x - 1] += 1
    dictA.setdefault(x + 1, 0)
    dictA[x + 1] += 1
print(max(dictA.values()))

Solution (Python):
def main():
    from collections import Counter
    n, *a = map(int, open(0).read().split())
    b = Counter(a)
    *c, = map(lambda x: tuple(x), b.items())
    c.sort(key=lambda x: x[0])
    ans = 0
    c = [c[0]] + c + [c[-1]]
    for x, y, z in zip(c, c[1:], c[2:]):
        v = y[0]
        tmp = y[1]
        if v - x[0] == 1:
            tmp += x[1]
        if v - z[0] == -1:
            tmp += z[1]
        ans = max(ans, tmp)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from collections import Counter
    n, *a = map(int, open(0).read().split())
    b = Counter(a)
    c = [(k, v) for k, v in b.items()]
    c.sort(key=lambda x: x[0])
    ans = 0
    c = [c[0]] + c + [c[-1]]
    for x, y, z in zip(c, c[1:], c[2:]):
        v = y[0]
        tmp = y[1]
        if v - x[0] == 1:
            tmp += x[1]
        if v - z[0] == -1:
            tmp += z[1]
        ans = max(ans, tmp)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

from fractions import gcd
import math
def resolve():
    N=pin()
    X=sorted(lispin())
    d=[0]*(10**5+1)
    for x in X:
        d[x]+=1
    ans=0
    for i in range(10**5+1):
        a,b,c=0,0,0
        try:
            a=d[i]
            b=d[i+1]
            c=d[i+2]
        except IndexError:pass
        ans=max(ans,a+b+c)
    print(ans)
        

resolve()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
maxim = max(A)
counter = [0]*(maxim+1)
dif = [-1, 0, 1]
for a in A:
    for d in dif:
        i = a + d
        if i < 0 or maxim < i:
            continue
        else:
            counter[i] += 1
print(max(counter))

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

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

def main():
    n = int(input())
    a = list(map(int, input().split()))
    l = [0]*(10**5 + 10)


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

main()

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

Solution (Python):
import collections

N = int(input())
counter = collections.defaultdict(int)
for i in list(map(int, input().split())):
    counter[i - 1] += 1
    counter[i] += 1
    counter[i + 1] += 1

print(max(counter.values()))

Solution (Python):
import collections
N = int(input())
a = list(map(int, input().split()))
if N == 1:
    print(1)
    exit()
if N == 2:
    if abs(a[0]-a[1]) <= 2:
        print(2)
    else:
        print(1)
    exit()
c = collections.Counter(a)
c_key = list(c.keys())
c_value = list(c.values())
res = 0
if len(c) == 2:
    if int(c_key[1])-int(c_key[0]) <= 2:
        print(c_value[0]+c_value[1])
        exit()
for i in range(1,len(c)-1):
    temp = c_value[i]
    temp_2 = 0
    temp_3 = 0
    flag = True
    if int(c_key[i])-int(c_key[i-1]) == 1:
        temp += c_value[i-1]
        flag = False
    if int(c_key[i+1])-int(c_key[i]) == 1:
        temp += c_value[i+1]
        flag = False
    if flag and int(c_key[i+1])-int(c_key[i]) == 2:
        temp_2 = c_value[i+1]+c_value[i]
        flag = False
    if flag and int(c_key[i])-int(c_key[i-1]) == 2:
        temp_3 = c_value[i-1]+c_value[i]
    if max(temp,temp_2,temp_3) > res:
        res = max(temp,temp_2,temp_3)
print(max(res,c_value[0],c_value[-1]))

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

Solution (Python):


from collections import defaultdict

n=int(input())
a=[int(x) for x in input().split()]
d=defaultdict(int)
for i in a:
    d[i]+=1

b=[[-2,0],[-1,0]]
for i in d:
    b.append([i,d[i]])
b.sort()

ans=1
m=len(b)
for i in range(m):
    ans=max(ans,b[i][1])
    if i+1<m and b[i][0]+1==b[i+1][0]:
        ans=max(ans,b[i][1]+b[i+1][1])
    if i+2<m and b[i][0]+1==b[i+1][0] and b[i+1][0]+1==b[i+2][0]:
        ans=max(ans,b[i][1]+b[i+1][1]+b[i+2][1])
print(ans)

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

num_list = [0 for _ in range(2*10**5)]
for i in range(n):
    num_list[a[i]-1] += 1
    num_list[a[i]] += 1
    num_list[a[i]+1] += 1
print(max(num_list))

Solution (Python):
import collections,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
a = LI()
ans = 0
num_count = collections.defaultdict(int)
for x in a:
    num_count[x-1] += 1
    num_count[x] += 1
    num_count[x+1] += 1
print(max(num_count.values()))

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
a = LI()
ans = 0
num_count = [0]*(10**5+2)
for x in a:
    num_count[x-1] += 1
    num_count[x] += 1
    num_count[x+1] += 1
print(max(num_count))

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
a = LI()
ans = 0
num_count = [0]*(10**5+1)
for x in a:
    num_count[x] += 1
for i in range(10**5+1):
    if i+2<=10**5:
        ans = max(ans,sum(num_count[i:i+3]))
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
dic = Counter(A)
cnt = 1
Mcnt = 1
for i in range(0,N):
  if (i-1) in dic and (i+1) in dic:
      cnt = dic[i-1] + dic[i] + dic[i+1]
  elif (i-1) in dic:
      cnt = dic[i-1] + dic[i]
  elif (i+1) in dic:
      cnt = dic[i] + dic[i+1]
  else:
      cnt = dic[i]
  if Mcnt < cnt:
    Mcnt = cnt
print(Mcnt)

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

dic={}
for i in range(n):
    dic[a_input[i]]=dic.get(a_input[i],0)+1
    dic[a_input[i]-1]=dic.get(a_input[i]-1,0)+1
    dic[a_input[i]+1]=dic.get(a_input[i]+1,0)+1
print(max(dic.values()))

Solution (Python):
n=int(input())
from collections import Counter as co
var=co(list(map(int,input().split())))
ans=0
for k in var:
  p=var[k]
  if k-1 in var:p+=var[k-1]
  if k+1 in var:p+=var[k+1]
  
  ans=max(ans,p)
print(ans)

Solution (Python):
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))
n=int(input())
a=mp()
l=[0]*(10**5+10)
for x in a:
    l[x]+=1
    l[x-1]+=1
    l[x+1]+=1
print(max(l))

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]

def to_bin(x: int) -> str: return format(x, 'b') 
def to_oct(x: int) -> str: return format(x, 'o') 
def to_hex(x: int) -> str: return format(x, 'x') 
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res

from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left


def main():
    n = II()
    aa = MII()
    x = {i: 0 for i in range(-1, 10**5+2)}
    for a in aa:
        x[a-1] += 1
        x[a] += 1
        x[a+1] += 1
    print(max(x.values()))

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
sa=set(a)
dic=Counter(a)
hantei=0
for i in dic:
  if (i-1) in dic and (i+1) in dic:
    x=dic[i]+dic[i-1]+dic[i+1]
  elif (i-1) in dic:
    x=dic[i]+dic[i-1]
  elif (i+1) in dic:
    x=dic[i]+dic[i+1]
  else:
    x=dic[i]
  if hantei < x:
    hantei=x
print(hantei)

Solution (Python):
from collections import defaultdict
dd = defaultdict(int)

n = int(input())
A=[int(i) for i in input().split()]

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

Solution (Python):
from collections import Counter
N = int(input())
L = list(map(int, input().split()))
c = Counter(L)


ans = 0
m = max(L) + 1
for i in range(m):
    ans = max(ans, c[i - 1] + c[i] + c[i + 1])

print(ans)

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

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

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

  ans = 0

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

  print(ans)

if __name__ == "__main__":
  main()