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:
import collections
N = int(input())
a = list(map(int, input().split()))
if N == 1:
    print(1)
    exit()
if N == 2:
    if abs(a[0]-a[1]) <= 2:
        print(2)
    else:
        print(1)
    exit()
c = collections.Counter(a)
c_key = list(c.keys())
c_value = list(c.values())
res = 0
for i in range(1,len(c)-1):
    temp = c_value[i]
    temp_2 = 0
    temp_3 = 0
    flag = True
    if int(c_key[i])-int(c_key[i-1]) == 1:
        temp += c_value[i-1]
        flag = False
    if int(c_key[i+1])-int(c_key[i]) == 1:
        temp += c_value[i+1]
        flag = False
    if flag and int(c_key[i+1])-int(c_key[i]) == 2:
        temp_2 = c_value[i+1]+c_value[i]
        flag = False
    if flag and int(c_key[i])-int(c_key[i-1]) == 2:
        temp_3 = c_value[i-1]+c_value[i]
    if max(temp,temp_2,temp_3) > res:
        res = max(temp,temp_2,temp_3)
print(max(res,c_value[0],c_value[-1]))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
if N == 1:
    print(1)
    exit()
if N == 2:
    if abs(a[0]-a[1]) <= 2:
        print(2)
    else:
        print(1)
    exit()
c = collections.Counter(a)
c_key = list(c.keys())
c_value = list(c.values())
res = 0
for i in range(1,len(c)-1):
    temp = c_value[i]
    if int(c_key[i])-int(c_key[i-1]) == 1:
        temp += c_value[i-1]
    if int(c_key[i+1])-int(c_key[i]) == 1:
        temp += c_value[i+1]
    if temp > res:
        res = temp
print(max(res,c_value[0],c_value[-1]))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
if N == 1:
    print(1)
    exit()
if N == 2:
    if abs(a[0]-a[1]) <= 1:
        print(2)
    else:
        print(1)
    exit()
c = collections.Counter(a)
c_key = list(c.keys())
c_value = list(c.values())
res = 0
for i in range(1,len(c)-1):
    temp = c_value[i]
    if int(c_key[i])-int(c_key[i-1]) == 1:
        temp += c_value[i-1]
    if int(c_key[i+1])-int(c_key[i]) == 1:
        temp += c_value[i+1]
    if temp > res:
        res = temp
print(max(res,c_value[0],c_value[-1]))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
if N == 1:
    print(1)
    exit()
c = collections.Counter(a)
c_key = list(c.keys())
c_value = list(c.values())
res = 0
for i in range(1,len(c)-1):
    temp = c_value[i]
    if int(c_key[i])-int(c_key[i-1]) == 1:
        temp += c_value[i-1]
    if int(c_key[i+1])-int(c_key[i]) == 1:
        temp += c_value[i+1]
    if temp > res:
        res = temp
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
dic = Counter(A)
cnt = 1
Mcnt = 0
for i in range(0,N):
  if (i-1) in dic and (i+1) in dic:
      cnt = dic[i-1] + dic[i] + dic[i+1]
  elif (i-1) in dic:
      cnt = dic[i-1] + dic[i]
  elif (i+1) in dic:
      cnt = dic[i] + dic[i+1]
  else:
      cnt = dic[i]
  if Mcnt < cnt:
    Mcnt = cnt
print(Mcnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
cnt = 1
Mcnt = 0
for i in range(0,N-1):
  for j in range(i+1,N):
      if A[j] - A[i] <= 2:
        cnt += 1
      else:
        if Mcnt < cnt:
          Mcnt = cnt
        cnt = 1
print(Mcnt)

Submission status: Wrong Answer

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

# 先にxを選んでおく！
ans = 0
for i in range(1, max(L) + 1):
    cm = L.count(i - 1)
    ce = L.count(i)
    cl = L.count(i + 1)
    ans = max(ans, cm + ce + cl)

print(ans)

Submission status: Wrong Answer

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

  c = [0] * (max(a)+1)

  for v in a:
    c[v] += 1

  ans = 0

  for i in range(len(c) - 2):
    x = c[i] + c[i+1] + c[i+2]
    ans = max(ans, x)

  print(ans)

if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
import math

n=int(input())
A=np.array(sorted(list(map(int,input().split()))))
if n==1:
    print(1)
elif n==2:
    print(2 if abs(A[0]-A[1])<=1 else 1)
else:
    #print(A)
    ans=0
    temp,left=0,0
    for i in range(1,n):
        if A[i]-A[left]<=2:
            ans=max(ans,i-left+1)
        elif A[i]-A[temp]<=2:
            ans=max(ans,i-temp+1)
        if A[i]!=A[i-1]:
            temp,left=i,temp
        #print(temp,left,ans)
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
import math

n=int(input())
A=np.array(sorted(list(map(int,input().split()))))
if n==1:
    print(1)
elif n==2:
    print(2 if abs(A[0]-A[1])<=1 else 1)
else:
    #print(A)
    ans=0
    temp,left=0,0
    for i in range(1,n):
        if A[i]-A[left]<=2:
            ans=max(ans,i-left+1)
        if A[i]!=A[i-1]:
            temp,left=i,temp
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
import math

n=int(input())
A=np.array(sorted(list(map(int,input().split()))))
if n==1:
    print(1)
elif n==2:
    print(2 if abs(A[0]-A[1])<=1 else 1)
else:
    #print(A)
    ans=0
    temp=(2 if A[1]-A[0]==0 else 1)
    left=0
    right=(2 if A[1]-A[0]==0 else 1)
    for i in range(1,n-1):
        if A[i]==A[i+1]:
            temp=right
            right+=1
        elif A[i+1]-A[i]==1:
            left=temp+1
            temp=right+1
            right=1
        else:
            temp,left,right=0,0,1
        #print(left,temp,right)
        ans=max(ans,left,temp,right)
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
import math

n=int(input())
A=np.array(sorted(list(map(int,input().split()))))
if n==1:
    print(1)
elif n==2:
    print(2 if abs(A[0]-A[1])<=1 else 1)
else:
    #print(A)
    ans=0
    temp=(2 if A[1]-A[0]==0 else 1)
    left=0
    right=(2 if A[1]-A[0]==0 else 1)
    for i in range(1,n-1):
        if A[i]==A[i+1]:
            temp+=1
            right+=1
        elif A[i+1]-A[i]==1:
            left=temp+1
            temp=right+1
            right=1
        else:
            temp,left,right=0,0,1
        #print(left,temp,right)
        ans=max(ans,left,temp,right)
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
import math

n=int(input())
A=np.array(sorted(list(map(int,input().split()))))
if n==1:
    print(1)
elif n==2:
    print(2 if abs(A[0]-A[1])<=1 else 1)
else:
    #print(A)
    ans=0
    temp=(2 if A[1]-A[0]==0 else 1)
    left=0
    right=(2 if A[1]-A[0]==0 else 1)
    for i in range(1,n-1):
        if A[i]==A[i+1]:
            temp+=1
            right+=1
        elif A[i+1]-A[i]==1:
            left=temp+1
            temp=right+1
            right=1
        else:
            temp,left,right=0,0,1
        #print(left,temp,right)
        ans=max(ans,left,temp)
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = sorted(list(map(int,input().split())))
c = collections.Counter(A)
Xmax = A[N-1]
ans = 0
tmp = 0
for X in range(Xmax):
  if X-1 in c:
    tmp += c[X-1]
  if X in c:
    tmp += c[X]
  if X+1 in c:
    tmp += c[X+1]
  ans = max(ans,tmp)
  tmp =0
  
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
import sys
import numpy as np
import statistics
n=int(input())
a=np.array(list(map(int,input().split())))
add_a=a+1
al=list(add_a)
minus_a=a-1
ml=list(minus_a)
l=list(a)+al+ml
try:
    most=statistics.mode(l)
    print(l.count(most))
except statistics.StatisticsError:
    print(min(n,3))

Submission status: Wrong Answer

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


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


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


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


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


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

N = read_a_int()
A = read_ints()

# どの数字を一番多くできるか
n_X = [0] * (10 ** 5 + 1)  # =Xにできる個数

for a in A:
    for da in [-1, 0, 1]:
        n_X[a + da] += 1
print(max(n_X))
# https://atcoder.jp/contests/abc072/tasks/arc082_a

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
max_val = max(A)
B = [0]*(max_val+1)
for i in range(N):
  B[A[i]]+=1
total = 0
for i in range(max_val-1):
  if total<B[i]+B[i+1]+B[i+2]:
    total = B[i]+B[i+1]+B[i+2]
print(total)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
A.sort()
A_c = Counter(A)
ans = 1

for i in range(1, N - 1):

    if A[i] * 3 - 3 <= sum(A[i - 1:i + 2]) <= A[i] * 3 + 3:
        ans = max(ans, sum([A_c[j] for j in set(A[i - 1:i + 2])]))

print(2 if len(A) == 2 and A[0] + 1 == A[1] else ans)

Submission status: Wrong Answer

Solution code:
import sys

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


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

    amax = max(a)

    from collections import Counter

    counter = Counter(a)

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(N):
    if p[i] == i+1:
        try:
            p[i+1],p[i] = p[i],p[i+1]
        except:
            pass
        ans += 1

print(ans)

Submission status: Wrong Answer

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(1,len(num)-1):
    tmp = num[i-1] + num[i] + num[i+1]
    ans = max(ans,tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
ave = sum(A) // len(A)

ans1 = len(list(filter(lambda x: x == ave or x+1 == ave or x-1 == ave, A)))
ans2 = len(list(filter(lambda x: x == ave+1 or x+1 == ave+1 or x-1 == ave+1, A)))

print(max(ans1, ans2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(max(p))

Submission status: Wrong Answer

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

print(max(p))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#ABC072-C
import collections
import itertools

n = int(input())
a = list(map(int,input().split()))
a.sort()
cnt = 0
for i in range(min(a)+1,max(a)-1):
    tmp = a.count(i-1) + a.count(i) + a.count(i+1)
    if tmp > cnt:
        cnt = tmp
        
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#ABC072-C
import collections
import itertools

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

c = collections.Counter(a)
acc = list(itertools.accumulate(c.values()))

acc.insert(0,0)
tmp = 0
tmp_prev = 0
if len(acc) >= 3:
    for i in range(3,len(acc)):
        tmp = acc[i] - acc[i-3]
        if tmp >= tmp_prev:
            tmp_prev = tmp
    print(tmp_prev)
        
else:
    print(acc[-1])

Submission status: Wrong Answer

Solution code:
#ABC072-C
import collections
import itertools

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

c = collections.Counter(a)
acc = list(itertools.accumulate(c.values()))

acc.insert(0,0)
tmp = 0
tmp_prev = 0
if len(acc) > 3:
    for i in range(3,len(acc)):
        tmp = acc[i] - acc[i-3]
        if tmp >= tmp_prev:
            tmp_prev = tmp
    print(tmp_prev)
        
else:
    print(acc[-1])

Submission status: Wrong Answer

Solution code:
#ABC072-C
import collections
import itertools

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

c = collections.Counter(a)
acc = list(itertools.accumulate(c.values()))

acc.insert(0,0)
tmp = 0
tmp_prev = 0
for i in range(3,len(acc)):
    tmp = acc[i] - acc[i-3]
    if tmp > tmp_prev:
        tmp_prev = tmp
        
        
print(tmp_prev)

Submission status: Wrong Answer

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

print(max(anslist))

Submission status: Wrong Answer

Solution code:
n=int(input())

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

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

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

print(maxnum)

Submission status: Wrong Answer

Solution code:
n=int(input())

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

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

for i in a:
#     print(i)
    if pre<i-1:
        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]
#     print(check)
maxnum=max(maxnum,sum(check))

print(maxnum)

Submission status: Wrong Answer

Solution code:
import collections

N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
M=collections.Counter(L)
M=sorted(M.items())
ans=max(M[i][1] for i in range(len(M)))
for i in range(1,len(M)-1):
	tmp=0
	tmp+=M[i][1]
	if M[i-1][0]==M[i][0]-1:
		tmp+=M[i-1][1]
	if M[i+1][0]==M[i][0]+1:
		tmp+=M[i+1][1]
	ans=max(ans,tmp)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
import math

n = int(input())
#a = list(map(int, stdin.readline().rstrip().split()))
a = sorted(list(map(int, stdin.readline().rstrip().split())))


count_max = 1

count_prev = 0
count_curr = 1
count_next = 0

current_value = a[0]
for i in range(1, n):
    if a[i] == current_value:
        count_curr += 1
    elif a[i] == current_value + 1:
        count_next += 1
    elif a[i] == current_value + 2:
        count_max = max(count_max, (count_prev + count_curr + count_next))
        current_value = current_value + 1
        count_prev = count_curr
        count_curr = count_next
        count_next = 1
    elif a[i] >= current_value + 3:
        count_max = max(count_max, (count_prev + count_curr + count_next))
        current_value = a[i]
        count_prev = 0
        count_curr = 1
        count_next = 0
    else:
        print("Error")


print(count_max)

Submission status: Wrong Answer

Solution code:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    d = {}
    for a in A:
        for i in [-1, 0, a]:
            if not a+i in d:
                d[a+i] = 1
            else:
                d[a+i] += 1
    print(max(d.values()))

if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

def input():
    return sys.stdin.readline().strip()

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

    for i in range(1,N+1):
        cnt = max(a.count(i-1)+a.count(i)+a.count(i+1),cnt)
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

def input():
    return sys.stdin.readline().strip()

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

    for i in range(min(a),max(a)):
        cnt = max(a.count(i-1)+a.count(i)+a.count(i+1),cnt)
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrA = np.array(input().split(),dtype=np.int64)

arr = np.bincount(arrA)
ans = 0
if len(arr)==2:
    ans = sum(arr)
else:
    for i in range(len(arr)):
        if i+3>len(arr):
            break
        num = sum(arr[i:i+3])
        ans = max(ans,num)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Wrong Answer

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrA = np.array(input().split(),dtype=np.int64)

arr = np.bincount(arrA)
ans = 0
# print(arr)
for i in range(1,len(arr)-1):
    num = arr[i-1] + arr[i] + arr[i+1]
    ans = max(ans,num)
    # print(i,num,ans)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Wrong Answer

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrA = np.array(input().split(),dtype=np.int64)

arr = np.bincount(arrA)
ans = 0
print(arr)
for i in range(1,len(arr)-1):
    num = arr[i-1] + arr[i] + arr[i+1]
    ans = max(ans,num)
    print(i,num,ans)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Wrong Answer

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrA = np.array(input().split(),dtype=np.int64)

arr = np.bincount(arrA)
ans = 0
for i in range(len(arr)):
    if i+3>len(arr):
        break
    num = sum(arr[i:i+3])
    ans = max(ans,num)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def myAnswer(N:int,A:list) -> int:
   if(N == 1): return A[0]
   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__ == '__main__':
   main()

Submission status: Wrong Answer

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()
ans = 0

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

for i in A:
    if i != 0:
        l[i-1] += 1
    l[i] += 1
    l[i+1] += 1
print(l)
print(max(l))

Submission status: Wrong Answer

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()
ans = 0

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

for i in A:
    l[i-1] += 1
    l[i] += 1
    l[i+1] += 1

print(max(l))

Submission status: Wrong Answer

Solution code:

import sys
import collections
#import numpy as np

readline = sys.stdin.readline

def main():
    N = int(input())
    #A1 = np.array(list(map(int, readline().split())))
    A = list(map(int, readline().split()))

    count = [0] * (max(A) + 2)
    for a in A:
        count[a] += 1
        count[a-1] += 1
        count[a+1] += 1

    print(max(count))  


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A_count = [0] * (max(A)+1)

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

max_count = 0
if len(A_count) < 4:
    print(sum(A_count))
else:
    for X in range(1, len(A_count)-1):
        count = A_count[X-1]+A_count[X]+A_count[X+1]
        if count > max_count:
            max_count = count

print(max_count)

Submission status: Wrong Answer

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

max_count = 0

for X in range(1, max(A)):
    count = A.count(X-1) + A.count(X) + A.count(X+1)
    if count > max_count:
        max_count = count

print(max_count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
max_count = 0

for X in range(1, max(A)):
    count = 0
    for i in A:
        if X-1 <= i <= X+1:
            count += 1
    
    if count > max_count:
        max_count = count

print(max_count)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
from collections import Counter

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    c = Counter(A)
    ans = 0
    for i in range(min(A)+1, max(A)):
        ans = max(ans, c[i-1]+c[i]+c[i+1])
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Solution code:
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
import collections
N = int(input())
A = list(map(int,input().split()))
Min = min(A)
Max = max(A)
d = {i:0 for i in range(Min,Max+1)}
for ii in A:
    d[ii] += 1
print(d)
s = [0] * (Max-Min+1)
n = len(s)
s[0] = d[Min]
for k in range(1,n):
    s[k] = s[k-1] + d[Min+k]
print(s)
ss = 0
if n <= 3:
    ss = s[n-1]
    print(ss)
else:
    mmax = s[2]
    for i in range(3,n):
        mmm = s[i] - s[i-3]
        mmax = max(mmm,mmax)
    print(mmax)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = Counter(a)
count = 1
for i in range(min(a)+1, max(a)):
    count = max(count, b.get(i-1,0)+b.get(i, 0)+b.get(i+1, 0))
print(count)

Submission status: Wrong Answer

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

ans = 0
for i in range(min(A), max(A)+1):
    ans = A.count(i-1) + A.count(i) + A.count(i+1)

print(ans)

Submission status: Wrong Answer

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

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

temp = {}
for i in a_:
    temp[i] = a_.count(i)

temp3 = []
for i in a_:
    if i in temp:
        a1 = temp[i]
    else :
        a1 = 0

    if i+1 in temp:
        a2 = temp[i+1]
    else :
        a2 = 0

    if i-1 in temp:
        a3 = temp[i-1]
    else :
        a3 = 0
        
    temp3.append(a1+a2+a3)
 
print(max(temp3))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
p = [0 for i in range(max(a)+2)]

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

print(max(p))

Submission status: Wrong Answer

Solution code:
n, *A = map(int, open(0).read().split())
B = [0] * (max(A) + 1)

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

for a in A:
  B[a] += 1
ans = 0
for b0, b1, b2 in zip(B, B[1:], B[2:]):
  ans = max(ans, b0 + b1 + b2)
print(ans)

Submission status: Wrong Answer

Solution code:
n, *A = map(int, open(0).read().split())
B = [0] * (max(A) + 1)

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

for a in A:
  B[a] += 1
ans = 0
for b0, b1, b2 in zip(B, B[1:], B[2:]):
  ans = max(ans, b0 + b1 + b2)
print(ans)

Submission status: Wrong Answer

Solution code:
n, *A = map(int, open(0).read().split())
B = [0] * (max(A) + 1)

for a in A:
  B[a] += 1
ans = 0
for b0, b1, b2 in zip(B, B[1:], B[2:]):
  ans = max(ans, b0 + b1 + b2)
print(ans)