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()))
b = [0 for i in range(10**5)]
for i in range(N):
    if a[i] > 0 and a[i] < 10**5-1:
        b[a[i]-1] += 1
        b[a[i]] += 1
        b[a[i]+1] += 1
    elif a[i] == 0:
        b[0] += 1
        b[1] += 1
    else:
        b[10**5-2] += 1
        b[10**5-1] += 1
print(max(b))

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

Solution (Python):
n = int(input())
A = sorted(list(map(int, input().split())))
count = dict()
for a in A:
    for i in range(a-1, a+2):
        if i not in count:
            count[i] = 1
        else:
            count[i] += 1
print(max(count.values()))

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

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

X=list(set(A))

RES=[0]*100002

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

print(max(RES))

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

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

a=collections.Counter(A)

X=sorted(a.items(), key=lambda x:x[0])

K=[]
V=[]

RES=[]
for i in range(len(X)):
    K.append(X[i][0])
    V.append(X[i][1])

if len(X)>=3:
    for j in range(1,len(X)-1):
        res=V[j]
        if K[j]-1==K[j-1]:
            res+=V[j-1]
        if K[j]+1==K[j+1]:
            res+=V[j+1]
        RES.append(res)
elif len(X)==2:
    if K[0]+1==K[1]:
        RES.append(V[0]+V[1])
    else:
        RES.append(max(V))
else:
    RES.append(V[0])        

print(max(RES))

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = []
for a in A:
    B.extend([a - 1, a, a + 1])
B = Counter(B)
print(B.most_common(1)[0][1])

Solution (Python):
import bisect

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

res = []
for i in range(1,10**5+1):
    res.append(bisect.bisect_right(A,i+1)-bisect.bisect_left(A,i-1))
print(max(res))

Solution (Python):
from collections import Counter
n=int(input())
a=[int(i) for i in input().split()]
plus=[i+1 for i in a]
minus=[i-1 for i in a]
print(sorted(list(Counter(a+plus+minus).values()))[-1])

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

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

for key in a:
    if key in d:
        d[key] += 1
    else:
        d[key] = 1

ans = 0
for i in range(10 ** 5 + 1):
    if i in d:
        b[i] = d[i]

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

Solution (Python):
from collections import Counter

N = int(input())
a = list(map(int, input().split()))
m = max(a)
d = Counter(a)

ans = 0
for i in range(-1, m+2):
  count = 0
  if i in d.keys():
    count += d[i]
  if i+1 in d.keys():
    count += d[i+1]
  if i-1 in d.keys():
    count += d[i-1]
  ans = max(ans, count)
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
a_list = list(map(int, input().split(" ")))
c = Counter(a_list)

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

Solution (Python):
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

NUM = 100000

N = int(input())

table = [0] * (NUM+1)

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

for i in range(N):
    table[input_array[i]] += 1


maximum = 1


for i in range(0,100001,1):
    tmp = 0
    if i-1 >= 0:
        tmp += table[i-1]
    tmp += table[i]
    if i+1 <= 100000:
        tmp += table[i+1]
    maximum = max(maximum,tmp)

print("%d"%(maximum))

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

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

afters = []
for ai in range(N):
	for sign in [-1,0,1]:
		afters.append(A[ai]+sign)
		
uniq = set(afters)

countDic = {}
sas = sorted(afters)
for a in sas:
	if a in countDic.keys():
		countDic[a] += 1
	else:
		countDic[a] = 1
	
print(max(countDic.values()))

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

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

c = collections.Counter(a)
res = 0
for i in range(10**5):
    num = c[i-1] + c[i] + c[i+1]
    if res < num:
        res = num
print(res)

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

T = [0]*100000
for x in a:
  T[x] += 1
ans = 0
for i in range(99998):
  ans = max(ans, sum(T[i:i+3]))
print ans

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

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


if __name__ == "__main__":
    main()

Solution (Python):

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






n = I()
d = defaultdict(int)
a = LI()
for i in a:
    d[i] += 1
    d[i+1] += 1
    d[i-1] += 1
d = list(d.values())
print(max(d))

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

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

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

b = [0 for i in range(10**5+1)]

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
if N == 1:
  print(1)
elif N == 2:
  if abs(A[1]-A[0]) <= 2:
    print(2)
  else:
    print(1)
else:
  L = [0]*(10**5+1)
  for i in range(N):
    L[A[i]+1] += 1
  for j in range(1,len(L)):
    L[j] = L[j-1]+L[j]
  ans = 0
  for k in range(3,len(L)):
    S = L[k]-L[k-3]
    if ans <= S:
      ans = S
  print(ans)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
ls = []
for i in a:
    ls.append(i)
    ls.append(i+1)
    ls.append(i-1)
import collections as col
dic = col.defaultdict(int)
for i in ls:
    dic[i] += 1
print(max(dic.values()))

Solution (Python):
def main():
    _ = int(input())
    a = [int(s) for s in input().split()]
    print(solve(a))

def solve(a):
    c = dict()

    for i in a:
        for j in range(i - 1, i + 2):
            c[j] = c.get(j, 0) + 1
    
    return max(c.values())

main()

Solution (Python):

N=int(input())
A=list(map(int,input().split()))
A.sort()
B=[0]*(max(A)+1)
back=A[0]
count=0
for a in A:
	if back==a:
		count+=1
	else:
		B[back]=count
		back=a
		count=1
B[back]=count
num=sum(B[0:min(3,len(B))])
for n in range(max(A)-1):
	if num<sum(B[n:n+3]):
		num=sum(B[n:n+3])
print(num)

Solution (Python):
from sys import stdin, stderr, setrecursionlimit, exit
from collections import Counter
setrecursionlimit(2147483647)
def getint():
    return int(stdin.readline().rstrip('\r\n'))
def getints():
    return [int(i) for i in stdin.readline().rstrip('\r\n').split()]
def getintlines(n=1):
    res = []
    for _ in range(n):
        res.append(getint())
    return res
def getintslines(n=1):
    res = []
    for _ in range(n):
        res.append(getints())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getint()
a = getints()
c = Counter()

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

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

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

Solution (Python):
import bisect

n=int(input())
a=list(map(int,input().split()))
a.sort()
max=0
for i in range(10**5+1):
    x=bisect.bisect_left(a,i-1)
    y=bisect.bisect_right(a,i+1)
    if y-x>max:
        max=y-x
print(max)

Solution (Python):
from collections import Counter 
N = int(input())
A = Counter(list(map(int, input().split())))
cnt = 0
for i in A:
    sums = A[i] + A[i+1] + A[i+2]
    if sums > cnt:
        cnt = sums
print(cnt)

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

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

d = {}
for a in A:
    for i in [-1,0,1]:
        if a+i in d.keys():
            d[a+i] += 1
        else:
            d[a+i] = 1

print(max(d.values()))

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
b=[0 for _ in range(100002)]
for i in range(N):
    b[a[i]-1],b[a[i]],b[a[i]+1]=b[a[i]-1]+1,b[a[i]]+1,b[a[i]+1]+1
b.sort(reverse=True)
print(b[0])

Solution (Python):
import collections

n = int(input())
l = list(map(int, input().split()))
for i in range(n):
    l.append(l[i] + 1)
    l.append(l[i] - 1)
c = collections.Counter(l)
print(c.most_common()[0][1])

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
table = [0 for i in range(10**5+3)]


for x in L:
    table[x] += 1
    table[x-1] += 1
    table[x+1] += 1

print(max(table))

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

m = [0] * (max(A) + 1)
for a in A:
    m[a] += 1
    
ans = 0
for i in range(len(m)):
    ans = max(ans, sum(m[i : i + 3]))
    
print(ans)

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

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

ans = [0] * 100010
for i in collection:
    ans[i] = collection[i-1]+collection[i]+collection[i+1]
print(max(ans))

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

Solution (Python):
from collections import defaultdict

int_n = int(input())
ar_int_a = list(map(int, input().split()))

d_cnt = defaultdict(int)
for w in ar_int_a:
    d_cnt[w] += 1


st_int_group = set(ar_int_a)
max_count = 0

for i in st_int_group:
    max_count = max(d_cnt[i] + d_cnt[i - 1] + d_cnt[i + 1], max_count)

print(max_count)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
d = {}
ans = 0
for i in a:
    try:
        d[i] += 1
    except:
        d[i] = 1
for i in d:
    cnt = d.get(i-1, 0) + d.get(i, 0) + d.get(i+1, 0)
    if cnt > ans:
        ans = cnt
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
aset = set(a)
d = {i:0 for i in aset}
for i in range(n):
    d[a[i]] += 1
aset = sorted(aset)
if len(aset) == 1:
    print(d[aset[0]])
    exit()
if len(aset) == 2:
    if abs(aset[0]-aset[1]) <= 1:
        print(d[aset[0]] + d[aset[1]])
    else:
        print(max(d[aset[0]], d[aset[1]]))
    exit()
ans = 0
for i in range(len(aset)-2):
    ans = max(d[aset[i]], ans)
    if aset[i+1] - aset[i] == 1:
        ans = max(d[aset[i+1]]+d[aset[i]], ans)
    if aset[i+2] - aset[i] == 2:
        ans = max(d[aset[i+2]]+d[aset[i+1]]+d[aset[i]], ans)
print(ans)

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

li = [[a[0],1]]

for i in range(1,n):
  if a[i] != a[i-1]:
    li.append([a[i],1])
  else:
    li[len(li)-1][1]+=1
ans = 0
for i in range(len(li)):
  ans_tmp =li[i][1]
  if 0<=i-1:
    if li[i-1][0]+1  == li[i][0]:
      ans_tmp = ans_tmp +li[i-1][1]
  if i+1<len(li):
    if li[i+1][0]-1  == li[i][0]:
      ans_tmp = ans_tmp +li[i+1][1]
  ans = max(ans,ans_tmp)
print(ans)

Solution (Python):
from collections import Counter

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

for i in range(min(a), max(a)+1):
    total = 0
    if i in a:
        total += a[i]
    if i-1 in a:
        total += a[i-1]
    if i+1 in a:
        total += a[i+1]
    max_total = max(max_total, total)
    
print(max_total)

Solution (Python):
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()
n=I()
a=IL()
cnt=[0 for i in range(pow(10,5))]
for i in range(n):
    cnt[a[i]]+=1
m=0
for i in range(2,pow(10,5)):
    m=max(cnt[i]+cnt[i-1]+cnt[i-2],m)
print(m)

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

result = [0]*(10**5+10)
for a in A:
  result[a] += 1
  result[a-1] += 1
  result[a+1] += 1
print(max(result))

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

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

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

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):
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
C=Counter(A)
ans=0
for i in C.keys():
    tmp=C[i-1]+C[i]+C[i+1]
    ans=max(ans,tmp)
print(ans)

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

count = {}
for ai in a:
  count[ai] = count.get(ai, 0) + 1

ans = 0
for key in count.keys():
  ans = max(ans, count.get(key - 1, 0) + count.get(key) + count.get(key + 1, 0))
print(ans)

Solution (Python):
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
Cont=Counter(A)
Cont1=Counter(A)
for k,v in Cont.items():
  Cont1[k-1]+=v
  Cont1[k+1]+=v
print(Cont1.most_common()[0][1])

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

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

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
L.sort()
L.append(1000000)
M = [0]*((10**5)+1)
c = 0
d = 1
num = L[0]
if N == 1:
  print(1)
elif N == 2:
  if abs(L[0]-L[1]) <=1 :
    print(2)
  else:
    print(1)
else:
  while c <= N-1:
    if L[c] == L[c+1]:
      d += 1
      c += 1
    else:
      M[num] = d
      d = 1
      c += 1
      num = L[c]
  M.insert(0,0)
  M.append(0)
  ans = 0
  for i in range(len(M)-2):
    if M[i]+M[i+1]+M[i+2] >= ans:
      ans = M[i]+M[i+1]+M[i+2]
  print(ans)

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

Solution (Python):
import collections

from itertools import chain


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

A = [[a-1, a, a+1] for a in A]
A = list(chain.from_iterable(A))

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

Solution (Python):


















import collections
def inpl(): return list(map(int, input().split()))


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

ans_l = []
for a_i in a:
  ans_l.append(a_i)
  ans_l.append(a_i-1)
  ans_l.append(a_i+1)

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

Solution (Python):
import collections
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(len(a)):
    b.append(a[i])
    b.append(a[i]-1)
    b.append(a[i]+1)

c = collections.Counter(b)
most = c.most_common()[0]

print(most[1])

Solution (Python):
from collections import Counter

n = int(input())
c = Counter(map(int, input().split()))
print(max([c[i-1]+c[i]+c[i+1] for i in range(1, 10**5-1)]))

Solution (Python):
from collections import Counter

def solve(N, As):
    c = Counter(As)
    c.update([a + 1 for a in As])
    c.update([a - 1 for a in As])
    return max([v for v in c.values()])

if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))

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

    count = {}
    for x in a:
        count[x] = count.get(x, 0) + 1
        count[x-1] = count.get(x-1, 0) + 1
        count[x+1] = count.get(x+1, 0) + 1

    
    ans = max(count.values())
    return ans


def main():
    print(solve())


if __name__ == '__main__':
    main()

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

nums = [0]*(10**5+10)
for a in A:
  nums[a] += 1
  nums[a-1] += 1
  nums[a+1] += 1
print(max(nums))

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

arr = li.copy()
arr += [i - 1 for i in li]
arr += [i + 1 for i in li]

arr.sort()

ans = 1
cnt = 1
tmp = arr[0]
for a in arr[1:]:
    if a != tmp:
        if cnt > ans:
            ans = cnt
        tmp = a
        cnt = 1
    else:
        cnt += 1

print(ans)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
maxval = 0
for i in range(100000):
    x = c[i] if i in c else 0
    y = c[i+1] if i+1 in c else 0
    z = c[i+2] if i+2 in c else 0
    maxval = max(maxval, x+y+z)
print(maxval)

Solution (Python):
from collections import Counter
n = int(input())
A = Counter([int(i) for i in input().split()])

ans = 0
for k, v in A.items():
    tmp = v + A[k-1] + A[k+1]
    if tmp > ans:
        ans = tmp
    
print(ans)

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

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

for i in range(n):
    a = A[i]
    for j in [a-1, a, a+1]:
        if j not in dic:
            dic[j] = 1
        else:
            dic[j] += 1

cou = 0
for x in dic:
    re_cou = dic[x]
    cou = max(cou, re_cou)

print(cou)

Solution (Python):
import bisect
N = int(input())
a = list(map(int, input().split()))
a.sort()
s = [0]*(10**5+1)

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

Solution (Python):
import bisect
N = int(input())
a = list(map(int, input().split()))
a.sort()
s = [0]*(10**5+1)

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

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



bucket = [0]*100000
for ak in a:
    bucket[ak]+=1
ans = 0
for i in range(1,99999):
    ans = max(ans,bucket[i-1] + bucket[i] + bucket[i+1])
print(ans)

Solution (Python):
def abc072_c():
    from collections import Counter
 
    _ = int(input())
    a = list(map(int, input().split()))
    a_ex = []
    for num in a:
        a_ex.append(num)
        a_ex.append(num-1)
        a_ex.append(num+1)
 
    print(max(Counter(a_ex).values()))
 
 
abc072_c()

Solution (Python):
import collections
n = int(input())
A = list(map(int,input().split()))
counter = collections.Counter(A)
max_A = max(A)
cnt = 0

for i in range(-1,max_A):
    temp_cnt = counter[i-1] + counter[i] + counter[i+1]
    cnt = max(cnt,temp_cnt)

print(cnt)

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

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

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

mx = 0
for dd in d:
    mx = max(d[dd], mx)
print(mx)

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

Solution (Python):
import sys
from collections import Counter

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):

    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    A = il()
    A_p, A_n = [0] * N, [0] * N
    for i in range(N):
        A_p[i] = A[i] + 1
        A_n[i] = A[i] - 1
    c = Counter(A + A_p + A_n)
    m = max(c.values())
    return m


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

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

Solution (Python):
import bisect
n = int(input())
a = sorted([int(i) for i in input().split()])
ans = 0
if n > 1:
 for i in range(100005):
  tmp = bisect.bisect_right(a,i+2)-bisect.bisect_left(a,i)
  ans = max(ans,tmp)
else:
  ans = 1
print(ans)

Solution (Python):
from collections import Counter




n=int(input())
a=[int(i) for i in input().split()]
b=[i-1 for i in a]
c=[i+1 for i in a]
d=a+b+c

counter = Counter(d)

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

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

num = [0] * (10**5+2)
for i in A:
    num[i] += 1
    num[i+1] += 1
    num[i+2] += 1

print(max(num))

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

import collections
 
c=collections.Counter(a)
l=c.most_common()

from operator import itemgetter

l.sort(key=itemgetter(0))   
    

ans=0
for i in range(len(l)-2):
    if int(l[i][0])+1==int(l[i+1][0]) and int(l[i+1][0])+1==int(l[i+2][0]):
        ans=max(ans,l[i][1]+l[i+1][1]+l[i+2][1])
    elif int(l[i][0]+1)==int(l[i+1][0]):
        ans=max(ans,l[i][1]+l[i+1][1])
    else:
        ans=max(ans,l[i][1])

if len(l)==1:
    ans=l[0][1]

if len(l)==2:
    if int(l[1][0])-int(l[0][0])<=2:
        ans=l[0][1]+l[1][1]
    else:
        ans=max(ans,l[0][1],l[1][1])
        
print(ans)

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

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

for i in range(N):
    tmp = arr[i]
    carr[tmp] += 1
  
max = 0
for i in range(10**5-2):
    sum = carr[i] + carr[i+1] + carr[i+2]
    if max < sum:
        max = sum
print(max)

Solution (Python):
N=int(input())
A=[0]*(10**5+2)

a=list(map(int,input().split()))
for i in range(N):
    for j in range(3):
        A[a[i]-1+j]+=1
print(max(A))

Solution (Python):
def abc072_c():
    from collections import Counter

    _ = int(input())
    a = list(map(int, input().split()))
    a_ex = []
    for num in a:
        a_ex.extend([num-1, num, num+1])

    print(max(Counter(a_ex).values()))


abc072_c()

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

    x = [0]*10**5

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

    ans = 0
    for i in range(len(x)):
        count = 0
        if i == 0:
            ans = max(x[0] + x[1], ans)
        elif i == len(x)-1:
            ans = max(x[len(x)-2] + x[len(x)-1], ans)
        else:
            ans = max(x[i-1] + x[i] + x[i+1], ans)

    print(ans)

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

b = [0] * int(1e5)
c = [0] * int(1e5)
for _a in a:
    b[_a] += 1

for i in range(int(1e5)):
    if i != 0:
        c[i] += b[i-1]
    if i != int(1e5-1):
        c[i] += b[i+1]
    c[i] += b[i]

print(max(c))

Solution (Python):
def main():
    _ = input()
    aa = list(map(int, input().split()))
    counts = [0] * 100001
    for a in aa:
        counts[a] += 1
    res = max(counts[0] + counts[1], counts[10000-1] + counts[100000])
    for i in range(1, 100000):
        res = max(res, counts[i - 1] + counts[i] + counts[i + 1])
    print(res)


if __name__ == '__main__':
    main()

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

Solution (Python):
if __name__ == '__main__':
    num = int(input())
    int_list = [int(i) for i in input().split()]

    result = {}
    for i in int_list:
        if str(i) in result:
            result[str(i)] += 1
        else:
            result[str(i)] = 1

        if str(i + 1) in result:
            result[str(i + 1)] += 1
        else:
            result[str(i + 1)] = 1

        if str(i - 1) in result:
            result[str(i - 1)] += 1
        else:
            result[str(i - 1)] = 1

    print(max(result.values()))

Solution (Python):
import collections

n = int(input())
nums = list(map(int, input().split()))
nums2 = [0] * 3 * n
nums2_i = 0
for num in nums:
  nums2[nums2_i] = num - 1
  nums2_i += 1
  nums2[nums2_i] = num
  nums2_i += 1
  nums2[nums2_i] = num + 1
  nums2_i += 1


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

Solution (Python):
import bisect as bi
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(a[0], a[n-1]+1):
	ans = max(ans, bi.bisect_right(a, i+1)-bi.bisect_left(a, i-1))
print(ans)

Solution (Python):
import collections
N=int(input())
A=list(map(int,input().split()))
B=dict(collections.Counter(A))
a=0
Bk=B.keys()
for i in Bk:
    if i-1 in Bk:
        if i+1 in Bk:
            if a<B[i]+B[i-1]+B[i+1]:
                a=B[i]+B[i-1]+B[i+1]
        else:
            if a<B[i]+B[i-1]:
                a=B[i]+B[i-1]
    elif i+1 in Bk:
        if a<B[i]+B[i+1]:
            a=B[i]+B[i+1]
    else:
        if a<B[i]:
            a=B[i]
print(a)

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

Solution (Python):
import collections as cl
N = int(input())
a_li = [int(i) for i in input().split()]
a_li2 = [i-1 for i in a_li]
a_li3 = [i+1 for i in a_li]
a_li.extend(a_li2)
a_li.extend(a_li3)
c = cl.Counter(a_li)
print(c.most_common()[0][1])

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

print(max(b))

Solution (Python):
N = int(input())
a = [int(i) for i in input().split(" ")]
dic = dict()

for A in a:
    l = [A-1,A,A+1]
    for i in l:
        if not i in dic:
            dic[i] = 1
        else:
            dic[i] += 1
            
dic = sorted(dic.items(), key=lambda x: x[1])
dic.reverse()
print(dic[0][1])

Solution (Python):
n = int(input())
num_list = list(map(int, input().split()))
m = {}
for i in range(-1, 10**5+2):
    m[i] = 0
for i in num_list:
    m[i-1] += 1
    m[i] += 1
    m[i+1] += 1
ans_list = m.values()
print(max(ans_list))

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
b = []
c = {}
for i in a:
    b.append(i-1)
    b.append(i)
    b.append(i+1)

for i in b:
    if i in c.keys():
        c[i] = c[i]+1
    else:
        c[i] = 1

print(sorted(c.items(),key = lambda x: x[1],reverse = True)[0][1])

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

Solution (Python):
from collections import Counter

n = int(input())
num_list = list(map(int,input().split()))
plus_list  = [num+1 for num in num_list]
minus_list = [num-1 for num in num_list]
result_list = num_list+plus_list+minus_list
result_cntr = Counter(result_list).most_common()
print(result_cntr[0][1])

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
table = [0 for i in range(10**5+2)]
for i in range(len(a)):
    table[a[i]] += 1
    if a[i] > 0:
        table[a[i]-1] += 1
    table[a[i] + 1] += 1
maxCount = 0
for i in range(len(table)-1):
    maxCount = max(maxCount, table[i])
print(maxCount)

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

Solution (Python):
import bisect

N = int(input())
A = sorted([int(i) for i in input().split()])
ans = 0
for i in set(A):
    l = bisect.bisect_left(A, i-1)
    r =  bisect.bisect_right(A, i+1)
    ans = max(ans, r-l)
print(ans)

Solution (Python):

from collections import Counter

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

ad = Counter(a)
cnt = 0
for x in range(a[0]-1, a[-1]+2):
    c = ad[x]+ad[x-1]+ad[x+1]
    cnt = max(c,cnt)

print(cnt)

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

Solution (Python):

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

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

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

print(max(cnt))

Solution (Python):
import collections

n=int(input())
l=list(map(int,input().split()))
s=collections.Counter(l)
s=list(s.items())
s=sorted(s,key=lambda x:x[0])

f=[0]*len(s)
for i in range(len(s)):
    f[i]=s[i][1]
    if i>=1:
        if s[i-1][0]==s[i][0]-1:
            f[i]+=s[i-1][1]
    if i<=len(s)-2:
        if s[i+1][0]==s[i][0]+1:
            f[i]+=s[i+1][1]
print(max(f))