Problem:
 Score : 300 points    Problem Statement You are given an integer sequence of length N , a_1,a_2,...,a_N .  For each 1≤i≤N , you have three choices: add 1 to a_i , subtract 1 from a_i or do nothing.  After these operations, you select an integer X and count the number of i such that a_i=X .  Maximize this count by making optimal choices.      Constraints  1≤N≤10^5  0≤a_i<10^5 (1≤i≤N)  a_i is an integer.         Input The input is given from Standard Input in the following format:  N  a_1  a_2 .. a_N       Output Print the maximum possible number of i such that a_i=X .        Sample Input 1 7
3 1 4 1 5 9 2      Sample Output 1 4  For example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4 , the maximum possible count.       Sample Input 2 10
0 1 2 3 4 5 6 7 8 9      Sample Output 2 3       Sample Input 3 1
99999      Sample Output 3 1

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

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

from collections import defaultdict
dict = defaultdict(int)
for a in A:
    dict[a-1] += 1
    dict[a] += 1
    dict[a+1] += 1

print(max(dict.values()))

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

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

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

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

print(ans)

Solution (Python):
import numpy as np
import sys
import math

n=int(input())
A=np.array(sorted(list(map(int,input().split()))))
C=np.bincount(A)
D=C.copy()
D[1:]+=C[:-1]
D[:-1]+=C[1:]
print(np.max(D))

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

Solution (Python):
from sys import stdin
from collections import Counter


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  
    a_arr = list(map(int,_in[1].split(' ')))  
    
    count = Counter(a_arr)
    cnt = 0
    for key in count.keys():
        _ = count[key]
        try:
            _ += count[key+1]
        except:
            pass
        try:
            _ += count[key-1]
        except:
            pass
        cnt = max(cnt,_)
    
    print(cnt)

Solution (Python):
from sys import stdin
from collections import Counter


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  
    a_arr = list(map(int,_in[1].split(' ')))  
    
    count = Counter(a_arr)
    cnt = 0
    keys = sorted(count.keys())
    for key in keys:
        _ = count[key]
        try:
            _ += count[key+1]
        except:
            pass
        try:
            _ += count[key-1]
        except:
            pass
        cnt = max(cnt,_)
    
    print(cnt)

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

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

ans = 0
for i in cnt:
    ans = max(ans, cnt[i])

print(ans)

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

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

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

from collections import defaultdict
cnts = defaultdict(int)
for a in A:
    if a != 0:
        cnts[a-1] += 1
    cnts[a] += 1
    cnts[a+1] += 1

print(max(cnts.values()))

Solution (Python):






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





a_list = a
a_plus = [item+1 for item in a]
a_minus = [item-1 for item in a]








mylist = a_list + a_plus + a_minus





import collections





counted = collections.Counter(mylist)
ans = max(counted.values())
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
up = 100001
l = [0 for i in range(up)]
for i in range(n):
    l[a[i]] += 1
ma = -1
for i in range(1, up-1):
    if ma < l[i-1] + l[i] + l[i+1]:
        ma = l[i-1] + l[i] + l[i+1]
print(ma)

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

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

m = []

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


d ={}
for i in m:
    if i not in d:
        d[i] =0
    d[i] += 1



b = 0
for i in d.keys():
    if b <= d[i]:
        b = d[i]


print(b)

Solution (Python):
import itertools
import sys
import numpy as np
import collections
n=int(input())
a=np.array(list(map(int,input().split())))
add_a=a+1
al=list(add_a)
minus_a=a-1
ml=list(minus_a)
l=list(a)+al+ml
print(collections.Counter(l).most_common()[0][1])

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

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

Solution (Python):
import collections

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

sum = []
for i in a:
  sum.append(i)
  sum.append(i+1)
  sum.append(i-1)
print(collections.Counter(sum).most_common()[0][1])

Solution (Python):


N = int(input())


A = list(map(int, input().split()))
from collections import Counter

def main():
    nums = []
    for a in A:
        nums.append(a)
        nums.append(a + 1)
        nums.append(a - 1)
    print(Counter(nums).most_common()[0][1])

if __name__ == "__main__":
    main()

Solution (Python):
import sys
from io import StringIO
import unittest
from collections import Counter

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

    counter = Counter(a)

    ans = 0

    for key, value in counter.items():
        if key == 0:
            tmp = counter[key + 1] + value
        else:
            tmp = counter[key + 1] + counter[key] + counter[key - 1]

        if ans < tmp:
            ans = tmp

    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """7
3 1 4 1 5 9 2"""
        output = """4"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """10
0 1 2 3 4 5 6 7 8 9"""
        output = """3"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """1
99999"""
        output = """1"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()

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

ans=0
now=0
for i,l in enumerate(L):
    if now<l:
        now=l
        ans=i

print(now)

Solution (Python):
def main():
    from collections import deque

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

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

    dq = deque()
    b_iter = iter(b)
    dq.append(next(b_iter))
    dq.append(next(b_iter))
    dq.append(next(b_iter))
    t = sum(dq)
    ans = t
    for x in b:
        dq.append(x)
        y = dq.popleft()
        t = t + x - y
        if ans < t:
            ans = t
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
N,*a = map(int, open(0).read().split())
if N == 1:
    print(1)
    exit()
lst = a[:]
for i in a:
    lst += [i+1,i-1]
c = Counter(lst)
print(c.most_common()[0][1])

Solution (Python):
import sys
sys.setrecursionlimit(10**6) 
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque 


from collections import Counter

from itertools import accumulate

from heapq import heapify,heappop,heappush



def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds

def main():
    mod = 10**9+7
    

    N = int(input())
    
    A = tuple(map(int, input().split())) 
    
    
    count=0
    l=[0]*(10**6)
    for a in A:
        l[a]+=1
        l[a+1]+=1
        l[a+2]+=1
    print(max(l))




if __name__ == "__main__":
    main()

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

def solve(N,A):
    ans = 0
    cnts = [0]*10**5
    for a in A:
        cnts[a] += 1
    ans = 0
    for i in range(10**5-2):
        ans = max(ans,sum(cnts[i:i+3]))
    return ans
print(solve(N,A))

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

C = Counter(A)
ans = 0
for e in C:
    ans = max(ans,C[e]+C[e-1]+C[e+1])
print(ans)

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

c = collections.defaultdict(int)
ans = 0
for x in a:
    c[x] += 1
    c[x-1] += 1
    c[x+1] += 1
    ans = max(ans, c[x], c[x-1], c[x+1])

print(ans)

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

Solution (Python):
from collections import Counter

N = int(input())
a = list(map(int, input().split()))
b = Counter(a)
ans = 0
X = 0
for i in b.keys():
    if X < b[i-1] + b[i] + b[i+1]:
        X = b[i-1] + b[i] + b[i+1]
print(X)

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

A=[0]*(max(a)+1)
ans=0

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

if len(A)>3:
    for j in range(1,max(a)):
        ans=max(ans,A[j-1]+A[j]+A[j+1])
else:
    ans=sum(A)

print(ans)

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int, input().split()))
dic=Counter(a)
ans=0
if n==1:
  print('1')
elif n==2:
  if any([a[0]==a[1],a[0]==a[1]-1,a[0]==a[1]+1]):
    print('2')
  else:
    print('1')
else:
  for i in range(n-2):
    ans=max(ans,dic[i]+dic[i+1]+dic[i+2])
  print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  

N = read_a_int()
A = read_ints()


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

for a in A:
    for da in [-1, 0, 1]:
        n_X[a + da + 1] += 1
print(max(n_X))

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

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

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

from collections import Counter

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

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

ans = 0
for x,y in a.items():
  cnt = y
  if x-1 in a: cnt += a[x-1]
  if x+1 in a: cnt += a[x+1]
  if cnt > ans: ans = cnt
print(ans)

Solution (Python):
from bisect import bisect_right
N = int(input())
A = sorted(list(map(int,input().split())))
cmax = 0
for i in range(N):
    a = A[i]
    ind = bisect_right(A,a+2)
    cmax = max(cmax,ind-i)
print(cmax)

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

Solution (Python):
from collections import defaultdict

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

for num in numbers:
    for x in [-1, 0, 1]:
        if num + x >= 0:
            d[num + x] += 1

ans = 0
for k, v in d.items():
    ans = max(ans, v)

print(ans)

Solution (Python):
from collections import defaultdict

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

cnt = defaultdict(int)
for num in a:
    for i in [-1, 0, 1]:
        cnt[num + i] += 1
ans = 0
for i in cnt:
    ans = max(cnt[i], ans)
print(ans)

Solution (Python):
import sys
from collections import Counter
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

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

    D = Counter(A)
    res = 0
    for v in D.values():
        res = max(res, v)

    print(res)

if __name__ == '__main__':
    resolve()

Solution (Python):
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
c = Counter(A)
ans = 0
for i in range(10**5):
    cnt = c[i-1]+c[i]+c[i+1]
    if ans < cnt:
        ans = cnt
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(0, 10 ** 5):
    tmp = C[i - 1] + C[i] + C[i + 1]
    ans = max(ans, tmp)

print (ans)

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

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

b = a + 1
c = a - 1

d = np.concatenate((a, b, c))
e = Counter(d)

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

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
num = [0 for _ in range(10**6)]
for a in A:
    num[a] += 1
    num[a+1] += 1
    num[a-1] += 1
mx = max(num)
tg = num.index(mx)
print(num[tg])

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
d = defaultdict(int)
for i in a:
    d[i-1] += 1
    d[i] += 1
    d[i+1] += 1
res = 0
for key in list(d):
    res = max(res, d[key])
print(res)

Solution (Python):
n, *a = map(int, open(0).read().split())
cnt = [0] * 100000
for x in a: cnt[x] += 1
ans = 0
for i in range(99998):
    ans = max(ans, cnt[i]+cnt[i+1]+cnt[i+2])
print(ans)

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


if __name__ == '__main__':
    main()

Solution (Python):
N,*A=map(int, open(0).read().split())
C=[0]*(10**5+5)
for a in A:
    C[a-1]+=1
    C[a]+=1
    C[a+1]+=1
print(max(C[i] for i in range(10**5+1)))

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

from collections import Counter
ctr = Counter(A)
ans = 0
for i in range(10**5+1):
    t = ctr[i-1] + ctr[i] + ctr[i+1]
    ans = max(ans,t)
print(ans)

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

Solution (Python):
from collections import defaultdict

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

d = defaultdict(int)

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

Solution (Python):
from collections import defaultdict

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

for n in nums:
    for x in [-1, 0, 1]:
        if 0 <= n + x and n + x <= 10 **5:
            frequency[n + x] += 1

ans = 0
for k, v in frequency.items():
    ans = max(ans, v)

print(ans)

Solution (Python):


from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    n = ii()
    a = li()
    acnt = [0 for i in range(100005)]
    for i in a:
        acnt[i]+=1
        acnt[i+1]+=1
        acnt[i+2]+=1
    print(max(acnt))


main()

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

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

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

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

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


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

print(counts[0][1])

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

L = [-10**10] +L +[10**10]
li = []
from bisect import bisect,bisect_right,bisect_left
for i in range(n+2):
    
    li.append((bisect_left(L,L[i]-1),bisect_right(L,L[i]+1)))

max1 = 0
for i in range(1,len(li)-1):
    max1 = max(max1,li[i][1]-li[i][0])
print(max1)

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

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

n = int(input())
a = sorted(list(map(int,input().split())))
x = [0]*100002
for i in range(n):
    x[a[i]]+=1
ans = 0
for i in range(100000):
    c = x[i] + x[i+1] + x[i+2]
    ans = max(ans,c)
print(ans)

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

n = int(input())
a = sorted(list(map(int,input().split())))
c = collections.Counter(a)
item = []
for key,Value in c.items():
    item.append([key,Value])
koho = []
if len(item) == 1:
    print(item[0][1])
    sys.exit()
if item[1][0] - item[0][0] == 1:
    cnt = item[1][1] + item[0][1]
else:
    cnt = item[0][1]
koho.append(cnt)
cnt = 0
for i in range(1,len(item)-1):
    cnt = 0
    if item[i][0] - item[i-1][0] == 1:
        cnt += item[i-1][1] + item[i][1]
    if item[i+1][0] - item[i][0] == 1:
        cnt += item[i+1][1]
    koho.append(cnt)
cnt = 0
if item[-1][0] - item[-2][0] == 1:
    cnt += item[-1][1] + item[-2][1]
else:
    cnt += item[-1][1]
koho.append(cnt)
print(max(koho))

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

Solution (Python):
import sys

readline = sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int, readline().split()))
    count = [0] * (pow(10, 5)+3)
    for a in A:
        count[a] += 1
        count[a+1] += 1
        count[a+2] += 1
    ans = max(count) 
    print(ans)     


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
max_val = max(A)
B = [0]*(max_val+3)
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())
x = [0]*100001
a = list(map(int,input().split()))
m = 0
ma = 0
for i in range(n):
    x[a[i]]+=1
for i in range(100001-2):
    m=x[i]+x[i+1]+x[i+2]
    if m>ma:
        ma=m
print(ma)

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

if __name__ == '__main__':
    main()

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

if __name__ == '__main__':
    main()

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


def read():
    N = int(input().strip())
    A = map(int, input().strip().split())
    return N, A


def solve(N, A):
    b = [0 for i in range(10**5+2)]
    for a in A:
        b[a-2] += 1
        b[a-1] += 1
        b[a] += 1
    return max(b)


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))

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

dic_a=defaultdict(int)
for a in alist:
  dic_a[a]+=1


max_answer=0
for v in list(dic_a):
  answer=dic_a[v-2]+dic_a[v-1]+dic_a[v]
  max_answer=max(answer,max_answer)

  answer=dic_a[v-1]+dic_a[v]+dic_a[v+1]
  max_answer=max(answer,max_answer)

  answer=dic_a[v]+dic_a[v+1]+dic_a[v+2]
  max_answer=max(answer,max_answer)
  
print(max_answer)

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

dic_a=defaultdict(int)
for a in alist:
  dic_a[a]+=1


max_answer=0
for v in dic_a:
  answer=0
  if v-1 in dic_a:
    answer+=dic_a[v-1]
  answer+=dic_a[v]
  if v+1 in dic_a:
    answer+=dic_a[v+1]
  max_answer=max(answer,max_answer)
  
print(max_answer)

Solution (Python):
n = int(input())
x = [0]*100001
a = list(map(int,input().split()))
m = 0
ma = 0
for i in range(n):
    x[a[i]]+=1
for i in range(100001-2):
    m=x[i]+x[i+1]+x[i+2]
    if m>ma:
        ma=m
print(ma)

Solution (Python):
import math

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

a_dict = {}

for a in a_list:
    for aa in [a - 1, a, a + 1]:
        a_dict[aa] = a_dict.get(aa, 0) + 1

print(max(a_dict.values()))

Solution (Python):
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for i in range(N):
        d[A[i]-1] += 1
        d[A[i]] += 1
        d[A[i]+1] += 1
    print(max(d.values()))
if __name__ == '__main__':
    main()

Solution (Python):
import collections
N = int(input())
a = list(map(int, input().split()))
d = collections.defaultdict(int)
for i in a:
    for j in range(-1,2):
        if i+j >= 0:
            d[i+j] += 1

print(max(d.values()))

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

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    amax = max(a)

    from collections import Counter

    counter = Counter(a)

    ans = 0
    for i in range(amax + 1):
        cnt = 0
        cnt = counter[i - 1] + counter[i] + counter[i + 1]
        ans = max(ans, cnt)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
N = int(input())
a = list(map(int, input().split()))
V = np.zeros((max(a)+4))

for v in a:
    V[v:v+3] += 1 
print(int(np.max(V)))

Solution (Python):
from collections import Counter

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

l = []
for i in A:
	l.extend([i-1, i, i+1])

count = Counter(l)
cand = sorted(count.most_common(), key=lambda x: x[1], reverse=True)[:3]
cand = list(filter(lambda x: cand[2][1]<=x[1], count.most_common()))
ans = 0
for tpl in cand:
    n = len(list(filter(lambda x: x == tpl[0] or x+1 == tpl[0] or x-1 == tpl[0], A)))
    ans = max(ans, n)

print(ans)

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

num = [0]*(max(A)+2)

for i in A:
    num[i] += 1
m = max(A)
ans = 0
for i in range(0,max(A)+2):
    if i == 0:
        tmp = num[i] + num[i+1]
    elif i == m+1:
        tmp = num[i-1] + num[i]
    else:
        tmp = num[i-1] + num[i] + num[i+1]
    ans = max(ans,tmp)

print(ans)

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

import collections
c = collections.Counter(A)

l_ans = []
for i in c.keys():
    ans = 0
    if not c.get(i-1) == None:
        ans += c[i-1]
    if not c.get(i) == None:
        ans += c[i]
    if not c.get(i+1) == None:
        ans += c[i+1]
    l_ans.append(ans)
print(max(l_ans))

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

s = [0]*(a[-1]+1)
for i in range(n):
    s[a[i]] += 1
ans = 0
if a[-1] - 1 > 0:
    for i in range(1,a[-1]):
        ans = max(ans, s[i] + s[i-1] + s[i+1])
    print(ans)
else:
    print(max(s))

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
start = min(A)
goal = max(A)

from collections import Counter
c = Counter(A)

ans = 0

for i in range(start,goal+1):
    ans = max(ans,c[i]+c[i+1]+c[i+2])
    
print(ans)

Solution (Python):
import sys
import numpy as np


input=sys.stdin.buffer.readline
N = int(input())
A = np.array(input().split(), dtype = np.int32)

counter = np.bincount(A)
B = counter.copy()
B[1:] += counter[:-1]
B[:-1] += counter[1:]
answer = B.max()
print(answer)

Solution (Python):
N = int(input())
*A, = map(int, input().split())
d = {}

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

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


table = sorted(d.items())

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    if n == 1:
        print(1)
    else:
        L = []
        for i in range(n):
            L.append(list(range(A[i] - 1, A[i] + 2)))

        ma = L[-1][-1]
        mi = L[0][0]
        res = [0] * (ma - mi + 1)
        for l in L:
            for i in l:
                res[i - mi] += 1

        print(max(res))


if __name__ == '__main__':
    resolve()

Solution (Python):
from collections import defaultdict
N = int(input())
A = list(map(int,(input().split())))
c = defaultdict(lambda:0)
for i in range(1,10**5+1):
    c[i]
for i in A:
    c[i] += 1
l = list(c.items())
l.sort()
p = []
for i in range(0,10**5-2):
    p.append(l[i][1]+l[i+1][1]+l[i+2][1])
print(max(p))

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

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
Ap = [a+1 for a in A]
Am = [a-1 for a in A]
label = set(A+Ap+Am)
dict = {l:0 for l in label}
for a in A+Ap+Am:
    dict[a]+=1
print(max(dict.values()))

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

s={}
for i in range(n):
  if a[i] not in s:
    s[a[i]]=1
  else:
    s[a[i]]+=1
ans=0
for i in s:
  x=s.get(i-1, 0)+s[i]+s.get(i+1, 0)
  if x>ans:
    ans=x
print(ans)

Solution (Python):
from collections import defaultdict

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

dic = defaultdict(int)
for elem in a:
    dic[elem] += 1
    dic[elem - 1] += 1
    dic[elem + 1] += 1


print(max(dic.values()))

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

num_list = [0 for _ in range(10 ** 5)]
for i in a:
    if i > 0:
        num_list[i - 1] += 1
    num_list[i] += 1
    if i < 10 ** 5 - 1:
        num_list[i + 1] += 1
print(max(num_list))

Solution (Python):

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


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

    
        
print(max(cnt))

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

Solution (Python):
from collections import defaultdict
n = int(input())
a = list(map(int,input().rstrip().split()))
dic = defaultdict(int)
for x in a:
  dic[x-1]+=1
  dic[x]+=1
  dic[x+1]+=1
m=0
for v in dic.values():
  m = max(m,v)   
print(m)

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)

counter=Counter(B)
count=list(counter.values())
print(max(count))

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

nn=10**5+1
c=[0]*nn
for i in range(n):
    c[a[i]]=c[a[i]]+1
    
cmax=0
for i in range(2,nn):
    cmax=max(cmax,c[i-2]+c[i-1]+c[i])
print(cmax)

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

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

succession=0
pre=-10000
maxnum=0
check=[0,0,0]

for i in a:

    if pre<i-2:
        succession=0
        pre=i
        maxnum=max(maxnum,sum(check))
        check=[1,0,0]
    elif pre==i:
        check[succession]+=1
    elif pre==i-1 and succession==0:
        succession+=1
        check[1]+=1
        pre=i
    elif pre==i-1 and succession==1:
        succession+=1
        check[2]+=1
        pre=i
    elif pre==i-1 and succession==2:
        maxnum=max(maxnum,sum(check))
        check=[check[1],check[2],1]
        pre=i
    elif pre==i-2:
        maxnum=max(maxnum,sum(check))
        check=[check[succession],0,1]
        succession=2
        pre=i

maxnum=max(maxnum,sum(check))

print(maxnum)

Solution (Python):
import collections
import sys
sys.setrecursionlimit(2000000)




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)

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

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