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



Sample input:
7
3 1 4 1 5 9 2


Sample output:
4

Submission status: Runtime Error

Solution code:
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(1,MAX+1):
  mae = 0;ima=0;tsugi = 0
  if i in dic:
    ima = dic[i]
  if i != 1:
    if i-1 in dic:
      mae = dic[i-1]
  if i+1 <= MAX:
    if i+1 in dic:
      tsugi = dic[i+1]
  temp = mae + ima + tsugi
  ans.append(temp)
print(max(ans))

Submission status: Runtime Error

Solution code:
import copy
from statistics import mode
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(mode(mixed)))

Submission status: Runtime Error

Solution code:
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
for i in range(1,len(a)-1):
    num2=num[i-1]+num[i]+num[i+1]
    if ans<num2:
        ans=num2
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

## Library

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

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

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

## Logic

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

Submission status: Runtime Error

Solution code:
def main():
  x, t = map(int, input().split())
  if t > x:
    print(0)
  else:
    print(x-t)

if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
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=0
for j in range(1,n-1):
  x=max(x,t[j-1]+t[j]+t[j+1])

print(x)

Submission status: Runtime Error

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

#for i in a:
#i=0
b=[0]*(10**5)
r=0
#while i<=n:
for i in a:
    b[i]+=1
    b[i+1]+=1
    b[i+2]+=1
t=max(b)
print(t)

Submission status: Runtime Error

Solution code:
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

for i in aset:
  #print(i)
  #print(al.count(i-1),al.count(i),al.count(i+1))
  if cnt < al.count(i-1) + al.count(i) + al.count(i+1):
    cnt = al.count(i-1) + al.count(i) + al.count(i+1)
  if cnt >= len(al) / 2
  break
print(cnt)

Submission status: Runtime Error

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

#for i in a:
#i=0
b=[0]*(max(a)+2)
r=0
#while i<=n:
for i in a:
    b[i]+=1
    b[i+1]+=1
    b[i+2]+=1
print(max(b)-1)


    A=a.count(a[i]+1)
    M=a.count(a[i])
    C=a.count(a[i]-1)

    b[i]=A+M+C
i=0
def dfs(i,j):

    
    max(dfs(i+1,j),dfs(i,j+1))

print(max(b))

Submission status: Runtime Error

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

#for i in a:
#i=0
b=[0]*(max(a)+2)
r=0
#while i<=n:
for i in a:
    b[i]+=1
    b[i+1]+=1
    b[i+2]+=1
print(max(b-1))

Submission status: Runtime Error

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

#for i in a:
#i=0
b=[0]*n
r=0
#while i<=n:
for i in a:
    r=a[i]
    A=a.count(i+1)
    M=a.count(i)
    C=a.count(i-1)

    b=A+M+C

print(max(b))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
alis=list(map(int,input().split()))
xlis=set(alis)
for al in alis:
    alis.add(al-1)
    alis.add(al+1)
counter=[0 for _ in range(n)]
for x in xlis:
    for i in range(n):
        if x-1<=alis[i]<=x+1:
            counter[i]+=1
print(max(counter))

Submission status: Runtime Error

Solution code:
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))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
dict = {}
ans = 0

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

l = sorted(dict.items())
l += [(-1,0),(-2,0)]

for j in range(len(l)-2):
  if l[i][0]+1 == l[i+1][0] and l[i][0]+2 == l[i+2][0]:
     ans = max(ans,l[j][1]+l[j+1][1]+l[j+2][1])
  elif l[i][0]+1 == l[i+1][0] and l[i][0]+2 != l[i+2][0]:
     ans = max(ans,l[j][1]+l[j+1][1])
  elif l[i][0]+1 != l[i+1][0] and l[i][0]+2 != l[i+2][0]:
     ans = max(ans,l[j][1])
   
  
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(map(int, input().split()))
S.sort()
if S[1] - S[0] >1:
  min_s = S[1]
else:
  min_s = S[0]
  
if S[N -1] - S[N -2] >1:
  max_s = S[N -2]
else:
  min_s = S[N -1]

ans = 0

for i in range(min_s -1 ,max_s +1):
  count = 0
  ans_list = list(map(lambda x: x-i, S))
  count = ans_list.count(0) + ans_list.count(1) + ans_list.count(-1)
  if ans < count:
    ans = count
print(ans)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())

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

a = sorted(a)
b = list(set(a))
c=collections.Counter(a)

ans = 1
for i in range(1,n-1):
    cnt = 0
    if abs(b[i]-b[i-1]) <= 1 and abs(b[i]-b[i+1]) <= 1:
        cnt += c[b[i]] + c[b[i-1]] + c[b[i+1]]
        
    ans = max(ans,cnt)

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
m = list(map(int,input().split()))

zen = m
cou = 0

for x in range(n):
    zen.append(m[x]-1)

for x in range(n):
    zen.append(m[x]+1)

a = collections.Counter(zen)

for k in range(n):
    if a[0][1] == m[k] or a[0][1] == m[k] -1 or a[0][1] == m[k] +1:
        cou += 1

print(cou)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
ls = list(map(int,input().split()))
a = min(ls)
b = max(ls)
c = len(ls)
s = 0
def sub(p,q):
    return p-q
ans = []
aaa = [0]*(len(ls))
for i in range(a,b+1):
    new = [i]*(c)
    ans = map(sub,ls,new)
    ans = list(map(str,ans))
    s = ans.count("-1") + ans.count("1") + ans.count("0")
    aaa[i] = s
print(max(aaa))

Submission status: Runtime Error

Solution code:
n = int(input())
ls = list(map(int,input().split()))
a = min(ls)
b = max(ls)
c = len(ls)
s = 0
def sub(p,q):
    return p-q
ans = []
aaa = [0]*(b-a+1)
for i in range(a,b+1):
    new = [i]*(c)
    ans = map(sub,ls,new)
    ans = list(map(str,ans))
    s = ans.count("-1") + ans.count("1") + ans.count("0")
    aaa[i-1] = s
print(aaa)
print(max(aaa))

Submission status: Runtime Error

Solution code:
n = int(input())
ls = list(map(int,input().split()))
a = min(ls)
b = max(ls)
c = len(ls)
s = 0
def sub(p,q):
    return p-q
ans = []
aaa = [0]*(b-a+2)
for i in range(a,b+1):
    new = [i]*(c)
    ans = map(sub,ls,new)
    ans = list(map(str,ans))
    s = ans.count("-1") + ans.count("1") + ans.count("0")
    aaa[i] = s
print(max(aaa))

Submission status: Runtime Error

Solution code:
N = int(input())
la = list(map(int, input().split()))

lcnt = [0] * (max(la) + 1)

for i in range(N):
    lcnt[la[i]-2] += 1
    lcnt[la[i]-1] += 1
    lcnt[la[i]] += 1

print(max(lcnt))

Submission status: Runtime Error

Solution code:
N = int(input())
a = np.array(list(map(int, input().split())))

ans = 0

for i in range(N):
    tmp = a.copy()
    tmp = np.abs(tmp - tmp[i])
    ans = max(ans, np.where(tmp<=1)[0].shape[0])

print(ans)

Submission status: Runtime Error

Solution code:
# ABC072
# C
# Together
import itertools

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

a.sort()
gr = itertools.groupby(a)
hoge_list = [0]*10001
ans = 0

for key, group in gr:
    hoge_list[key] = len(list(group))

for i in range(1,10000,1):
    _tmp = hoge_list[i-1] + hoge_list[i] + hoge_list[i+1]
    if ans < _tmp:
        ans = _tmp

print(ans)

Submission status: Runtime Error

Solution code:
# ABC072
# C
# Together
import itertools

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

a.sort()
gr = itertools.groupby(a)
hoge_list = [0]*10001
ans = 0

for key, group in gr:
    hoge_list[key] = len(list(group))

for i in range(1000):
    _tmp = hoge_list[i-1] + hoge_list[i] + hoge_list[i+1]
    if ans < _tmp:
        ans = _tmp

print(ans)

Submission status: Runtime Error

Solution code:
import sys
N = int(input())
a = sorted(list(map(int, input().split())))

X = 0
c = 1
i = 0
while True:
    if i == N - 1:
        X = max(X, c)
        break
    a_0 = a[i]
    a_1 = a[i] - 1
    a_2 = a[i] + 1
    while True:
        b_0 = a[i + 1]
        b_1 = a[i + 1] - 1
        b_2 = a[i + 1] + 1
        b = [b_0, b_1, b_2]
        if a_0 in b or a_1 in b or a_2 in b:
            c += 1
            i += 1
        else:
            X = max(X, c)
            c = 1
            i += 1
            break
print(X)

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int,input().split()))
h = [0]*(10**5+1)
for i in l:
  h[i+1] += 1
  h[i] += 1
  h[i+2] += 1
print(max(h))

Submission status: Runtime Error

Solution code:
def main():
    from collections import Counter
    n, *a = map(int, open(0).read().split())
    b = Counter(a)
    c = [[k, v] for k, v in b.items()]
    c.sort(key=lambda x: x[1], reverse=True)
    x = c[0][0]
    al, ar = c[0][1], c[0][1]
    if b.get(x - 1) is not None:
        al += b.get(xl - 1)
    if b.get(x - 2) is not None:
        al += b.get(xl - 2)
    if b.get(x + 1) is not None:
        al += b.get(x + 1)
    if b.get(x + 2) is not None:
        al += b.get(x + 2)

    print(max(al, ar))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
maxim = max(A)
counter = [0]*(maxim+1)
dif = [-1, 0, 1]
for a in A:
    for d in dif:
        if a == 0:
            counter[0] += 1
            counter[1] += 1
            break
        elif a == maxim:
            counter[maxim-1] += 1
            counter[maxim] += 1
        else:
            counter[a+d] += 1
print(max(counter))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
counter = [0]*(max(A)+1)
dif = [-1, 0, 1]
for a in A:
    for d in dif:
        counter[a+d-1] += 1
print(max(counter))

Submission status: Runtime Error

Solution code:
from sys import stdin
from collections import Counter


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

Submission status: Runtime Error

Solution code:
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(max(a)-1)]
print(max(d))

Submission status: Runtime Error

Solution code:
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)
if n == 1:
    print(1)
    sys.exit()
item = []
for key,Value in c.items():
    item.append([key,Value])
koho = []
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,n-2):
    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))

Submission status: Runtime Error

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

for i, v in enumerate(a):
    V[v:v+3, i] = 1
#print(V)
print(np.max(np.sum(V, axis=1, dtype=np.int)))

Submission status: Runtime Error

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

for i, v in enumerate(a):
    V[v:v+3, i] = 1
print(np.max(np.sum(V, axis=1, dtype=np.int)))

Submission status: Runtime Error

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

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
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] += 1

        print(max(res))


if __name__ == '__main__':
    resolve()

Submission status: Runtime Error

Solution code:
#ABC072-C
import collections
import itertools

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


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

    
        
print(max(cnt))

Submission status: Runtime Error

Solution code:
#ABC072-C
import collections
import itertools

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


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

    
        
print(max(cnt))

Submission status: Runtime Error

Solution code:
#ABC072-C
import collections
import itertools

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

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

    
        
print(max(cnt))

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int (input())
a = [int(i) for i in input().split()]

a_sort = np.sort(a)
a_min = a_sort[0]-1
a_max = a_sort[-1]+1
#num_cand = a_max_a_min + +1


dic = {}
for i in range(len(a_sort)):
    added = [a_sort-1, a_sort ,a_sort+1]
    for j in range(len(added)):
        if dic.get(added[j]) is None:
                  dic[added[j]] = 1
        else:
            dic[added[j]] += 1
            
            
            
val = max(list(dic.values()))[0]

print(int(val))

Submission status: Runtime Error

Solution code:
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

k=0
m=0
for key,item in dic.item():
  if(item>m):
    m=item
    k=key
    
print(k)

Submission status: Runtime Error

Solution code:
for i in a:
#     print(i)
    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
#     print(check)
maxnum=max(maxnum,sum(check))

print(maxnum)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def myAnswer(N:int,A:list) -> int:
   if(N == 1): return 1
   dic ={}
   for a in A:
      if(a == 0):
         for i in range(2):
            if(i in dic.keys()):
               dic[i]+=1
            else:
               dic[i]=1
      else:
         for i in range(a-1,a+2):
            if(i in dic.keys()):
               dic[i]+=1
            else:
               dic[i] = 1
   return max(list(dic.values()))

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ =

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
counter = np.bincount(A)
# print(counter)
cumsum = counter.cumsum()
# print(cumsum)
i = min(3, N)
# print('i', i)
print((cumsum[i:] - cumsum[:-i]).max())

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
counter = np.bincount(A)
# print(counter)
cumsum = counter.cumsum()
# print(cumsum)
print((cumsum[3:] - cumsum[:-3]).max())

Submission status: Runtime Error

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

cnt = 0

for x in range(min(A),max(A)):
    transient = A.count(X-1) + A.count(X) + A.count(X+1)
    if transient > cnt:
        cnt = transient

print(cnt)

Submission status: Runtime Error

Solution code:
n=int(input());A = list(map(int,input().split(' ')))
x = [0]*10001
for a in A:
    if a != 0:
        x[a-1]+=1;x[a]+=1;x[a+1]+=1
    else:
        x[a]+=1;x[a+1]+=1
print(max(x))

Submission status: Runtime Error

Solution code:
import sys  
import numpy as np
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
k = [0] * (max(a)+1)

for p in a:
    k[p] += 1
ans = 0
for q,r,s in zip(k, k[1:] + k[2:]):
    ans = max(ans, q+r+s)

print(ans)

Submission status: Runtime Error

Solution code:
import sys  
import numpy as np
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))

a_ = list(set(a))
temp2 = []

for i in a_:
    temp2.appned(a.count(a_))

temp = []
for i in range(1,len(temp2)):
    temp = temp2[i-1] + temp2[i] + temp2[i+1]

print(max(temp))

Submission status: Runtime Error

Solution code:
import numpy as np
from scipy.stats import mode

n = int(input())
a = np.array(input().split(), dtype=np.int64)
b = np.stack([a-1, a ,a+1])
mode_b, count_b = mode(b, axis=None)
print(b)
print(*count_b)

Submission status: Runtime Error

Solution code:
N=int(input())
a=list(map(int,input().split()))
m=max(a)
mm=min(a)
p=[0]*(m-mm)

if 1<=len(a)<=3:
  print(len(a))
else:
  for i in range(mm,m-1):
    p[i]=a.count(i)+a.count(i+1)+a.count(i+2)
  print(max(p))

Submission status: Runtime Error

Solution code:
import numpy as np

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

r = np.zeros(10**5+2)
for i in range(N):
    r[a[i]] += 1
    r[a[i]+1] += 1
    r[a[i]+2] += 1

print(int(r.max()))

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    a = map(int, input().split())
    d = {i: 0 for i in range(100001)}

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

    print(max(d.values()))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N=int(input())
a=list(map(int,input().split()))
m=max(a)
mm=min(a)
p=[0]*(m-mm)

for i in range(mm,m-1):
  p[i]=a.count(i)+a.count(i+1)+a.count(i+2)
  
print(max(p))

Submission status: Runtime Error

Solution code:
N=int(input())
a=list(map(int,input().split()))
m=max(a)
p=[0]*(m-1)

for i in range(m-1):
  p[i]=a.count(i)+a.count(i+1)+a.count(i+2)
  
print(max(p))

Submission status: Runtime Error

Solution code:
N = int(input())
ArR = [int(s) for s in input().split(" ")]

def calculate(n,arr):

    dict = {}

    for ar in arr:
        a1 = ar - 1
        a2 = ar
        a3 = ar + 1

        if dict.get(a1) == None:
            dict.__setitem__(a1,1)
        else:
            dict.__setitem__(a1,dict.get(a1)+1)

        if dict.get(a2) == None:
            dict.__setitem__(a2, 1)
        else:
            dict.__setitem__(a2, dict.get(a2) + 1)

        if dict.get(a3) == None:
            dict.__setitem__(a3, 1)
        else:
            dict.__setitem__(a3, dict.get(a3) + 1)


    print(max(dict.values()))
calculate(N,ARR)

Submission status: Runtime Error

Solution code:
n = input()
s = list(map(int,input().split()))

MAX = max(s)
nums = [0]*(MAX+1)

for i in s:
    if i == 0:
        nums[0] += 1
        nums[1] += 1
    elif i == MAX:
        nums[-1] += 1
        if i != 0:
            nums[-2] += 1
    else:
        nums[i-1] += 1
        nums[i] += 1
        nums[i+1] += 1

print(max(nums))

Submission status: Runtime Error

Solution code:
n = input()
s = list(map(int,input().split()))

MAX = max(s)
nums = [0]*(MAX+1)


for i in s:
    if i == 0:
        nums[0] += 1
        nums[1] += 1
    elif i == MAX:
        nums[-1] += 1
        nums[-2] += 1
    else:
        nums[i-1] += 1
        nums[i] += 1
        nums[i+1] += 1

print(max(nums))

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
#print(A)

d = {}
for i in range(n):
    a = A[i]
    for k in (-1, 0, 1):
        if a+k not in d:
            d[a+k] = 1
        else:
            d[a] += 1
max_ = 0
for v in d.values():
    if v >= max_:
        max_ = v
print(max_)

Submission status: Runtime Error

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

num = set(a)

cnt = [0]*max(num+1)

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

if len(cnt) == 1:
    print(cnt[0])
elif len(cnt) == 2:
    print(sum(cnt))
else:
    for i in range(1, max(a)):
        ans = max(ans, cnt[i-1]+cnt[i]+cnt[i+1])

    print(ans)

Submission status: Runtime Error

Solution code:
n = input()
s = list(map(int,input().split()))

nums = [0]*(max(s)+1)

for i in s:
    if i == 0:
        nums[0] += 1
        nums[1] += 1
    elif i == max(s):
        nums[-1] += 1
        nums[-2] += 1
    else:
        nums[i-1] += 1
        nums[i] += 1
        nums[i+1] += 1

print(max(nums))

Submission status: Runtime Error

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

max_n = max(A,1)
cnt = [0]*max_n
for i in range(max_A):
    for a in A:
        if abs(ai-i)<=1:
            cnt[i] += 1
print(max(cnt))

Submission status: Runtime Error

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

max_n = max(A)
cnt = [0]*max_n
for i in range(1,max_n):
    for a in A:
        if abs(a-i)<=1:
            cnt[i] += 1
print(max(cnt))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = [0] * pow(10,5)
for i in range(n):
  if a[i] == 0:
    b[0] += 1
    b[1] += 1
  elif a[i] == pow(10,5):
    b[pow(10,5) - 1] += 1
    b[pow(10,5)] += 1
  else:
    b[a[i]] += 1
    b[a[i] - 1] += 1
    b[a[i] + 1] += 1
print(max(b))

Submission status: Runtime Error

Solution code:
N = int(input())
a=list(map(int, input().split()))
cnt=[0]*(max(a)+1)
for i in range(N):
    cnt[a[i]]+=1
#print(cnt)

tri=[cnt[i]+cnt[i+1]+cnt[i+2] for i in range(len(cnt)-2)]
#print(tri)
print(max(tri))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in s_li:
        v_1 = s_li.count(v - 1)
        v_0 = s_li.count(v) + s_li.count(v + 1)
        v_2 = s_li.count(v + 2)
        t_c = v_1 + v_0
        t_c2 = v_2 + v_0

        if t_c > count:
            count = t_c
        if t_c2 > count:
            count = t_c2
        if count > len(s_li):
            break
        s_li = s_li[s_li.index(v + 1):]
    print(count)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

// 入力マクロ
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}



fn main() {
    input! {
        n: usize,
        a: [usize; n]
    }

    let mut count = vec![0; 100_002];
    for i in a {
        count[i] += 1;
        count[i+1] += 1;
        count[i+ 2] += 1;
    }

    let ans = count.iter().max().unwrap();
    println!("{}", ans);
}

Submission status: Runtime Error

Solution code:
import read_val
import copy


def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in range(s_li[0] - 1, s_li[-1] + 1):
        t_c = 0
        for vv in s_li:
            if v == vv or v - 1 == vv or v + 1 == vv:
                t_c += 1
            if vv > v + 2:
                break
        if t_c > count:
            count = t_c

    print(count)



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    t = input()
    if t == "1":
        print(input())
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in s_li:
        list_2 = list(filter(lambda x: x == v - 1 or x == v or x == v + 1, s_li))
        if len(list_2) > count:
            count = len(list_2)

    print(count)



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import read_val
import copy


def main():
    t = input()
    if t == "1":
        print(input())
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in s_li:
        list_2 = list(filter(lambda x: x == v - 1 or x == v or x == v + 1, s_li))
        if len(list_2) > count:
            count = len(list_2)

    print(count)



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

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

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

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

sum_three_num = []
for i in range(1, len(bucket) - 1):
    sum_three_num.append(bucket[i-1] + bucket[i] + bucket[i+1])

print(max(sum_three_num))

Submission status: Runtime Error

Solution code:
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)
c=Counter(a).most_common()
print(c[0][1])

Submission status: Runtime Error

Solution code:
n=int,input()
a=list(map(int,input().split()))
m=max(a)
n=min(a)
for i in range(n,m+1):
    pre=0
    for j in range(len(a)):
        if i-1<=a[j]<=i+1:
            pre+=1
    ans=max(ans,pre)
    
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
  import sys
  input = sys.stdin.readline
  n=input()
  a=tuple(map(int,input().split()))
  cnt=[0]*(max(a)+2)
  for i in a:
    cnt[i]+= 1
  print(max(map(sum,zip(cnt,cnt[1:],cnt[2:]))))  
if __name__=='__main__':
  main()

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define len(array) (sizeof(array) / sizeof(array[0]))
#define asort(array) sort(array, array + len(array))

int main() {
  int n;cin>>n;
  vector<int> an(100100);
  int a;
  rep(i,n) {
    cin>>a;
    an[a]++;
  }
  int x = an[1]+an[2]+an[3];
  int mx = x;
  rep(i,100000) {
    x = x - an[i+1] + an[i+4];
    mx = max(mx,x);
  }
  cout << mx;
}