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()))
M = [0]*(10**5+10)
for a in A:
    for i in range(3): M[a+i]+=1
print(max(M))

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

d = dict(Counter(a) + Counter(b) + Counter(c))
print (max(d.values()))

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

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

import collections
counter=collections.Counter(a)

ans=0
for key in counter.keys():
  s=0
  s+=counter[key]
  if key+1 in counter:
    s+=counter[key+1]
  if key-1 in counter:
    s+=counter[key-1]
  ans=max(ans,s)
  
print(ans)

Solution (Python):
n = int(input())
dic = {}
List = list(map(int,input().split()))

for item in List:
  mini_list = [item-1,item,item+1]
  for value in mini_list:
    if value not in dic:
      dic[value] = 1
    else:
      dic[value] +=1

print(max(dic.values()))

Solution (Python):
import collections

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

b = list()
c = list()

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

d = collections.Counter(a + b + c)

print(max(d.values()))

Solution (Python):
from collections import Counter

N = int(input())
A = Counter(list(map(int,input().split())))
keysA =  list(A.keys())
len_keysA = len(keysA)

if len_keysA == 1:
  print(N)
  exit()
ans = -float('inf')
for i in range(len_keysA):
  tmp_ans = A[keysA[i]]
  if i != 0 and abs(keysA[i]-keysA[i-1]) <= 1: tmp_ans += A[keysA[i-1]]
  if i != len_keysA-1 and abs(keysA[i]-keysA[i+1]) <= 1: tmp_ans += A[keysA[i+1]]  
  ans = max(ans, tmp_ans)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

N = int(input())
A = list(map(int, input().split()))
B = [0] * 100003
for i in range(N):
    B[A[i]] += 1

max = 0
for i in range(100002):
    if max < B[i - 1] + B[i] + B[i + 1]:
        max = B[i - 1] + B[i] + B[i + 1]
print(max)

Solution (Python):

import collections

N = int(input())
a_list = [int(e) for e in input().split()]

c = collections.Counter(a_list)

ans = 1

for number in sorted(c.items(), reverse=False):
    
    
    
    
    if ans < c[number[0]-1] + number[1] + c[number[0]+1]:
        ans = c[number[0]-1] + number[1] + c[number[0]+1]
        
print(ans)

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

Solution (Python):
from sys import stdin

n, *a = (int(x) for x in stdin.read().split())

count = {i: 0 for i in set(a)}
for i in a: count[i] += 1 

suite_count = count.copy()
for i in count:
    if i - 1 in count: suite_count[i] += count[i-1]
    if i + 1 in count: suite_count[i] += count[i+1]

print(max(suite_count.values()))

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    max_A = max(A)
    counts = [0] * (max_A + 2)
    for a in A:
        if a > 0:
            counts[a-1] += 1
        counts[a] += 1
        counts[a+1] += 1
    print(max(counts))


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    _ = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter, defaultdict
    c = defaultdict(int)
    for k, v in Counter(A).items():
        c[k] = v
    ans = 0
    for i in range(max(A) + 1):
        if i != 0:
            cur = c[i] + c[i-1] + c[i+1]
        else:
            cur = c[i] + c[i+1]
        ans = max(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    _ = int(input())
    A = [int(i) for i in input().split()]
    A.sort()
    from collections import Counter, defaultdict
    c = defaultdict(int)
    for k, v in Counter(A).items():
        c[k] = v
    ans = 0
    for i in range(10**5+1):
        if i != 0:
            cur = c[i] + c[i-1] + c[i+1]
        else:
            cur = c[i] + c[i+1]
        ans = max(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split(' ')]
A.sort()
B = [0]*(A[N-1]+3)

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

print(max(B))

Solution (Python):
from collections import defaultdict

def solve():
    N = int(input())
    A = map(int, input().split())
    d = defaultdict(lambda:0)
    for a in A:
        d[a]+=1
        d[a-1]+=1
        d[a+1]+=1
    
    print(max(d.values()))
    
solve()

Solution (Python):
from collections import Counter

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

count_max = 0
C = Counter(A)
for i in range(min(C.keys()), max(C.keys()) + 1):
    count = C.get(i-1, 0) + C.get(i, 0) + C.get(i+1, 0)
    count_max = max(count_max, count)
print(count_max)

Solution (Python):
input()
list_ = sorted(map(int, input().rstrip("\n").split()))

dict_ = dict()
for key in list_:
    dict_[key] = dict_.get(key, 0) + 1

max_ = 0
for key in set(list_):
    num = dict_[key] + dict_.get(key - 1, 0) + dict_.get(key + 1, 0)
    max_ = num if num > max_ else max_
print(max_)

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

    c = [0] * (100000 + 2)
    for ai in A:
        c[ai+1] += 1
        c[ai] += 1
        c[ai+2] += 1

    print(max(c))

if __name__ == "__main__":
    main()

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

    c = [0] * (100000 + 1)
    for ai in A:
        c[ai] += 1

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

if __name__ == "__main__":
    main()

Solution (Python):
import sys

N=int(input())

a=[int(t.strip()) for t in input().split()]

num=[]
num= [0] * (max(a)+3)
for i in range(N):
	num[a[i]] += 1
	
maximum=0
for i in range(len(num)-2):
	tmp=num[i] + num[i+1] +num[i+2]
	if maximum < tmp:
		maximum = tmp

print(maximum)

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

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

if len(c)==1:
    T=1
else:
    T=c[0]+c[1]+c[2]
    for i in range(m):
        T=max(T,c[i-1]+c[i]+c[i+1])
print(T)

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

import collections
a = list(map(int,input().split()))
A = [] * 3 * N
for i in range(len(a)):
    A.append(a[i] - 1)
    A.append(a[i])
    A.append(a[i] + 1)

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

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

import collections
a = list(map(int,input().split()))
b = [[0] * 3 for i in range(N)]
A = [] * 3 * N
for i in range(len(a)):
    b[i][0] = a[i] - 1
    b[i][1] = a[i]
    b[i][2] = a[i] + 1
    A.append(a[i] - 1)
    A.append(a[i])
    A.append(a[i] + 1)

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

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

mx = max(A)

score = [0]*(mx+3)

for i in A:
    score[i] += 1
    score[i+1] += 1
    score[i+2] += 1

print(max(score))

Solution (Python):
import collections

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

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


count = []
for i in range(10 ** 5):
    count.append(0)

for i in a:
    if i >= 1:
        count[i - 1] += 1
    if i < 10 ** 5 - 1:
        count[i + 1] += 1
    count[i] += 1

print(sorted(count, reverse = True)[0])

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

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

if len(C)==1:
    print(C[0])
else:
    T=max(C[0]+C[1],C[-1]+C[-2])
    for i in range(1,max(A)):
        T=max(T,C[i-1]+C[i]+C[i+1])
    print(T)

Solution (Python):
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    numbers = string_to_int(inputs[0])
    counter = collections.Counter()

    for n in numbers:
        counter[n-1] += 1
        counter[n] += 1
        counter[n+1] += 1

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


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Solution (Python):
import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
max = 0
for i in range((10 ** 5 ) + 1):
    cand = bisect.bisect_left(a, i + 3) - bisect.bisect_left(a, i)
    if max < cand:
        max = cand
print(max)

Solution (Python):

import sys
import bisect

def solve(N: int, a: "List[int]"):
    a.sort()
    answer = 0
    for i in range(N):
        count = bisect.bisect_left(a,a[i]+3)
        answer = max(answer,count-i)
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    solve(N, a)

if __name__ == '__main__':
    main()

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

for x in a:
  table[x]+=1
  table[x+1]+=1
  table[x-1]+=1
table=list(table.values())
print(max(table))

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
d={}
for ai in a:
    if ai not in d:
        d[ai]=1
    else:
        d[ai]+=1

s={}
for ai in d:
    k=d[ai]
    if ai-1 in d:
        k+=d[ai-1]
    if ai+1 in d:
        k+=d[ai+1]
    s[ai]=k

print(max(s.values()))

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

d={}
for a in A:
	for i in [a-1,a,a+1]:
		if i not in d:
			d[i]=1
		else:
			d[i]+=1

print(max(d.values()))

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

def addToMap(v):
    if v in m:
        m[v] += 1
    else:
        m[v] = 1

for i in range(n):
    v1, v2, v3 = a[i]-1, a[i], a[i]+1
    addToMap(v1)
    addToMap(v2)
    addToMap(v3)

maxK = 0
maxV = 0

for key, val in m.items():
    if val > maxV:
        maxK = key
        maxV = val

print(maxV)

Solution (Python):
n=int(input())
a=list(map(lambda x: int(x), input().split()))
a.sort()
cnt=[]
val=[]
last=-1
for i in a:
    if i == last:
        cnt[-1]+=1
    else:
        cnt.append(1)
        val.append(i)
        last = i

low_val=-10
low_cnt=0
mid_val=0
mid_cnt=0
ans=0
for i, v in enumerate(val):
    if v>=low_val+3:
        ans=max(ans, low_cnt+mid_cnt)
        low_val=v
        low_cnt=cnt[i]
        mid_val=0
        mid_cnt=0
    elif v==low_val+2:
        ans=max(ans, low_cnt+mid_cnt+cnt[i])
        if mid_val>0:
            low_val=mid_val
            low_cnt=mid_cnt
            mid_val=v
            mid_cnt=cnt[i]
        else:
            low_val=v
            low_cnt=cnt[i]
            mid_val=0
            mid_cnt=0
    if v==low_val+1:
        mid_val=v
        mid_cnt=cnt[i]
ans=max(ans, low_cnt+mid_cnt)
print(ans)

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

for i in range(len(d)):
    if i == 0:
        ans = max(ans, d[i] + d[i + 1])
        continue
    elif i == len(d) - 1:
        ans = max(ans, d[i - 1] + d[i])
        continue
    ans = max(ans, d[i-1] + d[i] + d[i + 1])

print(ans)

Solution (Python):
n=int(input())
a=list(map(lambda x: int(x), input().split()))
dic={}
for i in a:
    dic[i]=dic.get(i,0)+1
tmp=dic.get(0,0)+dic.get(1,0)
ans=0
for i in range(2,100000):
    tmp+=dic.get(i,0)
    if tmp>ans:
        ans=tmp
    tmp-=dic.get(i-2,0)
print(ans)

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

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

Solution (Python):
n=int(input())
l=[int(i) for i in input().split()]
from collections import defaultdict 
d=defaultdict(int)
for i in l: 
    d[i]+=1 
    d[i+1]+=1 
    d[i-1]+=1 
print(max(d.values()))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
cnt = [0] * 100004

for x in a:
   cnt[x-1]+=1
   cnt[x]+=1
   cnt[x+1]+=1
ans = -1
for i in range(len(cnt)):
   if cnt[i] > ans:
      ans = cnt[i]
print(ans)

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

b = list()
for i in range(100000):
    b.append(0)

for i in range(n):
    b[a[i]] += 1
    
c = list()    
for i in range(100000):
    if(i==0):
        if(b[i]):
            c.append(b[i+1]+b[i])
    elif(i==99999):
        if(b[i]):
            c.append(b[i-1]+b[i])
    else:
        if(b[i]):
            c.append(b[i-1]+b[i+1]+b[i])
        
print(max(c))

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

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

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

Solution (Python):
import collections

def test():
    n = int(input())
    a = [int(x) for x in input().split()]
    b = collections.Counter(a)
    ans = 0
    for x in range(max(a)+1):
        ex = b[x]
        if x - 1 in b:
            ex += b[x-1]
        if x + 1 in b:
            ex += b[x+1]
        ans = max(ans,ex)

    print(ans)


if __name__ == "__main__":
    test()

Solution (Python):
import collections
n = int(input())
list_a = list(map(int, input().split()))
count = collections.Counter(list_a)
max_x = [-1, -1]
for k, v in count.items():
  temp_num = v
  if k-1 in count.keys():
    temp_num += count[k-1]
  if k+1 in count.keys():
    temp_num += count[k+1]
  if temp_num > max_x[1]:
    max_x[0] = k
    max_x[1] = temp_num
print(max_x[1])

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

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

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

for i in range(N):
  res[a[i]-1]+=1
  res[a[i]]+=1
  res[a[i]+1]+=1
print(max(res))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
cnt={}
for i in range(min(a)-1,max(a)+2):
    cnt[i]=0
for i in a:
    if i in cnt:
        cnt[i]+=1
M=0
for i in a:
    if M < cnt[i-1]+cnt[i]+cnt[i+1]:
        M = cnt[i-1]+cnt[i]+cnt[i+1]
print(M)

Solution (Python):
import collections

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

c = collections.Counter(a)
ans = 0

for i in range(max(a)+1):
    cnt = c[i]
    if i-1 in c:
        cnt += c[i-1]
    if i+1 in c:
        cnt += c[i+1]
    ans = max(ans, cnt)

print(ans)

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
M=B[0]+B[1]+B[2]
for i in range(10**5-1):
  M=max(M,B[i]+B[i+1]+B[i+2])
print(M)

Solution (Python):
from collections import defaultdict

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

d = defaultdict(int)
for a_ in a:
    d[a_-1] += 1
    d[a_] += 1
    d[a_+1] += 1

res = max(d.values())
print(res)

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

for i in a:
    X[i] += 1
    X[i + 1] += 1
    X[i + 2] += 1
print(max(X))

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

for n in range(N):
  plus=li[n]+1
  minus=li[n]-1
  li.append(plus)
  li.append(minus)

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

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

for n in range(N):
  plus=li[n]+1
  minus=li[n]-1
  li.append(plus)
  li.append(minus)

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

Solution (Python):
import collections

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

c = collections.Counter(a)

max_value = -1
for ci in c.most_common():
    cnt = ci[1]

    index = ci[0]
    if index-1 in c:
        cnt += c[index-1]
    if index +1 in c:
        cnt += c[index+1]
    max_value = max(max_value, cnt)

print(max_value)

Solution (Python):
n = int(input())
a = [0 for _ in range(10**5 +2)]
b = [0 for _ in range(10**5 +2)]
c = [0 for _ in range(10**5 +2)]

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

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

ans = [x+y+z for x,y,z in zip(a,b,c)]
print(max(ans))

Solution (Python):
import collections

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

a_count = collections.Counter(a)

ans_list = []
for x in range(min(a), max(a)+1):
    ans_list.append(a_count[x-1] + a_count[x] + a_count[x+1])
        
print(max(ans_list))

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

Solution (Python):
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n = int(input())
    as_ = list(map(int, input().split()))
    counter_a_tmp = collections.Counter(as_)
    counter_a = collections.defaultdict(int)
    for key, count in counter_a_tmp.items():
        counter_a[key] = count

    ans = 0
    if max(as_) == 0:
        print(n)
    else:
        for i in range(0, max(as_) - 1):
            ans = max(ans, counter_a[i] + counter_a[i + 1] + counter_a[i + 2])

        print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

from collections import Counter
N = int(input())
A = list(map(str,input().split()))
L = [0]*100001
C = Counter(A)
C = C.items()

if N == 1:
    ans = 1
else:
    for c in C:
        idx,v = c
        idx = int(idx)
        L[idx] = v

    ans = 0
    for i in range(N-1):
        if i == 0:
            ans = L[0] + L[1]
            continue
        ans = max(ans,L[i-1]+L[i]+L[i+1])

print(ans)

Solution (Python):
def main():
  n = int(input())
  ans = 0
  a_lis = list(map(int,input().split()))
  A_dict = [0]*(10**5+1)
  for i in a_lis:
    A_dict[i] += 1
  for j in range(1,10**5):
    tmp = A_dict[j-1]+A_dict[j]+A_dict[j+1]
    if tmp > ans:
      ans = tmp
  print(ans)

if __name__=='__main__':
  main()

Solution (Python):
from collections import defaultdict

n = int(input())
ans = 0

a_lis = list(map(int,input().split()))
A_dict = [0]*(10**5+1)

for i in a_lis:
  A_dict[i] += 1

for j in range(1,10**5):
  tmp = A_dict[j-1]+A_dict[j]+A_dict[j+1]
  if tmp > ans:
    ans = tmp
print(ans)

Solution (Python):
from collections import defaultdict

n = int(input())

a_lis = list(map(int,input().split()))
A_dict = defaultdict(int)

for i in a_lis:
  A_dict[i] += 1
  
max_cnt = 0

for j in range(1, 10**5):
  tmp = A_dict[j-1]+A_dict[j]+A_dict[j+1]
  max_cnt = max(max_cnt, tmp)
print(max_cnt)

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

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

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

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

print(ans)

Solution (Python):
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    b = []
    for i in range(len(a)):
        b.append(a[i])
        b.append(a[i]+1)
        b.append(a[i]-1)
    b = collections.Counter(b).most_common()
    print(b[0][1])


if __name__ == '__main__':
    slove()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
z = 100002*[0]

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

print(max(z))

Solution (Python):
import collections
N = int(input())
A = [int(i) for i in input().split()]
Dict = dict(collections.Counter(A))
Cnt = []
for key in Dict.keys():
    cnt = Dict[key]
    Cnt.append([key,cnt])
Cnt.sort()
dp = [0 for i in range(len(Cnt)+1)]
Cnt.append([float('inf'),0])
if len(Cnt)<3:
    print(Cnt[0][1])
    exit()
else:
    if Cnt[1][0]-1==Cnt[0][0]:
        dp[0] = Cnt[0][1]+Cnt[1][1]
for i in range(1,len(Cnt)-1):
    if Cnt[i][0]==Cnt[i-1][0]+1:
        dp[i] += Cnt[i-1][1]
    if Cnt[i+1][0]-1==Cnt[i][0]:
        dp[i]+=Cnt[i+1][1]
    dp[i] += Cnt[i][1]
print(max(dp))

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

cnt = [0] * 1000010
for i in a:
    cnt[i] += 1
    cnt[i+1] += 1
    cnt[i-1] += 1

print(max(cnt))

Solution (Python):
Dic = {}

def adddic(n):
    if n in Dic:
        Dic[n] += 1
    else:
        Dic[n] = 1

N = int(input())
D = list(map(int,input().split()))
for n in range(N):
    adddic(D[n]-1)
    adddic(D[n])
    adddic(D[n]+1)
ans = 0
for key,value in Dic.items():
    ans = max(ans,value)
print(ans)

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

for i in A:
  D[i-1] += 1
  D[i]   += 1
  D[i+1] += 1
print (sorted(D.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(min(a),max(a)+1):
  ans=max(ans,c[i-1]+c[i]+c[i+1])
print(ans)

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
z = 100002*[0]

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

print(max(z))

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

t = [0] * (10 ** 5 + 3)  
for x in a:
    for i in range(x - 1, x + 2):
        t[i] += 1
print(max(t))

Solution (Python):

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

t = [0] * (10 ** 5 + 3)  
for x in a:
    t[x] += 1
    t[x + 3] -= 1

for i in range(1, 10 ** 5 + 3):
    t[i] += t[i-1]

print(max(t))

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

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

arr_c=collections.Counter(arr)

print(max(arr_c.values()))

Solution (Python):
from collections import Counter

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

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

from collections import Counter 

c = Counter(As)

ans = 0

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

Solution (Python):
import numpy as np
n = int(input())
dp = np.array([0]* 100010)
for j in map(int,input().split()):
    dp[j] += 1;dp[j+1] += 1;dp[j+2] += 1
print(np.max(dp))

Solution (Python):
import numpy as np
n = int(input())
dp = np.array([0]* 100010)
for i,j in enumerate(map(int,input().split())):
    if j -1 < 0: dp[j] += 1;dp[j+1] +=1
    else:dp[j] += 1;dp[j-1] += 1;dp[j+1] += 1
print(np.max(dp))

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

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

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

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

Solution (Python):
import collections

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

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

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

cnt = 0
for i in d:
    d1 = 0
    d2 = 0
    if (i - 1) in d:
        d1 = d[i - 1]
    if (i + 1) in d:
        d2 = d[i + 1]

    cnt = max(cnt, d[i] + d1 + d2)

print(cnt)

Solution (Python):
from collections import Counter

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

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

Solution (Python):
import collections
n = int(input())
A = list(map(int,input().split()))
Cou = collections.Counter(A)
Ite = list(Cou.items());Ite.sort()
ans = 0
for i in range(len(Ite)):
    num = Ite[i][0];cou = Ite[i][1]
    if i > 0 and Ite[i-1][0] == num-1:
        cou += Ite[i-1][1]
    if i < len(Ite)-1 and Ite[i+1][0] == num+1:
        cou += Ite[i+1][1]
    ans = max(ans,cou)
print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
b = [0] * (10 ** 5 + 2)

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

Solution (Python):
from collections import Counter

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

for i in ac.keys():
    ans = max(ans, ac[i] + ac[i + 1] + ac[i - 1])

print(ans)

Solution (Python):
from collections import Counter

N = int(input())
a = list(map(int, input().split()))
ac = Counter(a)
ak = list(ac.keys())
ans = 0

for i in ak:
    ans = max(ans, ac[i] + ac[i + 1] + ac[i - 1])

print(ans)

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

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

print(max(count))

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

Solution (Python):


n = int(input())
l = list(map(int, input().split()))
allx = [0 for _ in range(-1, 10**5+1)]

for value in l:
    allx[value+2] += 1
    allx[value+1] += 1
    allx[value] += 1

print(max(allx))

Solution (Python):
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
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())
A = [int(x) for x in input().split()]
L = [0] * (10 ** 5 + 4)
for a in A:
  L[a] += 1
  L[a + 3] -= 1

s = 0
for i, l in enumerate(L):
  s += l
  L[i] = s
  
print(max(L))

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

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

print(max(ary))

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

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

print(max(ary))

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

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

print(max(ary))

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

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

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

last = None
d = {}
for i in a:
  if last != i:
    d[i] = 1
    last = i
  else:
    d[i] += 1

out = -1
for x in range(a[0], a[-1]+1):
  s = 0
  if x-1 in d.keys():
    s += d[x-1]
  if x in d.keys():
    s += d[x]
  if x+1 in d.keys():
    s += d[x+1]
  if out < s:
    out = s
  
print(out)

Solution (Python):
from collections import Counter

N = int(input())
a_s = input().split()
a_s = [int(a_s[i]) for i in range(N)]

c = Counter(a_s)
c = sorted(c.items(), key=lambda x:x[0])
a_unique, a_counts = zip(*c)

ans = 0
for i,a in enumerate(a_unique):
    val = a_counts[i]
    if (i>0):
        if (a_unique[i-1]+1==a):
            val += a_counts[i-1]
            
    if (i<len(a_unique)-1):
        if (a_unique[i+1]-1==a):
            val += a_counts[i+1]
    
    if val > ans:
        ans = val
        
print(ans)

Solution (Python):
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
S=sorted(Counter(A).most_common())
if len(S)==1:
	print(S[0][1])
else:
	S.insert(0,(-2,0))
	S.append((-2,0))
	c=1
	for i in range(1,len(S)-2):
		r=S[i-1][1] if S[i-1][0]==S[i][0]-1 else 0
		l=S[i+1][1] if S[i+1][0]==S[i][0]+1 else 0
		c=max(c,S[i][1]+r+l)
	print(c)

Solution (Python):
from collections import Counter

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

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

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

Solution (Python):
import collections

n = int(input())
counter = collections.Counter()
ls = list(map(int, input().split()))
for k in ls:
    counter[k] += 1
res = 0
for key in sorted(counter.keys()):
    res = max(res, counter[key - 1] + counter[key] + counter[key + 1])
print(res)