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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
c = [0]*(max(a)+1)
max_num = 0
for i in a:
  c[i] += 1
for x in range(max(a)-1):
  if max_num < (c[x] + c[x+1] + c[x+2]):
      max_num = (c[x] + c[x+1] + c[x+2])
print(max_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
c = [0]*(max(a)+1)
max_num = 0
for i in a:
  c[i] += 1
for x in range(max(a)):
  if max_num < (c[x-1]) + (c[x]) + (c[x+1]):
      max_num = (c[x-1]) + (c[x]) + (c[x+1])
print(max_num)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
a = list(map(int,input().split()))
c = Counter(a)
max_num = 0
for x in range(1,max(a)+1):
  if max_num < (c[x-1]) + (c[x]) + (c[x+1]):
      max_num = max(max_num,(c[x-1]) + (c[x]) + (c[x+1]))
print(max_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
c = [0]*(max(a)+1)
max_num = 0
for i in a:
  c[i] += 1
for x in range(1,max(a)):
  if max_num < (c[x-1]) + (c[x]) + (c[x+1]):
      max_num = (c[x-1]) + (c[x]) + (c[x+1])
print(max_num)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# yorikatu_58_b.py
def summlize(C,i):
    ans = C[i]
    if i > 1:
       ans += C[i-1]
    if i < len(C):
        ans += C[i+1]
    return ans

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

ans = 0
for i in C.keys():
    sums = summlize(C,i)
    if ans < sums:
        ans = sums
print(ans)

Submission status: Wrong Answer

Solution code:
# yorikatu_58_b.py
def summlize(C,i):
    ans = C[i]
    if i > 1:
       ans += C[i-1]
    if i < len(C):
        ans += C[i+1]
    return ans

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

ans = 0
for i in range(100005):
    sums = summlize(C,i)
    if ans < sums:
        ans = sums
print(ans)

Submission status: Wrong Answer

Solution code:
# yorikatu_58_b.py
def summlize(C,i):
    ans = C[i]
    if i > 1:
       ans += C[i-1]
    if i < len(C):
        ans += C[i+1]
    return ans

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

ans = 0
for i in range(100000):
    sums = summlize(C,i)
    if ans < sums:
        ans = sums
print(ans)

Submission status: Wrong Answer

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


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()
# print(a)
aa = sorted(a)
# print(aa)
cnt = 0
ans = -1
for i in range(n):
    if aa[i]-aa[0] <= 2:
        cnt += 1
    ans = max(cnt, ans)
print(ans)

Submission status: Wrong Answer

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


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()
# print(a)
aa = sorted(a)
# print(aa)
cnt = 0
for i in range(n):
    if aa[i]-aa[0] <= 2:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

cnt = [0] * (max(a) + 2)

for i in range(n):
    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)

Submission status: Wrong Answer

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

  print(ans)
  return

if __name__ == "__main__":
  resolve()

Submission status: Wrong Answer

Solution code:
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=1
for i in range(len(aset)-1):
    k=1
    s=ca[aset[i]]
    while aset[i]+2>=aset[i+k]:
        k+=1
        if i+k>=len(aset):
            break
        s+=ca[aset[i+k]]
    ans=max(ans,s)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

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

b = collections.Counter(a)
b=b.most_common()
b.sort()
ans = 1

for i in range(len(b)-2):
    if b[i+2][0]-b[i][0]==2:
        ans=max(ans,b[i][1]+b[i+1][1]+b[i+2][1])
    elif b[i+2][0]-b[i][0]>2 and b[i+1][0]-b[i][0] <= 2:
        ans=max(ans,b[i][1]+b[i+1][1])
    else:
        ans=max(ans,b[i][1])
        
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

b = collections.Counter(a)
b=b.most_common()
b.sort()
ans = -1

for i in range(len(b)-2):
    if b[i+2][0]-b[i][0]==2:
        ans=max(ans,b[i][1]+b[i+1][1]+b[i+2][1])
    elif b[i+2][0]-b[i][0]>2 and b[i+1][0]-b[i][0] <= 2:
        ans=max(ans,b[i][1]+b[i+1][1])
    else:
        ans=max(ans,b[i][1])
        
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
*a, = map(int,input().split())
b = Counter(a)
c = sorted(b.items())
l = len(c)
ans = 1
for i in range(l):
    z = c[i][1]

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

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
*a, = map(int,input().split())
b = Counter(a)
c = sorted(b.items())
l = len(b)
ans = 0
for i in range(l):
    z = c[i][1]

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

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
*a, = map(int,input().split())
b = Counter(a)
c = sorted(b.items())
l = len(b)

ans = 0
for i in range(l):
    u = i - 1
    z = c[i][1]
    if 0<=u<l:
        z += c[u][1]
    v = i + 1
    if 0<=v<l:
        z += c[v][1]
    
    ans = max(ans, z)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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,max(a)):
    num2=num[i-1]+num[i]+num[i+1]
    if ans<num2:
        ans=num2
print(ans)

Submission status: Wrong Answer

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

## Library

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

## 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

X = 0

A.sort()
print(A)

tmp1 = A.count(A[0])
tmp2 = A.count(A[0]+1)

for i in range(A[0]+2,A[N-1]):
    tmp = tmp1+tmp2+A.count(i)
    if tmp > X:
        X = tmp
    else:
        tmp1 = A.count(i)
print(X)

Submission status: Wrong Answer

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

## Library

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

## 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

X = 0

A.sort()

for i in range(A[0],A[N-1]):
    X = max(X, A.count(i-1)+A.count(i)+A.count(i+1))
print(X)

Submission status: Wrong Answer

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,len(t)-1):
  x=max(x,t[j-1]+t[j]+t[j+1])

print(x)

Submission status: Wrong Answer

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

max_v=0
ans=0
ks=[0]+list(dic.values()) + [0]
for i in range(1,len(ks)-1):
  arround_v=ks[i-1]+ks[i]+ks[i+1]
  if max_v < arround_v:
    max_v=arround_v
    ans = arround_v
print(ans)

Submission status: Wrong Answer

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: Wrong Answer

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-1]+=1
print(max(b))

Submission status: Wrong Answer

Solution code:
n  =  int(input())
a= list(input().split())
a = [int(i) for i in a]
a.sort()
cnt=0

pre = -1
for i in range(0, len(a)):
  #print(i, i)
  if pre == a[i]:
    #print("pre", i)
    continue
  if a[i]+1 in a and a[i]+2 in a:
    if cnt < a.count(a[i]) + a.count(a[i]+1) + a.count(a[i]+2):
      cnt = a.count(a[i]) + a.count(a[i]+1) + a.count(a[i]+2)
  elif a[i]+1 in a:
    #print(a[i], a[i]+1, a.count(a[i]) + a.count(a[i]+1))
    if cnt < a.count(a[i]) + a.count(a[i]+1):
      cnt = a.count(a[i]) + a.count(a[i]+1)
  pre=a[i]
  if cnt > len(a) /2:
    break
if cnt == 0:
  print(1)
else:
  print(cnt)

Submission status: Wrong Answer

Solution code:
n  =  int(input())
a= list(input().split())
a = [int(i) for i in a]
a.sort()
cnt=0

pre = -1
for i in range(0, len(a)):
  #print(i, i)
  if pre == a[i]:
    #print("pre", i)
    continue
  if a[i]+1 in a and a[i]+2 in a:
    if cnt < a.count(a[i]) + a.count(a[i]+1) + a.count(a[i]+2):
      cnt = a.count(a[i]) + a.count(a[i]+1) + a.count(a[i]+2)
  elif a[i]+1 in a:
    #print(a[i], a[i]+1, a.count(a[i]) + a.count(a[i]+1))
    if cnt < a.count(a[i]) + a.count(a[i]+1):
      cnt = a.count(a[i]) + a.count(a[i]+1)
  pre=a[i]
if cnt == 0:
  print(1)
else:
  print(cnt)

Submission status: Wrong Answer

Solution code:
s=int(input())
n=set()
a=s
for i in range(10**7):
    if a in n:
        break
    
    if a%2==0:
        n.add(a)
        a=a//2
    else:
        n.add(a)
        a=3*a+1
 
print(i+1)

Submission status: Wrong Answer

Solution code:
n  =  int(input())
a= list(input().split())
a = [int(i) for i in a]
a.sort()
cnt=0

pre = -1
for i in range(0, len(a)):
  #print(i, i)
  if pre == a[i]:
    continue
  if a[i]+1 in a and a[i]+2 in a:
    if cnt < a.count(a[i]) + a.count(a[i]+1) + a.count(a[i]+2):
      cnt = a.count(a[i]) + a.count(a[i]+1) + a.count(a[i]+2)
  elif a[i]+1 in a:
    if cnt < a.count(a[i]) + a.count(a[i]+1):
      cnt = a.count(a[i]) + a.count(a[i]+1)
  else:
    break
  pre=a[i]
if cnt == 0:
  print(1)
else:
  print(cnt)

Submission status: Wrong Answer

Solution code:
n  =  int(input())
a= list(input().split())
a = [int(i) for i in a]
a.sort()
cnt=0

pre = -1
for i in range(0, len(a)):
  #print(i, i)
  if pre == a[i]:
    break
  if a[i]+1 in a and a[i]+2 in a:
    if cnt < a.count(a[i]) + a.count(a[i]+1) + a.count(a[i]+2):
      cnt = a.count(a[i]) + a.count(a[i]+1) + a.count(a[i]+2)
  elif a[i]+1 in a:
    if cnt < a.count(a[i]) + a.count(a[i]+1):
      cnt = a.count(a[i]) + a.count(a[i]+1)
  else:
    break
  pre=a[i]
if cnt == 0:
  print(1)
else:
  print(cnt)

Submission status: Wrong Answer

Solution code:
n  =  int(input())
a= list(input().split())
a = [int(i) for i in a]
a.sort()
cnt=0
for i in range(0, len(a)):
  #print(i, i)
  if a[i]+1 in a and a[i]+2 in a:
    if cnt < a.count(a[i]) + a.count(a[i]+1) + a.count(a[i]+2):
      cnt = a.count(a[i]) + a.count(a[i]+1) + a.count(a[i]+2)
  elif a[i]+1 in a:
    if cnt < a.count(a[i]) + a.count(a[i]+1):
      cnt = a.count(a[i]) + a.count(a[i]+1)
  else:
    break
if cnt == 0:
  print(1)
else:
  print(cnt)

Submission status: Wrong Answer

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

dic = {a:1 for a in 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()))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
X1, X2, X3 = 0, a.count(0), a.count(1)
count = X1 + X2 + X3
ans = 0
for i in range(2, max(a) + 1):
  count -= X1
  X1, X2, X3 = X2, X3, a.count(i)
  count += X3
  ans = max(ans, count)
else:
  print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=sorted(list(map(int,input().split())))
p=collections.Counter(A)
p_max = max(p, key=p.get)
ans1 = p[p_max]+p[p_max+1]+p[p_max-1]
ans2 = p[p_max]+p[p_max+1]+p[p_max+2]
ans3 = p[p_max]+p[p_max-1]+p[p_max-2]
print(max(ans1,ans2,ans3))

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=sorted(list(map(int,input().split())))
p=collections.Counter(A)
p_max = max(p, key=p.get)
ans = p[p_max]+p[p_max+1]+p[p_max-1]+p[p_max+2]+p[p_max-2]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=sorted(list(map(int,input().split())))
p=collections.Counter(A)
p_max = max(p, key=p.get)
ans = p[p_max]+p[p_max+1]+p[p_max-1]
print(max(ans+p[p_max+2],ans+p[p_max-2]))

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=sorted(list(map(int,input().split())))
p=collections.Counter(A)
p_max = max(p, key=p.get)
print(max(p[p_max]+p[p_max-1]+p[p_max-2],p[p_max]+p[p_max+1]+p[p_max+2],p[p_max]+p[p_max+1]+p[p_max-1]))

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=sorted(list(map(int,input().split())))
p=collections.Counter(A)
p_max = max(p, key=p.get)
print(max(p[p_max]+p[p_max-1]+p[p_max-2],p[p_max]+p[p_max+1]+p[p_max+2]))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
mana=0
l=[]
for i in range(1,n+1):
    ans=0
    if abs(a[i-1]-1)==i or abs(a[i-1]+1==i) or a[i-1]==i:
        ans+=1
        mana=max(ans,mana)
        l.append(mana)
print(mana)
print(l)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
amin = min(a) 
amax = max(a)
count = [0]*(amax+2)

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

ans=max(count)  
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
amin = min(a) 
amax = max(a)
count = [0]*(amax-amin)

for i in range(amin,amax,1):
  count[i-amin]=a.count(i)

ans=0
for i in range(len(count)-2):
  ans = max([ans, sum(count[i:i+3])])
  
print(ans)

Submission status: Wrong Answer

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

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

print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
Max = 0
count = 0
for i in range(1, N-1):
    if(a[i+1] - a[i] <= 1 and a[i] - a[i-1] <= 1):
            count = 3
            nowPlus = i+2
            nowMinus = i-2
            while  nowPlus <= N-1 and a[nowPlus] - a[i] < 2:
                count += 1
                nowPlus += 1
            while nowMinus >= 0 and a[i] - a[nowMinus] < 2 :
                count += 1
                nowMinus -= 1
            if(count > Max):
                Max = count
if(N == 1):
    Max = 1
print(Max)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
ans = 0
for i in range(1,n):
    dum = li.count(i-1) + li.count(i) + li.count(i+1)
    ans = max(dum,ans)
print(ans)

Submission status: Wrong Answer

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

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

maxA = max(a)
cntA = [0] * (10**6)
cnt3 = [0] * (10**6)

for _a in a:
    cntA[_a] += 1

for i in range(maxA-1):
    cnt3[i] += cntA[i] + cntA[i+1] + cntA[i+2]


# print(cntA)
# print(cnt3)

ans = max(cnt3)
print(ans)

Submission status: Wrong Answer

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

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

maxA = max(a)
cntA = [0] * (maxA + 2)
cnt3 = [0] * (maxA + 2)

for _a in a:
    cntA[_a] += 1

for i in range(maxA-1):
    cnt3[i] += cntA[i] + cntA[i+1] + cntA[i+2]


# print(cntA)
# print(cnt3)

ans = max(cnt3)
print(ans)

Submission status: Wrong Answer

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

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

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

print(max(cnt))

Submission status: Wrong Answer

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

for i in range(n):
  if a[i] not in dict:
    dict[a[i]] = 1
  else:
    dict[a[i]] += 1
    
l = list(sorted(dict.items()))
newl = [0,0]
for i in range(len(l)):
  newl.append(l[i][1])
newl += [0,0]
ans = 0

for j in range(len(newl)-2):
  ans = max(ans,newl[j]+newl[j+1]+newl[j+2])
  
print(ans)

Submission status: Wrong Answer

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

for i in range(n):
  if a[i] not in dict:
    dict[a[i]] = 1
  else:
    dict[a[i]] += 1
    
newd = sorted(dict.items())
ans = 0

for j in range(len(dict)-2):
  ans = max(ans,newd[j][1]+newd[j+1][1]+newd[j+2][1])
  
print(ans)

Submission status: Wrong Answer

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

for i in range(2,n+2):
  if i not in dict:
    dict[i] = 1
  else:
    dict[i] += 1
    
dict[len(dict)] = 0
dict[len(dict)] = 0
ans = 0

for j in range(len(dict)-2):
  ans = max(ans,dict[j]+dict[j+1]+dict[j+2])
  
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(int, input().split()))
max_s = max(S)
min_s = min(S)
ans = 0

for i in range(min_s ,max_s):
  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: Wrong Answer

Solution code:
n = int(input())

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

a = sorted(a)
l = [0]*100005 

for i in a:
    l[i-1] += 1
ans = 1
for i in range(1,n-1):
    cnt = 0
    cnt += l[i] + l[i-1] + l[i+1]
        
    ans = max(ans,cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
ans = 1
for i in range(min(A) + 1, max(A)):
    ans = max(ans, sum([i - 1 <= a <= i + 1 for a in A]))
print(ans)

Submission status: Wrong Answer

Solution code:
N=input()
A=list(map(int,input().split()))
counts = []
for i in range(min(A),max(A)+1):
    counts.append(A.count(i))
if len(counts)>2:
    ans = []
    for i in range(1,len(counts)-1):
        ans.append(counts[i-1]+counts[i]+counts[i+1])
    print(max(ans))
else:
    print(max(counts))

Submission status: Wrong Answer

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+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] = s
print(aaa)
print(max(aaa))

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
a.sort()
#print(a)
l=[0]*(a[-1]+1)#l[i]にはiの数が入る
for i in range(N):
    l[a[i]]+=1
#print(l)
ans=0
for i in range(len(l)-2):
    if ans<l[i]+l[i+1]+l[i+2]:
        ans=l[i]+l[i+1]+l[i+2]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int, input().split()))
m=max(a)
table=[0]*(m+2)

for num in a:
    table[num-1]+=1
    table[num]+=1
    table[num+1]+=1

ans=max(table)
print(ans)

Submission status: Wrong Answer

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

for i in range(N):
    if abs(a[i]-2) <= 1:
        cnt += 1

print(cnt)

Submission status: Wrong Answer

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

for i in range(len(a)):
    if abs(a[i]-2 <= 1):
        cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
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:
        if i == N - 1:
            X = max(X, c)
            break
        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: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
ma = max(a_list)
hoge = [0]*(ma+1)
for i in range(ma+1):
  hoge[i] = a_list.count(i)
ans = 0
for i in range(1,ma):
  t = hoge[i-1] + hoge[i] + hoge[i+1]
  if t > ans:
    ans = t
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
import statistics
ans = 0
X = statistics.median(a)
#print(X)
ans = 0
for i in range(int(X-N/10),int(X+N/10)):
    num = 0
    for j in a:
        if abs(i-j)<=1:
            num += 1
    ans = max(ans,num)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import queue
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1

n = readInt()
a = readInts()

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

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

ans = 0

for i in range(n-1):
	ans = max(ans, d[i]+d[i+1]+d[i+2])

print(ans)

Submission status: Wrong Answer

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, ac = map(int, [c[0][1], c[0][1], c[0][1]])
    s, t, u, v = b.get(x - 2), b.get(x - 1), b.get(x + 1), b.get(x + 2)
    if s is not None:
        al += s
    if t is not None:
        al += t
        ac += t
    if u is not None:
        ac += u
        ar += u
    if v is not None:
        ar += v

    print(max([al, ar, ac]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from collections import Counter
    n, *a = map(int, open(0).read().split())
    r, l = min(a), max(a)
    b = Counter(a)
    ans = 0
    for i in range(r, l):
        tmp = 0
        p, q, r = b.get(i - 1), b.get(i), b.get(i + 1)
        if p is not None:
            tmp += p
        if q is not None:
            tmp += q
        if q is not None:
            tmp += q
        ans = max(ans, tmp)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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, ac = c[0][1], c[0][1], c[0][1]
    s, t, u, v = b.get(x - 2), b.get(x - 1), b.get(x + 1), b.get(x + 2)
    if s is not None:
        al += s
    if t is not None:
        al += t
        ac += t
    if u is not None:
        ac += u
        ar += u
    if v is not None:
        ar += v

    print(max([al, ar, ac]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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(x - 1)
    if b.get(x - 2) is not None:
        al += b.get(x - 2)
    if b.get(x + 1) is not None:
        ar += b.get(x + 1)
    if b.get(x + 2) is not None:
        ar += b.get(x + 2)

    print(max(al, ar))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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(x - 1)
    if b.get(x - 2) is not None:
        al += b.get(x - 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: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))
    l = [0]*(10**5 + 10)


    for i in set(a):
        for j in a:
            if j - 1 <= i <= j + 1:
                l[j] += 1
        
    print(max(l))

main()

Submission status: Wrong Answer

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

for i in range(min(a), max(a)):
    cnt = 0
    for j in a:
        if j - 1 <= i <= j + 1:
            cnt += 1
    ans = max(ans, cnt)

print(ans)