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 collections

n = int(input())
array = [int(x) for x in input().split()]

res = []
for item in array:
    res.append(item-1)
    res.append(item)
    res.append(item+1)

res_dict = sorted(dict(collections.Counter(res)).items(), key=lambda x:x[1])
print(res_dict[-1][1])

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

for a in A:
    c[a] += 1
    c[a+3] -= 1

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

print(max(c))

Solution (Python):
MAX = 100000
def m():
    N = int(input())
    a = list(map(int, input().split()))
    t = [0] * (MAX + 1)

    for i in range(N): t[a[i]] += 1
    ans = 0
    tmp = 0
    for n in range(1, MAX):
        ans = max(t[n - 1] + t[n] + t[n + 1], ans)
    return ans

print(m())

Solution (Python):
N = int(raw_input())
a = map(int, raw_input().split())
lst = []
max = 0
for i in range(0, 100002):
	lst.append(0)

for i in range(0, N):
	lst[a[i]] = lst[a[i]] + 1

for i in range(1, 100001):
	if lst[i-1] + lst[i] + lst[i+1] > max:
		max = lst[i-1] + lst[i] + lst[i+1]

print max

Solution (Python):
from collections import Counter

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

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

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

Solution (Python):
from collections import defaultdict

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

d=defaultdict(int)

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

ans=sorted(d.items(),key = lambda x:-x[1])

v,c=ans[0]
print(c)

Solution (Python):
N = int(input())
A = list(map(int, input().split(' ')))
ans = {}
for i in A:
    for j in [i-1,i,i+1]:
        if j in ans:
            ans[j] += 1
        else:
            ans[j] = 1
print(max(ans.values()))

Solution (Python):





if __name__ == '__main__':
    from bisect import bisect_left
    from bisect import bisect_right

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

    for i in range(max(a) + 1):
        left = bisect_left(a, i - 1)
        right = bisect_right(a, i + 1)
        count = max(count, max(0, right - left))

    print(count)

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
plus=[0]*n
minus=[0]*n
for i in range(n):
    plus[i]=a[i]+1
    minus[i]=a[i]-1
plus=plus+minus+a
data=Counter(plus)
ans=[]
for i in data.values():
    ans.append(i)
print(max(ans))

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

C = Counter(B).most_common(1)
print(C[0][1])

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

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

mx = max(src)
ans = 0
for i in range(mx+1):
    ans = max(ans, ctr[i] + ctr[i+1] + ctr[i+2])
print(ans)

Solution (Python):
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
m = max(1, min(a))
M = max(a)
ans=[]
for x in range(m,M):
    ans.append(c[x-1]+c[x]+c[x+1])
if m >= M:
    ans.append(n)
print(max(ans))

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

times = {}
for i in a:
    for j in range(i-1, i+2):
        times[j] = times.get(j, 0) + 1

m = 0
for k in times:
    if times[k] > m:
        m = times[k]

print(m)

Solution (Python):
from collections import Counter
N = int(input())
a_list = [int(elem) for elem in input().split(' ')]

a_count = Counter(a_list)

max_num_x = 0
for key, value in a_count.items():
    num_x = a_count[key-1] + a_count[key] + a_count[key+1]
    if num_x > max_num_x:
        max_num_x = num_x

print(max_num_x)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
aa = []
amax = max(a) + 100


for i in range(amax + 1):
    aa.append(0)

for i in range(len(a)):
    aa[a[i]] = aa[a[i]] + 1
    
kouho = 1    
for j in range(len(aa) - 2):
    if kouho < aa[j] + aa[j + 1] + aa[j + 2]:
        kouho = aa[j] + aa[j + 1] + aa[j + 2]

print(kouho)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = [0 for k in range(100002)]

for k in A:
    B[k] += 1

ans = 0
for k in range(1,100001):
    ans = max(ans,B[k-1]+B[k]+B[k+1])

print(ans)

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

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

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

Solution (Python):


from collections import Counter

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

aaa = list()

for i in a:
    aaa.append(i - 1)
    aaa.append(i)
    aaa.append(i + 1)

c = Counter(aaa)
mode = c.most_common(1)

print(mode[0][1])

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
for x in range(n):
    a.append(a[x]-1)
    a.append(a[x]+1)
counter = Counter(a)
for name, cnt in counter.most_common():
    print(cnt)
    break

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
counta = [0 for _ in range(100000)]
ans = 0

for elem in a:
    counta[elem] += 1

for x in range(1, 100000 - 1):
    ans = max(ans, counta[x-1] + counta[x] + counta[x+1])

print(ans)

Solution (Python):
import collections
N = int(input())
a = list(map(int, input().split()))
a_minus1 = [i-1 for i in a]
a_plus1 = [i+1 for i in a]
a_join = a + a_minus1 + a_plus1
c = collections.Counter(a_join)
print(max(list(c.values())))

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
ans = 0
count = {}
for i in range(0, 10**5+1):
  count[i] = 0

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

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

  if temp > ans:
    ans = temp

print(ans)

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
a = na()

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

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

Solution (Python):
from collections import Counter

def max_count(nums):
    nums_decr = map(lambda x: x - 1, nums)
    nums_incr = map(lambda x: x + 1, nums)
    counter = Counter(nums)
    counter.update(nums_decr)
    counter.update(nums_incr)
    return counter.most_common(1)[0][1]


if __name__ == '__main__':
    _ = input()
    nums = list(map(int, input().split()))
    print(max_count(nums))

Solution (Python):
def c_together(N, A):
    from collections import defaultdict
    count = defaultdict(int)
    for i in A:
        count[i] += 1
    ans = 0
    for i in range(max(A) + 1):
        
        tmp = count[i - 1] + count[i] + count[i + 1]
        ans = max(ans, tmp)
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(c_together(N, A))

Solution (Python):
from collections import OrderedDict

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

number_hash = OrderedDict()

for i in sorted(nums):
    if i not in number_hash:
        number_hash[i] = 1
    else:
        number_hash[i] += 1

ans = 0
for i in number_hash:
    cnt = 0
    
    
    i_d = i - 1
    i_u = i + 1
    if i_d in number_hash:
        cnt += number_hash[i_d]
    if i_u in number_hash:
        cnt += number_hash[i_u]
    cnt += number_hash[i]

    if ans < cnt:
        ans = cnt

print(ans)

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
d = {-1:0,max(a)+1:0}
num_X = 0
for i in range(max(a)+1):
    d[i] = 0
for i in a:
    d[i] += 1
for i in range(max(a)+1):
    num_X = max(num_X,d[i-1]+d[i]+d[i+1])
print(num_X)

Solution (Python):
import collections
n = int(input())
a = [int(i) for i in input().split()]
x,answer = collections.Counter(a),0
for i in range(min(a),max(a)+1):
	num = 0
	for j in range(i-1,i+2):
		try:
			num += x[j]
		except:
			pass
	if num>answer:
		answer = num
print(answer)

Solution (Python):
N = int(input())
num = list(1+ int(x) for x in input().split())
L = max(num)
sumR = [0 for x in range(L+3)]
for i in range(N):
  sumR[num[i]-1] +=1
  sumR[num[i]+2] -=1
for j in range(len(sumR)-1):
  sumR[j+1] += sumR[j]
print(max(sumR))

Solution (Python):
from collections import Counter

N=int(input())

counter=Counter(list(map(int,input().split())))
res=0

for i in counter:
    cnt=counter[i-1]+counter[i]+counter[i+1]
    if res<cnt:res=cnt
print(res)

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

num = 0
for i in range(1, 100000):
    num = max(num, sum(p[i - 1: i + 2]))

print(num)

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

maximum = max(A)
count = [0]*(maximum + 2)

for i in range(N):
    if A[i] == 0:
        count[0] += 1
        count[1] += 1
        
    elif A[i] == maximum:
        count[A[i]] += 1
        count[A[i] - 1] += 1
    
    else:
        count[A[i] + 1] += 1
        count[A[i]] += 1
        count[A[i] - 1] += 1

print(max(count))

Solution (Python):
import numpy as np
N = int(input())
a = list(input().split())
a = [int(i) for i in a]
res = np.zeros(max(a)+2)
for i in range(len(a)):
    res[a[i]-1:a[i]+2] += 1
print(int(max(res)))

Solution (Python):
from collections import *
n=int(input())
a=list(map(int,input().split()))
b=set(a)
d=defaultdict(int)
mx=0
for i in a:
  d[i]+=1
for i in b:
  mx=max(mx,d[i-1]+d[i]+d[i+1])
print(mx)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
count=0
a_plus=[]
a_minu=[]
for i in range(n):
    a_plus.append(a[i]+1)
    a_minu.append(a[i]-1)
import collections
a.extend(a_plus)
a.extend(a_minu)
data=collections.Counter(a)
data=sorted(data.items(),key=lambda x:x[1],reverse=True)
print(data[0][1])

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

Solution (Python):
from collections import Counter
n = int(input())
a = sorted([int(i) for i in input().split()])
c = Counter(a)
d =[]
for k,v in c.items():
    d.append([k,v])

    

def count(a):
    na = len(a)
    count = 0
    cmax = 0
    if n == 1:
        return 1
    else:
        for i in range(na):
            j = i
            while j <= na-1  and a[j][0]-a[i][0] <= 2:
                count += a[j][1]
                j += 1
            if count > cmax:
                cmax = count
            count = 0
        return cmax

print(count(d))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
dict = {}
for i in range(N):
    if(a[i] - 1 in dict):
        dict[a[i] - 1] += 1
    else:
        dict[a[i] - 1] = 1
    if(a[i] in dict):
        dict[a[i]] += 1
    else:
        dict[a[i]] = 1
    if(a[i] + 1 in dict):
        dict[a[i] + 1] += 1
    else:
        dict[a[i] + 1] = 1
maxNum = 0
l = list(dict.values())
for i in range(len(l)):
    maxNum = max(maxNum, l[i])
print(maxNum)

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

dic = {}
for num in l:
    dic.setdefault(num, 0)
    dic[num] += 1
max_num = 0
for k, v in dic.items():
    prev = dic[k - 1] if k - 1 in dic else 0
    next = dic[k + 1] if k + 1 in dic else 0

    if (prev + v + next) > max_num:
        max_num = prev + v + next
print(max_num)

Solution (Python):
import numpy as np
n = int(input())
j = np.array([0 for i in range(int(10e5 + 1))])
m = list(map(int, input().split()))
for i in m:
    j[max(0, i-1):  i+2] += 1
print(np.max(j))

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

dp = [0]*(int(1e5) + 1)
for e in a:
    dp[e] += 1

ans = 0
for i in range(1, int(1e5)):
    ans = max(ans, dp[i-1] + dp[i] + dp[i+1])
print(ans)

Solution (Python):
n=input()
n=int(n)
nums=input()
co=[0]*100010
nums=list(map(int,nums.split(" ")))
for i in nums:
  co[i]+=1
  co[i-1]+=1
  co[i+1]+=1
print(max(co))

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

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

for a in alist:
	sum_list[a] += 1
	sum_list[a + 1] += 1
	sum_list[a + 2] += 1

print(max(sum_list))

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

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

    if a[i]+1 in dic:
        dic[a[i]+1]+=1
    else:
        dic[a[i]+1]=1

    if a[i]-1 in dic:
        dic[a[i]-1]+=1
    else:
        dic[a[i]-1]=1

print(max(dic.values()))

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

cnt = Counter()
for x in map(int, input().split()):
    cnt[x] += 1
    cnt[x-1]+=1
    cnt[x+1]+=1

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

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

C = [0 for _ in range(100000+2)]
for a in A:
    C[a] += 1
    C[a+1] += 1
    C[a+2] += 1
C.sort()
print(C[-1])

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

Solution (Python):
num = int(input())
val = [int(x) for x in input().split()]

numbers = [int(x) for x in range(-1, 100001)]
numbers_dict = dict()

for number in numbers:
    numbers_dict[number] = numbers_dict.get(number, 0) + 1

for i in val:
    numbers_dict[i - 1] += 1
    numbers_dict[i] += 1
    numbers_dict[i + 1] += 1

print(max(numbers_dict.values())-1)

Solution (Python):

from collections import Counter


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


c = Counter(xs)


res = 0
for i in range(100000):
    res = max(res, c[i] + c[i - 1] + c[i + 1])

print(res)

Solution (Python):
N = int(input())
A = list(map(int,input().split(" ")))
B = {}

for center in A:
	for num in [center-1,center,center+1]:
		if num in B:
			B[num] += 1
		else:
			B[num] = 1

print(max(B.values()))

Solution (Python):

from collections import Counter

N = input()
line = input().split(" ")

cnt = Counter()
for i in line:
    x = int(i)
    cnt[x] += 1
    cnt[x-1] += 1
    cnt[x+1] += 1
print(cnt.most_common(1)[0][1])

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

arr = list(map(int, input().split()))
a = [0 for i in range(0,max(arr)+2)]
for ar in arr:
  if ar is not 0:
    a[ar-1] += 1
  a[ar] += 1
  
  a[ar+1] += 1 
ans = max(a)

print(ans)

Solution (Python):
n = int(input())
inlis = list(map(int,input().split()))
donelis =[]
numlis=[]

for i in inlis:
    donelis.append(i+1)
    donelis.append(i)
    donelis.append(i-1)

estc =0
donelis.sort()
a = -2
count=0
for i in donelis:
    if a != i:
        if count > estc:
            estc = count
        count = 1
        a = i
    else:
        count +=1
if count >estc:
    estc =count
print(estc)

Solution (Python):
n = int(input())
inlis = list(map(int,input().split()))
donelis =[]
numlis=[]

for i in inlis:
    donelis.append(i+1)
    donelis.append(i)
    donelis.append(i-1)

estc =0
donelis.sort()
a = -2
count=0
for i in donelis:
    if a != i:
        if count > estc:
            estc = count
        count = 1
        a = i
    else:
        count +=1
if count >estc:
    estc =count
print(estc)

Solution (Python):
from collections import Counter


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

c = Counter(a)
a=list(set(a))
a.sort()
x=0
for i in a:
  a_1=0
  a_2=0
  if i-2 in c:
    a_2=c[i-2]
  if i-1 in c:
    a_1=c[i-1]
  x0 = a_2 + a_1 + c[i]
  x=max(x,x0)
print(x)

Solution (Python):
N = int(input())
xs = list(map(int, input().split()))
counts = [0]*100005

for x in xs:
  if x > 0: counts[x-1] += 1
  counts[x] += 1
  counts[x+1] += 1

print(max(*counts))

Solution (Python):
from collections import defaultdict

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

cnt = defaultdict(int)
for ai in a:
	cnt[ai - 1] += 1
	cnt[ai] += 1
	cnt[ai + 1] += 1

res = max(cnt.values())

print(res)

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

def solve(cand):
	global a
	res = 0
	for ai in a:
		if ai - 1 == cand or ai == cand or ai + 1 == cand:
			res += 1
	return res

cnt = {}
for ai in a:
	for i in range(-1,2):
		b = ai + i
		if b >= 0:
			if b not in cnt:
				cnt[b] = 1
			else:
				cnt[b] += 1

candX = max(cnt.items(), key=lambda x:x[1])[0]
res = solve(candX);

print(res)

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

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

Solution (Python):


from collections import Counter

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

countDict = Counter(aList)

maxC = 0

for i in range(0, 100001):
    
    maxCandidate = countDict[i]+countDict[i+1]+countDict[i+2]
    
    if maxCandidate > maxC:
        maxC = maxCandidate
        
print(maxC)

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

Solution (Python):


N = int(input())
alist = list(map(int, input().split(" ")))

distribution = {}

def set(key):
    global distribution
    if not key in distribution:
        distribution[key] = 1
    else:
        distribution[key] += 1

for a in alist:
    set(a - 1)
    set(a)
    set(a + 1)

ret = -1
for value in distribution.values():
    if ret < value:
        ret = value
print(ret)

Solution (Python):
n = int(input())
a_n = list(map(int, input().split()))
a_n.sort()
a_n.reverse()
def check(idx):
    global a_n
    base = a_n[idx]
    count = 0
    dif = 0
    while dif <= 2:
        idx += 1
        count += 1
        if(idx == n):
            return count
        dif = base - a_n[idx]
    return count

ans = 1
i = 0
c = check(i)
tmp = a_n[0]
while(i != n):
    if(tmp != a_n[i]):
        tmp = a_n[i]
        c = check(i)
    if(ans < c):
        ans = c
    i += 1
print(ans)

Solution (Python):

from collections import Counter

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

if(n==1):
    print('1')
else:
    ans = 0
    cnt = Counter(a)
    for i in range(1,max(a)+2):
        tmpsum = cnt[i-1]+cnt[i]+cnt[i+1]
        ans = max(tmpsum,ans)
    print(ans)

Solution (Python):
from collections import Counter

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

C = Counter(A)

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

print(ans)

Solution (Python):
from collections import Counter

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

C = Counter(A)

ans = 0
for i in range(100000):
    ans = max(C[i] + C[i-1] + C[i+1], ans)

print(ans)

Solution (Python):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
a=i2()
d=[0 for i in range(10**5)]
for i in range(n):
 d[a[i]]+=1
 if a[i]<n-1:d[a[i]+1]+=1
 if a[i]>0:d[a[i]-1]+=1
print(max(d))

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

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

print(max(map(sum,zip(c , c [1:], c [2:]))))

Solution (Python):

N = int(input())
a = list(map(int, input().split()))
 
set_a = set(a)
cnt = [0] * (max(a)+1)
ans = 0
 
for i in a:
    cnt[i] += 1
 
if len(cnt) == 1:
    print(cnt[0])
elif len(cnt) == 2:
    print(sum(cnt))
else:
    for i in range(1, max(a)):
        ans = max(ans, cnt[i-1]+cnt[i]+cnt[i+1])

    print(ans)

Solution (Python):
dic={}
for i in range(100002):
    dic[i]=0
input()
for n in map(int,input().split()):
    dic[n]+=1
m=0
for i in range(0,100000):
    m=max(m,dic[i]+dic[i+1]+dic[i+2])
print(m)

Solution (Python):
def C_Together():

    try:
        LOCAL_FLAG
        N = 3
        a = [6, 2, 6]
        
        
        N = 6
        a = [12, 22, 16, 22, 13, 12]

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

    counter = {}
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    for i in range(N):
        counter[a[i]] = counter.get(a[i], 0) + 1

    

    results = 0
    key = -1

    for k, v in counter.items():
        temp = v + counter.get(k-1, 0) + counter.get(k+1, 0)
        if(temp > results):
            results = temp
            key = k

    print(results)
    


C_Together()

Solution (Python):
def C_Together():

    try:
        LOCAL_FLAG
        N = 3
        a = [6, 2, 6]
        
        
        N = 6
        a = [12, 22, 16, 22, 13, 12]

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

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

    results = 0
    key = -1

    for k, v in counter.items():
        temp = v
        if k-1 in counter:
            temp += counter[k-1]
        if k+1 in counter:
            temp += counter[k+1]
        if(temp > results):
            results = temp
            key = k

    print(results)
    

C_Together()

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

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

print(max(ans))

Solution (Python):
cnt = [0]*100002

n = int(input())

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



for x in a:

	cnt[x] += 1

	if x > 0 : cnt[x-1] += 1

	cnt[x+1] += 1

	

answer = 0

for n in cnt:

	answer = max(answer, n)



print(answer)

Solution (Python):
n = int(input())
l = []
for i in range(100002):
  l.append(0)

def sum(i):
  l[i] += 1
  l[i+1] += 1
  if i != 0:
    l[i-1] += 1

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

for i in list(m):
  sum(i)

ans = 0

for i in range(100002):
  if ans < l[i]:
    ans = l[i]

print(ans)

Solution (Python):
input()
d = {}
for i in map(int, input().split()):
    for j in (-1, 0, 1):
        a = i + j
        if a in d:
            d[a] += 1
        else:
            d[a] = 1
print(sorted(d.values())[-1])

Solution (Python):
from collections import defaultdict as dd
N = input()
a_raw = list(map(int, input().split()))
num_count = dd(int)
for item in a_raw:
    num_count[item] += 1
    num_count[item-1] += 1
    num_count[item+1] += 1
print(max(num_count.values()))

Solution (Python):
N = int(input())
cnt_a = [0] * 200000
A = [int(n) for n in input().split()]

for a in A:
  if a != 0:
    cnt_a[a-1] += 1
  cnt_a[a] += 1
  cnt_a[a+1] += 1

print(max(cnt_a))

Solution (Python):
import numpy as np
from collections import Counter

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

    ans = 0
    counter = Counter(A)
    for a, cnt in counter.most_common():
        tmp = counter[a-1] + cnt + counter[a+1]
        if ans < tmp:
            ans = tmp


    print(ans) 


main()

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


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


if __name__ == '__main__':
    main()

Solution (Python):

n = int(input().rstrip())
array = sorted(list(map(int, input().split(' '))))
count = [0] * 100002

for a in array:
    count[a - 1] += 1
    count[a    ] += 1
    count[a + 1] += 1

print(max(count))

Solution (Python):

n = int(input().rstrip())
array = sorted(list(map(int, input().split(' '))))
count = [0] * 100002

for a in array:
    count[a - 1] += 1
    count[a    ] += 1
    count[a + 1] += 1

print(max(count))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
xCnt = dict()
ans = 0
for v in a:
    for i in range(-1,2):
        if v+i not in xCnt:
            xCnt[v+i] = 0
        xCnt[v+i] += 1
        ans = max(ans, xCnt[v+i])

print(ans)

Solution (Python):
import math
n = input()
ai = list(int(i) for i in input().split())
li = [0] * (max(ai)+10)
for i in range(len(ai)):
    p = ai[i]
    p = p+1
    li[p-1] = li[p - 1] + 1
    li[p] = li[p] + 1
    li[p + 1] = li[p + 1] + 1
print(max(li))

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

Solution (Python):
from collections import Counter


def main():
    """
    1<=N<=10^5: a_1 ... a_n
    0<=a<=10^5
    +1, -1, +0
    連続する3つの数値に対して、
    minに+1,中央に何もせず,maxに+1各操作をすると
    中央の個数が最大になる
    3つ揃わない場合もあるので、注意

    10^5で初期化 + 各数値の個数
    10^5とおりの数値についてa, a+1, a+2を想定して
        存在するものの個数をsum
    """
    N = int(input())
    counter = Counter(map(int, input().split()))
    n_max = 0

    def sort_func(t):
        return t[0]
    for a, n in sorted(counter.items(),
                       key=sort_func):

        temp_max = sum([
            counter.get(a - 1, 0),
            counter[a],
            counter.get(a + 1, 0)
        ])
        n_max = max(n_max, temp_max)
    print(n_max)

if __name__ == '__main__':
    main()

Solution (Python):
input()
nums = [int(i) for i in input().split()]
col = {
	i : 0 for i in range(min(nums)-1, max(nums)+2)
}

for i in nums:
	col[i-1] += 1
	col[i] += 1
	col[i+1] +=1

print(max(col.values()))

Solution (Python):
import sys

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



dict={}


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



max_sum=0
for key,value in dict.items():
	
	sum=dict[key]
	if key-1 in dict:
		sum+=dict[key-1]
	if key+1 in dict:
		sum+=dict[key+1]

	if max_sum<sum:
		max_sum=sum

print max_sum

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
 
res = [0] * 100000
 
for i in a:
	res [i] += 1
	
print(max(map(sum,zip(res , res [1:], res [2:]))))

Solution (Python):
from collections import defaultdict
N=int(input())
a=list(map(int,input().split()))
d=defaultdict(int)
for item in a:
    d[item-1]+=1
    d[item]+=1
    d[item+1]+=1
b=sorted(d.items(),key=lambda x:x[1],reverse=True)
print(b[0][1])

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

Solution (Python):
import numpy as np;c=[0]*10**5;input()
for i in map(int,input().split()):
    c[i]+=1
print(max([sum(c[i:i+3]) for i in range(10**5)]))

Solution (Python):
n  = int(input())
ls = list(map(int, input().split()))
ls_plus1  = list(map(lambda x: x + 1, ls))
ls_minus1 = list(map(lambda x: x - 1, ls))
dic = {}
for a in ls_minus1 + ls + ls_plus1:
    dic[a] = dic.get(a, 0) + 1
print(max(dic.values()))

Solution (Python):
n  = int(input())
ls = list(map(int, input().split()))
ls_plus1  = list(map(lambda x: x + 1, ls))
ls_minus1 = list(map(lambda x: x - 1, ls))
dic = {}
for a in ls_minus1 + ls + ls_plus1:
    dic[a] = dic.get(a, 0) + 1
print(sorted(dic.values())[-1])

Solution (Python):
n  = int(input())
ls = list(map(int, input().split()))
ls_plus1  = list(map(lambda x: x + 1, ls))
ls_minus1 = list(map(lambda x: x - 1, ls))
dic = {}
for a in (ls_minus1 + ls + ls_plus1):
    if a in dic: 
        dic[a] += 1
    else: 
        dic[a] = 1
print(sorted(dic.values())[-1])

Solution (Python):
n  = int(input())
ls = list(map(int, input().split()))
ls_plus1  = list(map(lambda x: x + 1, ls))
ls_minus1 = list(map(lambda x: x - 1, ls))
dic = {}
for a, b, c in zip(ls_minus1, ls, ls_plus1):
    if a in dic: 
        dic[a] += 1
    else: 
        dic[a] = 1
    if b in dic:
        dic[b] += 1
    else:
        dic[b] = 1
    if c in dic:
        dic[c] += 1
    else:
        dic[c] = 1
print(sorted(dic.values())[-1])

Solution (Python):


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

counter = {}
for a in ai:
    counter.setdefault(a-1, 0)
    counter.setdefault(a,   0)
    counter.setdefault(a+1, 0)
    
    counter[a-1] = counter[a-1] + 1
    counter[a  ] = counter[a  ] + 1
    counter[a+1] = counter[a+1] + 1

ans = 0
for key in counter.keys():
    ans = max(ans, counter[key])

print(ans)

Solution (Python):
from collections import defaultdict
def read(): return list(map(int, input().split()))


n = int(input())
a = read()

cnt = defaultdict(int)
for i in a:
    cnt[i - 1] += 1
    cnt[i] += 1
    cnt[i + 1] += 1

print(max(cnt.values()))

Solution (Python):

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

set_a=set(a)
cnt=[0]*(max(a)+1)
ans=0

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

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

elif len(cnt)==2:
    ans= cnt[0]+cnt[1]
    print(ans)

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

Solution (Python):
import sys

test =False
if test:
    N = 1
    items = [9999]
else:
    N = int(raw_input())
    items = raw_input().split()
    items = [int(item) for item in items]
max_count = 0
min_val = min(items)
max_val = max(items)
counts = {}
for i in items:
    counts[i - 1] = counts.get(i - 1, 0) + 1
    counts[i] = counts.get(i, 0) + 1
    counts[i + 1] = counts.get(i + 1, 0) + 1
print max(counts.values())

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

Solution (Python):

N  = int(input())
a = list(map(int, input().split()))
b = [ 0 for _ in range((10**5)+1) ]
ans = float('-inf')
for tmp in a:
    if tmp != 0:
        b[tmp-1] += 1
    b[tmp] += 1
    b[tmp+1] += 1
for tmp in b:
    ans = max(ans, tmp)
print(ans)

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