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())
la = [int(w) for w in input().split()]

cnt = collections.Counter(la)

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

print(ans)

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

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

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

print(max(ans_l))

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

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

print(max(B))

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

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

for a in A:
  ans+=[B[a-1]+B[a]+B[a+1]]

print(max(ans))

Solution (Python):
import collections

n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
ans=0
for k,v in c.items():
    ans=max(ans,(v + c.get(k-1,0) + c.get(k+1,0)))
print(ans)

Solution (Python):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    n, *a = map(int, read().split())
    ac = Counter(a)
    acs = sorted(ac.items())
    r = ac.most_common()[0][1]
    if len(acs) == 2:
        if acs[1][0] - acs[0][0] == 1:
            r = acs[0][1] + acs[1][1]

    for i1 in range(1, len(acs) - 1):
        if abs(acs[i1 - 1][0] - acs[i1+1][0]) <= 2:
            r = max(r, acs[i1-1][1] + acs[i1][1] + acs[i1+1][1])
        elif abs(acs[i1 - 1][0] - acs[i1][0]) <= 1:
            r = max(r, acs[i1-1][1] + acs[i1][1])
        elif abs(acs[i1 + 1][0] - acs[i1][0]) <= 1:
            r = max(r, acs[i1+1][1] + acs[i1][1])
    print(r)
if __name__ == '__main__':
    main()

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

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

Solution (Python):
import collections

N = int(input())
a = [int(i) for i in input().split()]
g = a[:]
for i in g:
    a.append(i-1)
    a.append(i+1)



dict = collections.Counter(a)

for a, b in dict.most_common():
    print(b)
    break

Solution (Python):

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

Solution (Python):
import collections

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

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

l = collections.Counter(a)
l = list(l.values())
print(max(l))

Solution (Python):
from collections import Counter
N, = list(map(int,input().split()))
a  = list(map(int,input().split()))
c  = Counter()
for ai in a:
    for b in range(ai-1,ai+2):
        c[b] += 1
print(max(c.values()))

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

c_dic = {}
for i in a:
    if i not in c_dic:
        c_dic[i] = 1
    else:
        c_dic[i] += 1
    
    if i + 1 not in c_dic:
        c_dic[i + 1] = 1
    else:
        c_dic[i + 1] += 1

    if i - 1 not in c_dic:
        c_dic[i - 1] = 1
    else:
        c_dic[i - 1] += 1

print(max(c_dic.values()))

Solution (Python):
from collections import Counter as C

_ = input()
a = C([int(x) for x in input().split()])

ans = 0
for k in a:
    ans = max(ans, a[k-1] + a[k] + a[k+1])
else:
    print(ans)

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

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

Solution (Python):
MAX_A = 100_001
N = int(input())
A = list(map(int, input().split()))
_A = [0] * MAX_A
for a in A:
    _A[a] += 1
    if a - 1 >= 0:
        _A[a - 1] += 1
    if a + 1 < MAX_A:
        _A[a + 1] += 1
print(max(_A))

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

X={i:0 for i in range(-1,max(A)+2)}
for a in A:
    X[a]+=1
    X[a-1]+=1
    X[a+1]+=1

print(max(X.values()))

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

print(max(c.values()))

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

A_={}
for _ in range(-1,10**5+10):
    A_[_]=0

for a in A:
    a_b = a-1
    a_a = a+1
    A_[a] +=1
    A_[a_b] +=1
    A_[a_a] +=1    

ans = 0
ans_idx = 0
for k in A_.keys():
    a = A_[k]
    if ans < a:
        ans = a
        ans_idx = k
        

print(ans)

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

if n == 1:
    print(1)
    exit()

if len(set(a)) == 1:
    print(n)
    exit()

n_dict = {}
min_n = 10**9
max_n = 0
for i in range(n):
    t = a[i]
    if t in n_dict:
        n_dict[t] += 1
    else:
        n_dict[t] = 1
    
    max_n = max(t, max_n)
    min_n = min(t, min_n)

ans = 0
for x in range(min_n+1, max_n+1):
    tmp = 0
    if x-1 in n_dict: tmp += n_dict[x-1]
    if x in n_dict: tmp += n_dict[x]
    if x+1 in n_dict: tmp += n_dict[x+1]
    
    ans = max(ans, tmp)
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
from collections import Counter
d = Counter(a)
ans = 0
for key,val in d.items():
    ans = max(ans,d[key]+d[key-1]+d[key+1])
print(ans)

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

result_list = []
for a in l:
    result_list.extend([a-1,a,a+1])
    
result_list

import collections

count = collections.Counter(result_list) 
hindo_jun = count.most_common() 

print(hindo_jun[0][1])

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

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

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

ans = 0
for i in range(1+10**5):
    if i==0:
        if ans < c[i]+c[i+1]:
            ans = c[i]+c[i+1]
    elif i==10**5:
        if ans < c[-2]+c[-1]:
            ans = c[-2]+c[-1]
    elif ans < c[i-1] + c[i] + c[i+1]:
        ans = c[i-1] + c[i] + c[i+1]

print(ans)

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


if __name__ == "__main__":
    main()

Solution (Python):

n = int(input())
a = list(map(int, input().split()))
arr = [0] * 100002

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

print(max(arr))

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

i = 0
ans = 1
while True:
    cnt1 = 0
    cnt2 = 0
    while a[i + cnt1] == a[i]:
        cnt1 += 1
        cnt2 += 1
        if i + cnt1 == n:
            ans = max(ans, cnt1)
            break
    if i + cnt1 == n:
        break
    while a[i + cnt2] <= a[i] + 2:
        cnt2 += 1
        if i + cnt2 == n:
            break
    ans = max(ans, cnt2)
    i += cnt1

print(ans)

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

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

cnt = [0] * 10**5
for v in a:
    cnt[v] += 1

res = 0
for i in range(10**5-2):
    res = max(res, cnt[i] + cnt[i+1] + cnt[i+2])

print(res)

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

N = int(input())
a = list(map(int,input().split()))
ac = collections.Counter(a)
dc = sorted(ac.items(),key = lambda x:(-x[1],x[0]))

ans = 0
for i in range(len(dc)):
    key = dc[i][0]
    val = dc[i][1]
    if ans > 3*val:
        print(ans)
        exit()
    ans = max(ans,ac[key-1]+ac[key]+ac[key+1])
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
C = [0]*(10**5)
for ai in A:
    C[ai] += 1

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

Solution (Python):
from collections import defaultdict
n = int(input())
a_list = [int(x) for x in input().split()]
d = defaultdict(int)
for a in a_list:
    for i in range(-1, 2):
        d[a + i] += 1
print(sorted(d.values())[-1])

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

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

c = Counter(b)


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

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

count = [0]*(max(a)+1)
for i in a: count[i]+=1

if len(count) <= 2:
  print(sum(count))
  exit()
  
ans = 0
for i in range(2,max(a)):
  if count[i-1]+count[i]+count[i+1] > ans:
    ans = count[i-1]+count[i]+count[i+1]
print(ans)

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

a_count = collections.Counter(a)

total = 0
for i in a_count.keys():
    total = max(total,a_count[i-1] + a_count[i] + a_count[i+1])
print(total)

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

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

res = max(x)
print(res)

Solution (Python):
from collections import Counter

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

Solution (Python):







N = int(input())

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

countA = {}
for v in a:
	for i in (-1,0,1):
		
		if(v - i in countA):
			countA[v - i] = countA[v - i] + 1
		else:
			countA[v - i] = 1
print(max(countA.values()))

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

lis = sorted(lis)

count = [0]*100001

for i in range(n):
    count[lis[i]] += 1

ans = 0

for j in range(1,100000):
    t = count[j-1]+ count[j]+ count[j+1]
    ans = max(ans, t)
    
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

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

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    a = list(mi())
    l = [0]*(10**5)
    m = -1
    for i in range(N):
        l[a[i]] += 1
    for i in range(10**5-2):
        t = l[i]+l[i+1]+l[i+2]
        m = max(m, t)
    print(m)


if __name__ == '__main__':
    main()

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

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

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

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

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

count=[0]*100001
for i in lst:
    if i==0:
        count[1]+=1
    else:
        count[i-1]+=1
        count[i]+=1
        count[i+1]+=1
        
print(max(count))

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

Solution (Python):


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

if n == 1:
    print(1)
    exit(0)
if n == 2:
    if abs(a[0]-a[1]) <= 2:
        print(2)
    else:
        print(1)
    exit(0)

if n >= 3:
    d = [0 for _ in range(100001)]
    for i in range(n):
        d[a[i]] += 1
    ans = 0 
    for i in range(100001-2):
        tmp = d[i] + d[i+1] + d[i+2]
        if ans <= tmp:
            ans = tmp 

print(ans)

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

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

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

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

ans = num[0] + num[1] + num[2]

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

print(ans)

Solution (Python):
from collections import Counter

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

ans = 0
amin = min(a)
amax = max(a)
for x in range(amin, amax+1):
   ans = max(ans, c[x-1]+c[x]+c[x+1])

print(ans)

Solution (Python):
from collections import defaultdict


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

    d = defaultdict(int)
    for aa in a:
        for i in range(-1, 2):
            d[aa+i] += 1

    ans = 0
    for k in d:
        if d[k] > ans:
            ans = d[k]

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np

N=int(input())
A=np.array(list(map(int, input().split())))
L=np.zeros(10**5+1)
for i in range(N):
  L[A[i]]+=1

a_max=max(A)
ans=0

for i in range(10**5-1):
  ans=max(ans,L[i]+L[i+1]+L[i+2])
  if i==a_max:
    break
print(int(ans))

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

nums = [0]*(max(a)+1)
for i in a: nums[i] += 1

if len(nums) <= 2:
  print(sum(nums))
  exit()
  
ans = 0
for i in range(1,max(a)):
  if ans < nums[i-1] + nums[i] + nums[i+1]:
    ans = nums[i-1] + nums[i] + nums[i+1]

print(ans)

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

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
C = [0] * 100002
for x in A:
    for i in range(3):
        C[x + i] += 1
print(max(C))

Solution (Python):
from collections import Counter

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

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

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

Solution (Python):
n,*l=map(int,open(0).read().split())
c=[0]*(10**5+3)
for i in l:
  for j in (-1,0,1): c[i+j]+=1
print(max(c))

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

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

print(max(l))

Solution (Python):

import math

import collections

n = int(input())

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

b = [[_a - 1, _a, _a + 1] for _a in a]

numbers = {}
for i in range(n):
    c = collections.Counter(b[i])

    for k, v in c.items():
        if k in numbers.keys():
            numbers[k] += 1
        else:
            numbers.update({k: 1})

ans = sorted(numbers.items(), key=lambda x: x[1], reverse=True)

print(ans[0][1])

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

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

for v in a:
    l[v]+=1
    l[v+1]+=1
    l[v+2]+=1

print(max(l))

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

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

d=dict()

ans=0
count=0

from collections import defaultdict
d = defaultdict(lambda: 0, d)

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

p=0
while(p<100010):
    count=d[p-1]+d[p]+d[p+1]
    p=p+1
    if(count>ans):
        ans=count
print(ans)

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

mx=0
for i in range(1,am):
  
  m=sum(num[i-1:i+2])
  if m>mx:
    mx=m
if len(num)<=3:
  mx=sum(num)
print(mx)

Solution (Python):









import os
import sys
from collections import Counter




def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    cnt_list = Counter(a)

    a_max = a[-1]
    a_min = a[0]
    cnt_max = 0
    for center in range(a_min-1, a_max+2):
        cnt = 0
        if center in cnt_list.keys():
            cnt += cnt_list[center]
        if center-1 in cnt_list.keys():
            cnt += cnt_list[center-1]
        if center+1 in cnt_list.keys():
            cnt += cnt_list[center+1]
        if cnt > cnt_max:
            cnt_max = cnt
    print(cnt_max)



if __name__ == "__main__":
    main()

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

r=0
l=0
ans=0
while r<n:
    if a[r]-a[l]<=2:
        if r-l+1>ans:
            ans=r-l+1
        r+=1
    else:
        l+=1
print(ans)

Solution (Python):
from collections import defaultdict
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a_max = max(a)
A = defaultdict(int)
for i in range(n):
    A[a[i]] += 1
ans = 0
if A[0] == n:
    print(n)
    exit()
for i in range(a_max):
    ans = max(ans,A[i]+A[i+1]+A[i+2])
print(ans)

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

l = [0] * 100002
for i in a:
    l[i+1] += 1
    l[i+2] += 1
    l[i] += 1
print(max(l))

Solution (Python):
from collections import Counter
n, *a = map(int, open(0).read().split())
l = Counter(a)
for ai in a:
    l[ai+1] += 1
    l[ai-1] += 1
print(l.most_common()[0][1])

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
if n == 1:
    print(1)
elif n == 2:
    if abs(a[0] - a[1]) <= 2:
        print(2)
    else:
        print(1)
else:
    d = {}
    for i in range(max(a) + 3):
        d[i] = 0
    for i in a:
        d[i] += 1
    ans = 1
    pre = 0
    for i in range(max(a) + 1):
        pre = d[i] + d[i + 1] + d[i + 2]
        if ans < pre:
            ans = pre
    print(ans)

Solution (Python):
n = int(input())
A = tuple(map(int, input().split()))
from collections import Counter
CA = Counter(A)

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

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

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

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

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

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, *a = map(int, read().split())
cnt = [0] * (10 ** 5 + 10)

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

print(max(cnt))

Solution (Python):
def resolve():
    from collections import defaultdict
    N = int(input())
    A = [int(i) for i in input().split()]
    d = defaultdict(int)
    for a in A:
        d[a] += 1
    maxA = 0
    d = dict(d)
    for key in d.keys():
        sumA = d.get(key)
        if key - 1 in d:
            sumA += d.get(key - 1)
        if key + 1 in d:
            sumA += d.get(key + 1)
        maxA = max(maxA, sumA)
    print(maxA)

resolve()

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

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


counter=Counter(a_n)

print(a_n.count(counter.most_common()[0][0]))

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

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

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

count=[0 for _ in range(max(A)+1)]
for i in range(n):
  count[A[i]]+=1
  
answer=0
if n>3:
  for i in range(0,n-2):
    tmp=sum(count[i:i+3])
    if tmp>answer:
      answer=tmp
elif n==2:
  if len(count)>3:
    answer=1
  else:
    answer=2
elif n==1:
  answer=1

print(answer)

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

def main(n,a):
    hist=[0]*(10**5+1)
    for i in range(n):
        hist[a[i]]+=1
    
    max3=0
    for i in range(10**5-1):
        max3=max(max3,hist[i]+hist[i+1]+hist[i+2])
    return max3

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(ans)

Solution (Python):
from math import*
from bisect import*
import copy

n=int(input())
arr=list(map(int,input().split()))
arr.sort()
brr=copy.deepcopy(arr)
brr=list(set(brr))
brr.sort()


ans=0

for i in range(len(brr)):
	d=bisect_left(arr,brr[i])
	c=bisect_right(arr,brr[i]+2)

	if ans<c-d:
		ans=c-d
print(ans)

Solution (Python):



class Counter(dict):
    def __missing__(self, i):
        return 0

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

counter = Counter()

for item in a:
    counter[item] += 1
    counter[item+1] += 1
    counter[item-1] += 1

maxima = max(counter.values())

print(maxima)

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

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

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

print(ans)

Solution (Python):
from collections import Counter

def main():
    n = int(input())
    a = Counter(map(int, input().split()))
    akeys = a.keys()
    mx = max(akeys)
    cnt = 0
    for i in akeys:
        c = a[i]
        if i+1 in akeys:
            c += a[i+1]
        if i+2 in akeys:
            c += a[i+2]
        cnt = max(cnt, c)
    print(cnt)
    
if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = 100002*[0]

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

print(max(A))

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

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

print(max(A))

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

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

print(max(B))

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

import collections
c = collections.Counter(a)
_max = 0
for i in range(max(a)+1):
  _sum = c[i-1] + c[i] + c[i+1]
  if _max < _sum:
    _max = _sum
print(_max)

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

import collections
c = collections.Counter(a)
ans = 0

if len(c) == 1:
  ans = list(c.values())[0]
else:
  for x in range(min(a),max(a)):
    ans_candidate = c[x] + c[x+1] + c[x+2]

    if ans < ans_candidate:
      ans = ans_candidate
print(ans)

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

cnt = Counter()
for a in A:
    cnt[a-1] += 1
    cnt[a]   += 1
    cnt[a+1] += 1

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

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

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

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

for i in a:
    al[i] += 1
    al[i+1] += 1
    al[i+2] += 1

print(max(al))

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

num = [0]*(10**5+1)
for i in a:
    if i-1 >= 0:
        num[i-1] += 1
    num[i] += 1
    if i+1 <= N:
        num[i+1] += 1

print(max(num))

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

l=[0]*(10**5+5)
for i in a:
    l[i]+=1
p=0
for j in range(10**5):
    p=max(p,l[j]+l[j+1]+l[j+2])
print(p)

Solution (Python):
n=int(input())
b=[0 for i in range(100002)]
a=list(map(int,input().split()))
a.sort()
for i in range(n):
    b[a[i]]+=1
ans=0
for i in range(1,100001):
    tmp=b[i-1]+b[i]+b[i+1]
    if tmp>ans:
        ans=tmp
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 sys
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def main():
	a = int(input())
	
	
	al=lin()
	bl=[v+1 for v in al]
	cl=[v-1 for v in al]
	zl = al+bl+cl
	cc = collections.Counter(zl)
	ret = max(cc.values())
	print(ret)
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
r = [0 for _ in range(100001)]
for i in range(n):
    r[a[i]] += 1
ans = 0
for i in range(len(r)-2):
    ans = max(ans,sum(r[i:i+3]))
print(ans)

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

MinatoYukina = [0]*100003

for i in range (0, N):
	MinatoYukina[L[i]]+=1
	MinatoYukina[L[i]+1]+=1
	MinatoYukina[L[i]+2]+=1

print(max(MinatoYukina))

Solution (Python):
import collections

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

l = [None] * n * 3
for i in range(n):
    l[i] = a[i]
    l[n+i] = a[i]-1
    l[2*n+i] = a[i]+1
    
c = collections.Counter(l)
    
print(c.most_common()[0][1])

Solution (Python):
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
x = np.hstack([a - 1, a, a + 1])
x[x < 0] = 0
r = np.bincount(x)
print(r[1:].max())

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


class segtree:
    x_unit=0 
    def __init__(self,N):
        self.n=(1<<len(bin(N-1)[2:]))
        self.x=[self.x_unit]*(2*self.n)

    def build(self, seq):
        for i,j in enumerate(seq, start=self.n):  
            self.x[i] = j
        for i in range(self.n-1, 0, -1):
            self.x[i] = 0
            
            
            

    def fold(self,l,r): 
        l+=self.n
        r+=self.n-1
        while l<r:
            if l%2==1: 
                self.x[l]+=1
                l+=1 
            if r%2==0: 
                self.x[r]+=1
                r-=1 
            l //= 2
            r //= 2
        if l==r:
            self.x[l]+=1
        
    def get(self,i): 
        i+=self.n
        ret=self.x[i]
        while i>1:
            i //= 2
            ret+=self.x[i]
        return ret

seq=[0]*(10**5+2)
q=[(max(0, a[i]-1), min(10**5,a[i]+1)) for i in range(n)]
seg=segtree(10**5+2)
seg.build(seq)
for i in range(n):
    l,r=q[i]
    seg.fold(l,r+1)
ans=[]
for i in range(10**5+2):
    ans.append(seg.get(i))
print(max(ans))

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

seq=[0]*(10**5+3)
for i in range(n):
    l=max(a[i]-1,0)
    r=a[i]+2
    seq[l]+=1
    seq[r]-=1
from itertools import accumulate
seq=list(accumulate(seq))
print(max(seq))

Solution (Python):
from collections import Counter

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

min_v=min(a)
max_v=max(a)

c=Counter(a)

ans=0
for i in range(min_v,max_v+1):
  t_ans=c[i-1]+c[i]+c[i+1]
  ans=max(ans,t_ans)

print(ans)

Solution (Python):
import collections

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

CNT_A = collections.Counter(A_s).most_common()

ans_list = []

if (len(CNT_A) >= 3):
    CNT_A.sort()

    for i in range(len(CNT_A) - 2):
        val = CNT_A[i][0]
        next_val = CNT_A[i + 1][0]
        nnnn_val = CNT_A[i + 2][0]
        
        
        if (abs(val - next_val) <= 2):
            cnt = CNT_A[i][1] + CNT_A[i + 1][1]
            if (abs(val - nnnn_val) <= 2):
                cnt += CNT_A[i + 2][1]
                
        else:
            cnt = CNT_A[i][1]
        
        ans_list.append(cnt)
    
    ans = max(ans_list)

elif (len(CNT_A) == 2):
    val = CNT_A[0][0]
    n_val = CNT_A[1][0]
    
    if (abs(val - n_val) <= 2):
        ans = CNT_A[0][1] + CNT_A[1][1]
    else:
        ans = CNT_A[0][1]
    
else:
    ans=CNT_A[0][1]

print(ans)

Solution (Python):
from collections import Counter


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

nc = Counter(A)
C = []
for i in range(max(A) + 1):
    c = nc[i - 1] + nc[i] + nc[i + 1]
    C.append(c)

print(max(C))

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

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

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

print(max(counter))