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=input()
a=list(map(int, input().split()))

b=map(lambda x: x+1, a)
c=map(lambda x: x-1, a)
b=list(b)
c=list(c)

for num in range(len(a)):
    a.append(b[num])
    a.append(c[num])

d=collections.Counter(a)
values,counts=zip(*d.most_common())
print(counts[0])

Solution (Python):
import collections

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

aa=[]

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

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

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

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

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

Solution (Python):
from sys import stdin, setrecursionlimit
from collections import defaultdict


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

    ans = 0

    dic = defaultdict(int)
    for ai in a:
        dic[ai - 1] += 1
        dic[ai] += 1
        dic[ai + 1] += 1
        ans = max(ans, dic[ai - 1], dic[ai], dic[ai + 1])

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

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

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

    ctr = [0] * (10 ** 5 + 2)  
    for x in A:
        for j in range(-1, 2):
            ctr[x + j] += 1
    print(max(ctr))


if __name__ == '__main__':
    main()

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

    res_list = [0] * 100001

    for num in A:
        res_list[num] += 1
        
        if num != 0:
            res_list[num-1] += 1
        if num != 10**5:
            res_list[num+1] += 1
    
    print(max(res_list))

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    a = list(map(int, input().split()))
    num_dict = {}
    a.sort()
    a_max = a[N-1]
    temp = a[0]
    sum = 1

    for i in range(1,N):
        if temp == a[i]:
            sum += 1
        else:
            num_dict[temp] = sum
            sum = 1
            temp = a[i]
    num_dict[a[N-1]] = sum

    ans = 0
    judge = 0
    for j in range(1, a_max):
        
        if j == 1 and j in num_dict:
            if j+1 in num_dict:
                judge = num_dict[j] + num_dict[j+1]
                ans = judge
                continue
            else:
                judge = num_dict[j]
                ans = judge
                continue

        if (j in num_dict) and (j-1 in num_dict) and (j+1 in num_dict):
            if judge <= (num_dict[j-1] + num_dict[j] + num_dict[j+1]):
                judge = num_dict[j-1] + num_dict[j] + num_dict[j+1]
                ans = judge
                continue
            else:
                continue

        elif (j in num_dict) and (j-1 in num_dict):
            if judge <= (num_dict[j-1] + num_dict[j]):
                judge = num_dict[j-1] + num_dict[j]
                ans = judge
                continue
            else:
                continue

        elif (j in num_dict) and (j+1 in num_dict):
            if judge <= (num_dict[j+1] + num_dict[j]):
                judge = num_dict[j+1] + num_dict[j]
                ans = judge
                continue
            else:
                continue

        elif (j-1 in num_dict) and (j+1 in num_dict):
            if judge <= (num_dict[j+1] + num_dict[j-1]):
                judge = num_dict[j+1] + num_dict[j-1]
                ans = judge
                continue
            else:
                continue

        elif j in num_dict:
            if judge <= (num_dict[j]):
                judge = num_dict[j]
                ans = judge
                continue
            else:
                continue

        else:
            continue

    if a_max-1 in num_dict:
        if judge <= num_dict[a_max-1] + num_dict[a_max]:
            ans = num_dict[a_max-1] + num_dict[a_max]
    else:
        if judge <= num_dict[a_max]:
            ans = num_dict[a_max]
    return ans

print(main())

Solution (Python):
from collections import Counter

N = int(input())
a = list(map(int,input().split()))
c = Counter(a)
max_num = 0

for x in range(max(a)+1):
      max_num = max(max_num,(c[x] + c[x+1] + c[x+2]))
print(max_num)

Solution (Python):
from collections import Counter

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

c=Counter(a)

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

print(ans)

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

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

for i in a:
    if i == 1:
        point[1] += 1
        point[2] += 1
    else:
        point[i] += 1
        point[i-1] += 1
        point[i+1] += 1

print(max(point))

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

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

ans = [0 for _ in range(100005)]

for aa in a:
    ans[aa] += 1
    ans[aa+1] += 1
    ans[aa+2] += 1





print(max(ans))

Solution (Python):
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
store = defaultdict(lambda:0)
for i in a:
  store[i+1]+=1
  store[i-1]+=1
  store[i]+=1
print(max(store.values()))

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

Solution (Python):
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions


def readints():
    return list(map(int, input().split()))


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


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()

x = [0]*(10**5+10)

for i in range(n):
    x[a[i]-1] += 1
    x[a[i]] += 1
    x[a[i]+1] += 1
max_x = max(x)
print(max_x)

Solution (Python):


N = int(input())
A = list(map(int,input().split()))
cnt = [0]*(10**5+2)
for i in A:
    cnt[i]+=1
    cnt[i+1]+=1
    cnt[i+2]+=1
    
print(max(cnt))

Solution (Python):
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
a = [i+1 for i in a]

imos = [0] * (10**5 + 3)

for i in a:
    imos[i-1] += 1
    imos[i+2] -= 1

i = accumulate(imos)
print(max(i))

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
ans = 0
for c in cnt:
    ans = max(ans, c)

print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
a.sort()
oldi = 0
m = a[0]
M = 0
ans = 0
if N == 1:
  ans = 1
for i in range(1, N):
  M = a[i]
  while M - m > 2:
    oldi += 1
    m = a[oldi]
  if i - oldi + 1 > ans:
    ans = i - oldi + 1
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
MAX = max(A)
dic = {}
for i in range(N):
  if A[i] not in dic:
    dic[A[i]] = 1
  else:
    dic[A[i]] += 1

ans = []
for i in range(MAX+1):
  mae = 0;ima=0;tsugi = 0
  if i in dic:
    ima = dic[i]
  if i-1 in dic:
    mae = dic[i-1]
  if i+1 in dic:
    tsugi = dic[i+1]
  temp = mae + ima + tsugi
  ans.append(temp)
print(max(ans))

Solution (Python):
from bisect import bisect_left, bisect_right

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

ans = 1
for i in range(N):
    X = a[i]
    res = bisect_right(a, X+1) - bisect_left(a, X-1)
    ans = max(res, ans)

print(ans)

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

Solution (Python):
def resolve():
  n = int(input())
  a = list(map(int, input().split()))
  c = [0] * (max(a) + 3)
  for x in a:
    x += 1
    c[x-1] += 1
    c[x] += 1
    c[x+1] += 1
  ans = max(c)

  print(ans)
  return

if __name__ == "__main__":
  resolve()

Solution (Python):
import sys
from collections import Counter

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


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    B = []
    for a in A:
        B.append(a - 1)
        B.append(a)
        B.append(a + 1)
    D = Counter(B)
    res = max([v for v in D.values()])
    print(res)


if __name__ == '__main__':
    resolve()

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

cnt = {}
for i in range(n):
    if a[i] not in cnt:
        cnt[a[i]] = 0
    cnt[a[i]] += 1
    
ans = 0
for i in range(n):
    tmp = cnt[a[i]]
    if a[i] - 1 in cnt:
        tmp += cnt[a[i] - 1]
    if a[i] + 1 in cnt:
        tmp += cnt[a[i] + 1]
    ans = max(ans, tmp)
print(ans)

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

maxX = 0
maxV = 0

for i in range(10**5+1):
    val = count[i-1] + count[i] + count[i+1]
    if val > maxV:
        maxV = val
        maxX = i
print(maxV)

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

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
sa =set(a)
ca = Counter(a)
ans = 0

for x in sa:
    
    tmp = ca[x-1] + ca[x] + ca[x+1]
    if ans < tmp:
        ans = tmp

print(ans)

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

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

Solution (Python):
import copy
import collections
N = int(input())
seq = [int(i) for i in input().split()]
seqP1 = [i + 1 for i in copy.copy(seq)]
seqM1 = [i - 1 for i in copy.copy(seq)]
mixed = seq + seqM1 + seqP1
print(mixed.count(collections.Counter(mixed).most_common()[0][0]))

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):
n = int(input())
*a, = map(int,input().split())
c = [0 for _ in range(10**5+1)]
for A in a:
    c[A] += 1
ans = 0
l = len(c)
for i in range(l):
    z = c[i]

    if 0 <= i - 1 <l:
        z += c[i-1]

    if 0 <= i+1 <l:
        z += c[i+1]

    ans = max(ans, z)
print(ans)

Solution (Python):
N=int(input())
*A,=map(int,input().split())
A.sort()
i_min=A[0]
i_max=A[-1]

import collections
C=collections.Counter(A)
count=[]
i=i_min
while i_min<=i<=i_max:
    count.append(C[i]+C[i-1]+C[i+1])
    i+=1

print(max(count))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
num=[0]*(max(a)+1)
for i in range(n):
    num[a[i]]+=1
ans=0
if max(a)<3:
    ans=sum(num)
else:
    for i in range(1,max(a)):
        num2=num[i-1]+num[i]+num[i+1]
        if ans<num2:
            ans=num2
print(ans)

Solution (Python):
import numpy as np
n = int(input())
a = list(map(int,input().split()))
base = np.zeros(100002)

for i in range(n):
  base[a[i]] += 1
  base[a[i]+1] += 1
  base[a[i]+2] += 1
  
print(int(max(base)))

Solution (Python):
from collections import Counter

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

counter = Counter(A)

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

print(max(counter.values()))

Solution (Python):




import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter











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



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

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

  ans = [0]*(10**6)
  for x in a:
    ans[x-1] += 1
    ans[x] += 1
    ans[x+1] += 1
  print(max(ans))
if __name__ == '__main__':
  main()

Solution (Python):
from collections import defaultdict
N=int(input())
A=list(map(int,input().split()))
B=defaultdict(int)
for a in A:
    B[a-1]+=1
    B[a]+=1
    B[a+1]+=1
print(max(B.items(),key=lambda B:B[1])[1])

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

count = [0] * (10**5 + 2)
for num in a:
  count[num] += 1
  count[num + 1] += 1
  count[num + 2] += 1

ans = max(count)
print(ans)

Solution (Python):

import math


def inp():
    return(int(input()))



def inlist():
    return(list(map(int, input().split())))



def instr():
    s = input()
    return(list(s[:len(s)]))



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


n = inp()

a = inlist()
count = [0] * (100001)

for i in a:

    count[i] += 1
    if i > 0:
        count[i-1] += 1
    count[i+1] += 1

m = 0
ind = 0
print(max(count))

Solution (Python):
N=int(input())
an=sorted(list(map(int,input().split())))
dic={}

for ai in an:
  if ai not in dic:dic[ai]=1
  else:dic[ai]+=1
  pass

max_v=0
for x in range(an[0],an[-1]+1):
  v=0
  if x-1 in dic: v+=dic[x-1]
  if x   in dic: v+=dic[x]
  if x+1 in dic: v+=dic[x+1]
  max_v=max(max_v,v)
print(max_v)

Solution (Python):
N = input()
a = map(int, input().split())
count = {}
for v in a:
    for i in [v-1, v, v+1]:
        if i in count.keys():
            count[i] += 1
        else:
            count[i] = 1

print(max(count.values()))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a_min=min(a)
a_max=max(a)

s=list(range(a_min,a_max+1))
t=[0]*(a_max+1)

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

x=sum(t[:2]) 
for j in range(1,len(t)-1):
  x=max(x,t[j-1]+t[j]+t[j+1])

print(x)

Solution (Python):
from collections import Counter

c = Counter()  
N = int(input())
for x in input().split():
    c[int(x)] += 1

A_uniq = sorted(c.keys())

def gen_candiate(seq):
    s = set()
    for n in seq:
        s.add(n-1)
        s.add(n)
        s.add(n+1)
    return sorted(s)

result = 0
for n in gen_candiate(A_uniq):
    tmp = c.get(n-1, 0) + c.get(n, 0) + c.get(n+1, 0)
    if tmp > result:
        result = tmp

print(result)

Solution (Python):
from collections import Counter as C

n  =  int(input())
a= list(input().split())
al = list([int(i) for i in a])
aset = set([int(i) for i in a])

cnt=0
ca = C(al)

for i in aset:
  
  
  if cnt < ca[i-1] + ca[i] + ca[i+1]:
    cnt = ca[i-1] + ca[i] + ca[i+1]

print(cnt)

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



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

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

print(max(b))

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

dic = collections.Counter(A)
for a in A:
    if (a-1 in dic) & (a+1 in dic): 
        dic[a-1] += 1
        dic[a+1] += 1

    elif (a+1 in dic):
        dic[a+1] += 1
        dic[a-1] = 1
    elif (a-1 in dic):
        dic[a-1] += 1
        dic[a+1] = 1
    else:
        dic[a+1] = 1
        dic[a-1] = 1

print(max(dic.values()))

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

Solution (Python):
from collections import Counter

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



ans = 0
for key in c.keys():
    v = c[key]
    v += c.get(key - 1, 0)
    v += c.get(key + 1, 0)
    ans = max(ans, v)
print(ans)

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

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

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

ans=0

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

print(ans)

Solution (Python):
from collections import Counter

N = int(input())
a = list(map(int, input().split()))
c = dict(Counter(a))
cx = {i: 0 for i in range(10 ** 5 + 1) if i not in c.keys()}
c.update(cx)
c = sorted(c.items(), key=lambda x: x[0])
ans = 0
for i in range(10 ** 5 - 1):
  ans = max(sum((c[i][1], c[i+1][1], c[i+2][1])), ans)
  
print(ans)

Solution (Python):
import collections

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

for i in li:
    ans.append(i-1)
    ans.append(i)
    ans.append(i+1)

c = collections.Counter(ans)

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

Solution (Python):
from collections import Counter

c = Counter()  

N = int(input())
for x in input().split():
    c[int(x)] += 1

A_uniq = sorted(c.keys())

def gen_candiate(seq):
    s = set()
    for n in seq:
        s.add(n-1)
        s.add(n)
        s.add(n+1)
    return sorted(s)



result = 0
for n in gen_candiate(A_uniq):
    tmp = c.get(n-1, 0) + c.get(n, 0) + c.get(n+1, 0)
    if tmp > result:
        result = tmp

print(result)

Solution (Python):
from collections import Counter

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

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

a_counter = Counter(a_all)
print(a_counter.most_common()[0][1])

Solution (Python):
n = int(input())
A = [int(i) for i in input().split()]
cnt_x = [0] * (10**5 + 2)
for a in A:
    cnt_x[a - 1] += 1
    cnt_x[a] += 1
    cnt_x[a + 1] += 1
print(max(cnt_x))

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

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

Solution (Python):
from itertools import accumulate


N = int(input())
acc = [0] * (10 ** 5 + 3)
for a in map(int, input().split()):
    acc[max(0, a - 1)] += 1
    acc[a + 2] -= 1
acc = list(accumulate(acc))
print(max(acc))

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

Solution (Python):
from collections import defaultdict

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

d = defaultdict(int)

m = -1

for a in A:
    d[a] += 1
    d[a+1] += 1
    d[a-1] += 1
    m = max(d[a], d[a+1], d[a-1], m)

print(m)

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

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

Solution (Python):
from collections import Counter as CC
N = int(input())
a = list(map(int, input().split()))
b = CC(a)
X1, X2, X3 = 0, b[min(b)], b[min(b)+1]
count = X1 + X2 + X3
ans = count
for i in range(min(b) + 2, max(b) + 1):
  count -= X1
  X1, X2, X3 = X2, X3, b[i]
  count += X3
  ans = max(ans, count)
else:
  print(ans)

Solution (Python):
import collections
N=int(input())
A=sorted(list(map(int,input().split())))
p=collections.Counter(A)
B=list(set(A))
ans=0
l=len(B)
if l==1:
  ans = p[B[0]]
elif l==2:
  if B[1]-B[0] <= 2:
    ans = p[B[0]]+p[B[1]]
  else:
    ans = max(p[B[0]],p[B[1]])
else:  
  for i in range(l-2):
    sum_a = p[B[i]]+p[B[i+1]]+p[B[i+2]]
    if sum_a > ans:
      ans = sum_a
print(ans)

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

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

c = [0 for _ in range(10**5+3)]

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=[0]*100002
for i in a:
    ans[i]+=1
    ans[i+1]+=1
    ans[i+2]+=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)
c=collections.Counter(a)
print(c.most_common()[0][1])

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7



N = INT()
a = LIST()

lim = 10**5+3
cnt = [0]*lim

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

ans = 0
for i in range(2, lim):
	ans = max(ans, cnt[i-2]+cnt[i-1]+cnt[i])
print(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)
c = collections.Counter(a)
print(c.most_common()[0][1])

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

N = INT()
a = np.array(LIST())
a = np.bincount(a)
b = a.copy()
b[1:] += a[:-1]
b[:-1] += a[1:]
print(b.max())

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

N = INT()
a = np.array(LIST())

a = np.bincount(a)

b = a.copy()

b[1:] += a[:-1]

b[:-1] += a[1:]

print(b.max())

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()
ans =[]

for x in a:
	ans.append(x-1)
	ans.append(x)
	ans.append(x+1)




print(max(Counter(ans).values()))

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

maxa = max(al)
import collections
c =collections.Counter(al)
res = 0
for i in range(maxa+1):
    res = max(res,c[i-1]+c[i]+c[i+1])

print(res)

Solution (Python):
from collections import defaultdict

_ = input()
counts = defaultdict(int)
for a in map(int, input().split()):
    counts[a] += 1
    counts[a - 1] += 1
    counts[a + 1] += 1
print(max(counts.values()))

Solution (Python):
from collections import defaultdict

N = input()
counts = defaultdict(int)
values = set()
for a in map(int, input().split()):
    counts[a] += 1
    values.add(a)
ans = 0
for x in values:
    ans = max(ans, counts[x - 1] + counts[x] + counts[x + 1])
print(ans)

Solution (Python):
from collections import Counter

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

CA = Counter(A)
ans = 0
for key, val in CA.items():
    temp = 0
    kouho = [key - 1, key, key + 1]
    for num in kouho:
        if num in CA:
            temp += CA[num]
    ans = max(ans, temp)
print(ans)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
      
    b = [0] * (10**6)
    for aa in a:
        b[aa - 1] += 1 
        b[aa + 0] += 1 
        b[aa + 1] += 1 
        
    print(max(b))
        
    
if __name__ == '__main__':
    main()

Solution (Python):


import sys







from bisect import bisect_left, bisect_right 






















def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    L.sort()

    ans = -1
    for x in range(10**5):
        ans = max(ans, bisect_right(L, x+1) - bisect_left(L, x -1))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
alis=list(map(int,input().split()))
xlis=dict()
for i in set(alis):
    xlis[i-1]=0
    xlis[i+1]=0
    xlis[i]=0
for i in alis:
    xlis[i-1]+=1
    xlis[i+1]+=1
    xlis[i]+=1
print(max(xlis.values()))

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

Solution (Python):
import collections
N = int(input())
a = list(map(int, input().split()))
Max = 0
count = collections.Counter(a)
for i in range(N):
    c = 0
    X = a[i]
    c += count[X-1]
    c += count[X]
    c += count[X+1]
    if c > Max:
        Max = c
print(Max)

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

d = {}
for each in a:
  d[each] = d.get(each, 0) + 1
  d[each-1] = d.get(each-1, 0) + 1
  d[each+1] = d.get(each+1, 0) + 1
  
print(max(d.values()))

Solution (Python):
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    c = Counter(A)
    uniq = list(k for k in c.keys())
    uniq.sort()
    ans = 0
    for u in uniq:
        ans = max([ans, c[u - 1] + c[u] + c[u + 1]])
    print(ans)


if __name__ == '__main__':
    main()

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

result_list = []
for a in A:
    result_list.append(a-1)
    result_list.append(a)
    result_list.append(a+1)
C = Counter(result_list).most_common()
print(C[0][1])

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

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

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

cnt = [0] * (10**6)


for _a in a:
    cnt[_a-1] += 1
    cnt[_a] += 1
    cnt[_a+1] += 1


print(max(cnt))

Solution (Python):
from collections import defaultdict

n = int(input())

d = defaultdict(int)

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

print(max(d.values()))

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