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
import math
from fractions import gcd

from collections import Counter



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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())


 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N = int(sys.stdin.readline())
L = list(map(int, sys.stdin.readline().split()))

LM = list(map(lambda x : x - 1, L))
LP = list(map(lambda x : x + 1, L))

X = LM + L + LP



Xc = Counter(X)

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

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

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
l.sort()
lcount=[]
count=0
now=l[0]
for i in range(n):
  if now==l[i]:
    count+=1
  else:
    lcount.append([count,now])
    count=1
    now=l[i]
lcount.append([count,now])
if len(lcount)==1:
  print(n)
elif len(lcount)==2:
  l1=lcount[0][0]
  l2=lcount[1][0]
  if lcount[1][1]-lcount[0][1]==1:
    print(l1+l2)
  else:
    print(max(l1,l2))
else:
  count=0
  for i in range(1,len(lcount)-1):
    scount=0
    scount+=lcount[i][0]
    if lcount[i][1]-lcount[i-1][1]==1:
      scount+=lcount[i-1][0]
    if lcount[i][1]-lcount[i+1][1]==-1:
      scount+=lcount[i+1][0]
    if scount>count:
      count=scount
  count1=lcount[0][0]
  if lcount[1][1]-lcount[0][1]==1:
    count1+=lcount[1][0]
  count2=lcount[-1][0]
  if lcount[-2][1]-lcount[-1][1]==-1:
    count2+=lcount[-2][0]
  print(max(count,count1,count2))

Solution (Python):
import collections

num = int(input())
s = sorted(list(map(int, input().split())))
if num == 1:
    print(1)
else:
    c = collections.Counter(s)
    max_ans = 0
    for i in range(num):
        start = s[i]
        current_ans = c[start]+c[start+1]+c[start+2]
        max_ans = max(current_ans,max_ans)
        i += c[start]
    print(max_ans)

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

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



N = I()
a = III()

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

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

print(ans)

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

Solution (Python):
from collections import defaultdict


def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(int)
    for ai in a:
        for i in range(ai - 1, ai + 2):
            d[i] += 1
    m = max(d.items(), key=lambda x: x[1])
    print(m[1])


if __name__ == "__main__":
    resolve()

Solution (Python):


from collections import Counter

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

c = Counter(a)

st = set()
for key in c.keys():
    for i in (-1, 0, 1):
        st.add(key + i)

ans = 0
for x in st:
    cnt = c[x-1] + c[x] + c[x+1]
    ans = max(ans, cnt)

print(ans)

Solution (Python):


from collections import Counter

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

c = Counter(a)
keys = c.keys()

st = set()
for key in keys:
    for i in (-1, 0, 1):
        st.add(key + i)

ans = 0
for x in st:
    cnt = c[x-1] + c[x] + c[x+1]
    ans = max(ans, cnt)

print(ans)

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

d = dict()

for i in a:
    d[i] = d.get(i, 0) + 1

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

d = [(0, 0)] + d + [(0, 0)]

ans = 1

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

print(ans)

Solution (Python):

N=int(input())
a=list(map(int,input().split()))
L=max(a)+1
b=[0]*L

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

ans=0

if L<=2:
    print(sum(b))
else:    
    for p in range(L-2):
        ans = max(ans,b[p]+b[p+1]+b[p+2])

    print(ans)

Solution (Python):

import collections
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        a = list(map(int, input().split()))

        cnt = collections.Counter(a)

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



if __name__ == '__main__':
    AtCoder().main()

Solution (Python):
input()
C = [0] * 100002
for i in map(int, input().split()):
  C[i - 1] += 1
  C[i] += 1
  C[i + 1] += 1
print(max(C))

Solution (Python):
input()
C=[0]*100002
for i in map(int,input().split()):
  C[i-1]+=1
  C[i]+=1
  C[i+1]+=1
print(max(C))

Solution (Python):
import sys
import collections

input = sys.stdin.readline

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

l = collections.Counter(a)

points = 0

for i in l.keys():
    cnt = l[i] + l[i-1] + l[i+1]
    if points < cnt: points=cnt

print(points)

Solution (Python):
input();d={}
for a in map(int,input().split()):
 for i in[-1,0,1]:d[a+i]=d.get(a+i,0)+1
print(max(d.values()))

Solution (Python):
import collections as c

N = int(input())
A = c.Counter(list(map(int,input().split())))
key = list(A.keys())
val = list(A.values())


ans = 0
for i in range(len(key)):
	tmp = 0

	if i <= len(key) - 3:
		tmp += val[i]
		if key[i+1] <= key[i]+2:
			tmp  += val[i+1]
		if key[i+2] <= key[i]+2:
			tmp += val[i+2]
	elif i == len(key) - 2:
		tmp += val[i]
		if key[i+1] <= key[i]+2:
			tmp += val[i+1]
	else:
		tmp += val[i]

	ans = max(tmp, ans)

print(ans)

Solution (Python):
import collections
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
c = collections.Counter(data)
ans = 0
max_v = max(data)
for i in range(max_v+1):
    ans = max(ans,c[i]+c[i+1]+c[i+2])
print(ans)

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

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))
    
    d = {}
    for i in range(N):
        if a[i] in d.keys():
            d[a[i]] += 1
        else:
            d[a[i]] = 1
        
        if a[i] + 1 in d.keys():
            d[a[i] + 1] += 1
        else:
            d[a[i] + 1] = 1
        
        if a[i] - 1 in d.keys():
            d[a[i] - 1] += 1
        else:
            d[a[i] - 1] = 1
    
    d_new = sorted(d.items(), key=lambda x: x[1])
    print(d_new[-1][1])

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

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

    MAX = int(1e5)
    count = [0] * (MAX + 1)

    for t in a:
        if t > 0:
            count[t-1] += 1
        if t < MAX:
            count[t+1] += 1
        count[t] += 1
    
    max_ = count[0]
    for i in range(1, MAX+1):
        max_ = max(max_, count[i])
    print(max_)

if __name__ == "__main__":
    main()

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

dic = Counter(a)
for i,j in list(dic.items()):
    if i-1 in dic:
        dic[i-1]+=j
    elif i-1 not in dic:
        dic[i-1]=j
    if i+1 in dic:
        dic[i+1]+=j
    elif i+1 not in dic:
        dic[i+1]=j

print(max(dic.values()))

Solution (Python):
from collections import Counter
N = int(input().strip())
counter = Counter()
for i in list(map(int, input().strip().split(' '))):
  counter[i-1] += 1
  counter[i] += 1
  counter[i+1] += 1

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

Solution (Python):
from collections import*
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
a=Counter(a)
cnt=1
for i in range(min(a),max(a)+1):
	cnt_=a[i-1]+a[i]+a[i+1]
	if cnt_>cnt:cnt=cnt_
print(cnt)

Solution (Python):
from collections import*
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
a=Counter(a)
cnt=1
for i in range(min(a),max(a)+1):
	cnt_=a[i-1]+a[i]+a[i+1]
	if cnt_>cnt:cnt=cnt_
print(cnt)

Solution (Python):
import collections

N = int(input())
a = list(map(int,input().split()))
b = collections.Counter(a)
dp = [0] * (max(a)+1)
if len(b) == 1 and a[0] == 0:
    print(N)
    exit()
dp[0] = b[0] + b[1]
dp[1] = dp[0] + b[2]

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

Solution (Python):
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
li = na()
c = Counter(li)
ans = 1
for k in c.keys():
    ct = c[k] + c[k - 1] + c[k + 1]
    ans = max(ans, ct)
print(ans)

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

def main():
    N = int(input())
    a = list(map(int,input().split()))
    max_a = max(a)
    count = [0 for _ in range(max_a+1)]
    c = collections.Counter(a)
    c = list(c.items())

    if len(c) == 1:
        print(c[0][1])

    elif len(c) == 2:
        if abs(c[0][0]-c[1][0]) <= 2:
            print(c[0][1]+c[1][1])
        else:
            print(max(c[0][1],c[1][1]))

    else:
        for i in range(len(c)):
            count[c[i][0]] = c[i][1]

        sum_list = [0 for _ in range(len(count)-2)]
        for i in range(len(count)-2):
            sum_list[i] = count[i]+count[i+1]+count[i+2]
        print(max(sum_list))

if __name__ == "__main__":
    main()

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

X = [0] * (max(A) + 3)

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

print(max(X))

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

C = [0] * (max(A) + 3)

for i in A:
    for j in range(3):
        C[i+j] += 1
print(max(C))

Solution (Python):
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

ans = 0
n = inp()
a = inpl()
d = defaultdict(int)

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

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

Solution (Python):
import collections
N = int(input())
a = list(map(int, input().split()))
cand = collections.Counter(a)
cand_list = cand.most_common(len(set(a)))
ans = 0
for i in range(len(set(a))):
  num = cand_list[i][0]
  count = cand[num] + cand[num + 1] + cand[num - 1]
  ans = max(ans,count)

print(ans)

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

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

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


import collections

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

c = collections.Counter(A)

ans = 0
for a in A:
    tmp = c[a-1] + c[a] + c[a+1]
    ans = max(ans, tmp)

print(ans)

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

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

a.sort()

a_list = [0] * (a[-1]+1)

cnt = 0
tmp = 0

for i in range(a[-1]+1):
    
    while a[tmp] == i:
        
        cnt += 1
        tmp += 1
        if tmp == len(a):
            break
    a_list[i] = cnt
    cnt = 0

ans = 0

if len(a_list) == 1:
    print(a_list[-1])
    exit()

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

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

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

from collections import defaultdict
dic = defaultdict(int)

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

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
Ns = [0]*100005
for A in As:
  Ns[A-1] += 1
  Ns[A] += 1
  Ns[A+1] += 1
r = max(Ns)
print(r)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
a.sort()
M=0
s=0
for i in range(a[0],a[N-1]+1):
    t=0
    for j in range(s,N):
        if a[j]==i:
            t+=1
            s=j+1
        elif i+1<=a[j]<=i+2:
            t+=1
        else:
            break
    if t>M:
        M=t
print(M)

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

adict = {}
for i in alist:
	if str(i) in adict:
		adict[str(i)]+=1
	else:
		adict[str(i)]=1
	if str(i-1) in adict:
		adict[str(i-1)]+=1
	else:
		adict[str(i-1)]=1
	if str(i+1) in adict:
		adict[str(i+1)]+=1
	else:
		adict[str(i+1)]=1
print(max(adict.values()))

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):
    b[a[i]]+=1

maxim = -1
maximid=-1
if(n>=3):
    c = [b[i]+b[i+1]+b[i+2] for i in range(n-2)]
    for i in range(n-2):
        if(maxim<c[i]):
            maxim = c[i]
            maximid = i+1
    print(maxim)
else:
    if(len(a) == 2 and abs(max(a)-min(a))<=1):
        print(2)
    else:
        print(1)

Solution (Python):
from itertools import chain
from collections import Counter
n=int(input())
As=list(map(int,input().split()))
As = [[a-1, a, a+1] for a in As]
As = list(chain.from_iterable(As))

result_cntr = Counter(As).most_common()
print(result_cntr[0][1])

Solution (Python):
from collections import defaultdict

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

counter = defaultdict(int)
for i in range(N) :
    counter[a[i]-1] += 1
    counter[a[i]] += 1
    counter[a[i]+1] += 1

print(max(counter.values()))

Solution (Python):
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    d = dict()
    for a in A:
        d[a] = d.get(a, 0) + 1
        d[a+1] = d.get(a+1, 0) + 1
        d[a-1] = d.get(a-1, 0) + 1

    max_count = 0
    for a in d:
        if d[a] > max_count:
            max_count = d[a]
    return max_count




if __name__ == '__main__':
    print(main())

Solution (Python):
from collections import defaultdict

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    
    count = defaultdict(int)
    for aa in a:
        count[aa] += 1
        count[aa+1] += 1
        count[aa-1] += 1
    v = 0
    for k in count.keys():
        v = max(count[k], v)
    print(v)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
N = int(input())
A = [int(s) for s in input().split()]
c = Counter(A)
ans = max([c[k-1] + c[k] + c[k+1] for k in c.keys()])
print(ans)

Solution (Python):
import collections

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

dict = collections.Counter(a)

x_max = 0


for key in dict.keys():
  k = int( key )
  x_max = max(x_max, dict[str(k-1)]+dict[str(k)]+dict[str(k+1)])

    
print(x_max)

Solution (Python):
import collections

n = int(input())

a = list( input().split() )

dict = collections.Counter(a)






x_max = 0
mem_key = ""

for key in dict.keys():
  k = int( key )
  l = dict[str(k-1)]
  m = dict[str(k)]
  n = dict[str(k+1)]
  
  
  if l+m+n >= x_max:
    x_max = l+m+n
    mem_key = key
    
print(x_max)

Solution (Python):


import itertools
import collections

n = int(input().split()[0])
a_list = list(map(int, input().split()))

a_op_list = [[a-1, a, a+1] for a in a_list]
a_op_list = itertools.chain.from_iterable(a_op_list)
c = collections.Counter(a_op_list)
max_count = max(c.values())

print(max_count)

Solution (Python):
nums = int(input())
ary  = list(map(int,input().split()))
count =0
max_count = 0
ary.sort()
ary_count = [0 for i in range(100005)]
ary_count.append(0)

for i in ary:
    ary_count[i] += 1

for i in range(1,100005):
    count += ary_count[i]
    count += ary_count[i+1]
    count += ary_count[i-1]
    if count > max_count:
        max_count = count
    count = 0
print(max_count)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N = _I()
A = LI()

"""
最小値から最大値
の間には絶対収まる
1111155なら1でいい
なら、
各数字のカウントを保持する
"""
char_counts = [0]*(10**5+5)

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



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

Solution (Python):
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(map(int,input().split()))
a = collections.Counter(a)
a = sorted(a.items())
li = [0]*N
tmp = 0
if len(a)==1:
    print(a[0][1])
    exit()

for i in range(len(a)-1):
    tmp += a[i][1]
    if a[i][0]-1==a[i-1][0]:
        tmp += a[i-1][1]
    if a[i][0]+1==a[i+1][0]:
        tmp += a[i+1][1]
    li[i] = tmp
    tmp = 0

if a[-1][0]-1==a[-2][0]:
    li.append(a[-1][1]+a[-2][1])
print(max(li))

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

    if a+1 not in d:
        d[a+1] = 1
    else:
        d[a+1] += 1


print(max(d.values()))

Solution (Python):

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

ans=0


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


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



for i in range(10**5+1):
    if ans < sum(b[i:i+3]):
        ans=sum(b[i:i+3])

print(ans)

Solution (Python):


from collections import Counter

def main(N,A):
    A = Counter(A)
    elements = set(A)
    ans = 0
    
    for i in elements:
        tmp = A[i]
        if(i+1 in elements):
            tmp += A[i+1]
        if(i+2 in elements):
            tmp += A[i+2]
        ans = max(ans, tmp)

    print(ans)

if __name__ == '__main__':
    N = int(input())
    A = [int(a) for a in input().split()]
    main(N,A)

Solution (Python):

n = int(input())
num_list = [ int(v) for v in input().split() ]

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

for i in num_list:
    ans_list[i] += 1
    ans_list[i+1] += 1
    ans_list[i+2] += 1

print(max(ans_list))

Solution (Python):
from collections import Counter

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

a_dict = Counter(a_list)

new_a_dict = {}

for k,v in a_dict.items():
    for diff in [-1,0,1]:
        if k+diff in new_a_dict:
            new_a_dict[k+diff] += v
        else:
            new_a_dict[k+diff] = v

print(max(new_a_dict.values()))

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

Solution (Python):
from bisect import*;b=bisect;n,a=open(0);*a,=sorted(map(int,a.split()));print(max(b(a,i)-b(a,i-3)for i in range(10**5)))

Solution (Python):
from bisect import*;n,a=open(0);*a,=sorted(map(int,a.split()));print(max(bisect(a,i+1)-bisect(a,i-2) for i in range(10**5)))

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

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

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

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

print(sorted(L)[-1])

Solution (Python):

N = int(input())
a = list(map(int, input().split()))
b = [0] * 100001  
c = [0] * 99999
for i in range(N):
    b[a[i]] += 1
for i in range(99999):  
    c[i] = b[i] + b[i + 1] + b[i + 2]
print(str(max(c)))

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

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

counts = defaultdict(int)
for a in A:
    counts[a + 1] += 1
    counts[a] += 1
    counts[a - 1] += 1

print(max(counts.values()))

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
cnt = [0] * (max(A) + 2)


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

cnt.sort(reverse=True)
print(cnt[0])

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


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

cnt.sort()
print(cnt[-1])

Solution (Python):
import statistics,collections

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

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

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

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

d = {}

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

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

d[-1] = 0
d[max(a)+1] = 0

ans = 0

for x in range(max(a)+1):
  if x-1 in d:
    ans = max(ans, d[x-1] + d[x] + d[x+1])

print(ans)

Solution (Python):
from collections import Counter


n = int(input())
cnt = Counter(list(map(int, input().split())))

ret = 0

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



print(ret)

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

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

x = {}

for i in range(N):

    ai = a[i]

    temp = x.get(ai-1, 0)
    temp += 1
    x[ai-1] = temp

    temp = x.get(ai, 0)
    temp += 1
    x[ai] = temp

    temp = x.get(ai+1, 0)
    temp += 1
    x[ai+1] = temp

X = max(x.values())
print(X)

Solution (Python):
import collections


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

    c = collections.Counter(a_list)

    dic_cnt = dict(c.most_common())

    answer = -1
    for k in dic_cnt.keys():
        cnt = dic_cnt[k]
        if k-1 in dic_cnt.keys():
            cnt += dic_cnt[k-1]
        if k+1 in dic_cnt.keys():
            cnt += dic_cnt[k+1]
        answer = max(answer,cnt)
    print(answer)

Solution (Python):
import collections


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

    tmp_A = []
    for a in A:
        tmp_A.append(a-1)
        tmp_A.append(a)
        tmp_A.append(a+1)

    c = collections.Counter(tmp_A)
    most_common_element = c.most_common()[0][0]

    answer = 0
    for a in A:
        if a == most_common_element or a-1 == most_common_element or a+1 == most_common_element:
            answer += 1
    print(answer)

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

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

Solution (Python):
import collections
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)
ls = collections.Counter(ls)
print(ls.most_common(1)[0][1])

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

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

a.sort()
h = {}
for i in range(a[-1]+1):
    h[i] = 0

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

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

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

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

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

ans = 0
for i in range(10**5 + 1):
    if ans < sum(numCount[i: i + 3]):
        ans = sum(numCount[i: i + 3])

print(ans)

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

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

print(maxc)

Solution (Python):
from collections import defaultdict

n = int(input())
a_list = list(map(int, input().split()))
dic = defaultdict(int)

for a in a_list:
    dic[a-1] += 1
    dic[a] += 1
    dic[a+1] += 1

print(max(dic.values()))

Solution (Python):
n = int(input())
raw = list(map(int,input().split()))
can = []
for i in range(n):
  now = raw[i]
  can.append(now-1)
  can.append(now)
  can.append(now+1)
can.sort()
ans = 0
for j in range(3*n):
  try:
    if can[j-1] == can[j]:
      cnt += 1
    else:
      cnt = 1
  except:
    
    cnt = 1
  if cnt > ans:
    ans = cnt

print(ans)

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

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

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

ans = 0
for i in nums.values():
  ans = max(ans, i)

print(ans)

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

a_hash = {}
for i in range(N):
    if a[i] in a_hash:
        a_hash[a[i]] += 1
    else:
        a_hash[a[i]] = 1

a_sort = sorted(a_hash.items(), key = lambda x: x[0])
a_sort = list(a_sort)
ans_list = [0] * N

if len(a) == 1:
    print(1)
    exit()
if len(a_sort) == 1:
    print(a_sort[0][1])
    exit()

for i in range(len(a_sort)):
    if i == 0:
        if a_sort[0][0] == a_sort[1][0] - 1:
            ans_list[0] += a_sort[0][1] + a_sort[1][1]
    elif i == len(a_sort) -1:
        if a_sort[i][0] == a_sort[i-1][0] + 1:
            ans_list[i] += a_sort[i][1] + a_sort[i-1][1]
        else:
            ans_list[i] = a_sort[i][1]
    else:
        if a_sort[i][0] == a_sort[i-1][0] + 1:
            ans_list[i] += a_sort[i][1] + a_sort[i-1][1]
        if a_sort[i][0] == a_sort[i+1][0] - 1:
            ans_list[i] += a_sort[i+1][1]


print(max(ans_list))

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

ans = 0
for x in d:
    cand = d[x]
    if x - 1 in d:
        cand += d[x - 1]
    if x + 1 in d:
        cand += d[x + 1]
    
    ans = max(ans, cand)

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.append(a[-1] + 1)

b = [a[0]]
c = [1]
ans = 0
for i in range(1, n+1):
    if a[i] == b[-1]:
        c[-1] += 1
    else:
        cand = c[-1]
        if len(b) >= 2 and b[-2] == b[-1] - 1:
            cand += c[-2]
        if len(b) >= 3 and b[-3] == b[-1] - 2:
            cand += c[-3]
        ans = max(ans, cand)
        b.append(a[i])
        c.append(1)

print(ans)

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

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

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

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

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

for i in range(n):
    k = lst[i]
    lst.append(k-1)
    lst.append(k+1)

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

Solution (Python):
import collections

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

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

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

Solution (Python):
import collections

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

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

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
a.sort()
a_dic = {}
for i in range(N):
    n = a[i]
    a_dic.setdefault(n, 0)
    a_dic[n] += 1
maximum = 0
for j in a_dic:
    tmp = a_dic[j] + a_dic.get(j-1,0) + a_dic.get(j+1,0)
    if tmp > maximum:
        maximum = tmp
print(maximum)

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

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

tmp = l[0] + l[1] + l[2]
ans = tmp
for i in range(3, MAX_a):
    tmp = tmp + l[i] - l[i-3]
    ans = max(tmp , ans)

print(ans)