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

list = [0]*99999
for i in range(n):
  list[a[i]-1] += 1

ans = 0
for i in range(1,99998):
  sum = list[i-1]+list[i]+list[i+1]
  ans = max(sum, ans)
  
print(ans)

Submission status: Wrong Answer

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

list = [0]*100000
for i in range(n):
  list[a[i]-1] += 1

ans = 0
for i in range(1,99999):
  sum = list[i-1]+list[i]+list[i+1]
  ans = max(sum, ans)
  
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
A.sort()
a=0
b=0
c=1

for i in range(N-1):
  if A[i] == A[i+1]:
    a += 1
    b += 1
    c += 1
  else:
    if ans < a:
      ans = a
    a = b
    a += 1
    b = c
    b += 1
    c = 1
if ans < a:
      ans = a
if ans < b:
      ans = b
if ans < c:
      ans = c
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
A.sort()
a=0
b=0
c=1

for i in range(N-1):
  if A[i] == A[i+1]:
    a += 1
    b += 1
    c += 1
  else:
    if ans < a:
      ans = a
    a = b
    a += 1
    b = c
    b += 1
    c = 1
    
print(ans)

Submission status: Wrong Answer

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

dp=[0 for n in range(max(a)+1)]
for n in range(N):
    dp[a[n]]+=1

ans=0
for n in range(1,len(dp)-1):
    ans=max(ans,dp[n-1]+dp[n]+dp[n+1])

print(ans)

Submission status: Wrong Answer

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

dp=[0 for n in range(max(a)+1)]
for n in range(N):
    dp[a[n]]+=1

ans=0
for n in range(1,len(dp)-2):
    ans=max(ans,dp[n-1]+dp[n]+dp[n+1])

print(ans)

Submission status: Wrong Answer

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

dp=[0 for n in range(max(a)+1)]
for n in range(N):
    dp[a[n]]+=1

ans=0
for n in range(len(dp)-1):
    if n==0:
        ans=max(ans,dp[0]+dp[1])
    elif n==N-1:
        ans=max(ans,dp[N-2]+dp[N-1])
    else:
        ans=max(ans,dp[n-1]+dp[n]+dp[n+1])

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

n = int(input())

a_list = list(map(int, input().split()))
sort_a_list = sorted(a_list)

l = 0
r = 0
ans = 0
max_ans = 0
sabun = 0
#print(sort_a_list)

while (r < n-1):
    #print(l,r)
    #print(ans)
    #print(sabun)
    if (sabun <= 2):
        if sort_a_list[r] - sort_a_list[l] > 2:
            l += 1
            sabun = sort_a_list[r] - sort_a_list[l]
            ans -= 1
            continue
        r += 1
        sabun = sort_a_list[r] - sort_a_list[l]
        ans += 1
        max_ans = max(max_ans,ans)
    else:
        l += 1
        sabun = sort_a_list[r-1] - sort_a_list[l-1]
        ans -= 1
print(max_ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

n = int(input())

a_list = list(map(int, input().split()))
sort_a_list = sorted(a_list)

l = 0
r = 0
ans = 0
max_ans = 0
sabun = 0

while (r < n):
    if (sabun <= 2):
        r += 1
        sabun = sort_a_list[r-1] - sort_a_list[l]
        if sabun <= 2:
            ans += 1
            max_ans = max(max_ans,ans)
    else:
        l += 1
        sabun = sort_a_list[r-1] - sort_a_list[l-1]
        ans -= 1
print(max_ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

t = [0] * (max(a) + 1)
for v in a:
    t[v] += 1

ans = 0
for i in range(0, max(a) - 1):
    ans = max(ans, t[i] + t[i+1] + t[i+2])

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

t = [0] * (max(a) + 1)
for v in a:
    t[v] += 1

ans = 0
for i in range(1, max(a) - 1):
    ans = max(ans, t[i] + t[i+1] + t[i+2])

print(ans)

Submission status: Wrong Answer

Solution code:

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

cnt=[0]*(a[-1]+2)
for i in range(N):
    cnt[a[i]]+=1

out=0
for i in range(1,a[-1]+1):
    dam = cnt[i-1] + cnt[i] + cnt[i+1]
    out=max(out,dam)
print(out)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

print(cnt.index(max(cnt)))

Submission status: Wrong Answer

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

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

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

print(max(cnt))

Submission status: Wrong Answer

Solution code:
N = int(input())
a_s = list(map(int,input().split()))
cnt = [0] * (max(a_s)+1)
for a in a_s:
    cnt[a] += 1
answer = 1
for i,c in enumerate(cnt):
    if i < 1:
        continue
    if i < 2:
        continue
    answer = max(answer, sum(cnt[i-2:i+1]))
print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
a_s = list(map(int,input().split()))
cnt = [0] * (max(a_s)+1)
for a in a_s:
    cnt[a] += 1
answer = 1
for i,c in enumerate(cnt):
    if i < 1:
        continue
    if i < 2:
        answer = max(answer, sum(cnt[i-1:i+1]))
        continue
    answer = max(answer, sum(cnt[i-2:i+1]))
print(answer)

Submission status: Wrong Answer

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

ans = 0
for X in range(1, N+2):
  cnt = 0
  for i in range(N):
    if X - 1 <= A[i] <= X + 1:
      cnt += 1
  ans = max(ans, cnt)
  
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
M = max(L)
ans = 0

for i in range(1,M):
  cnt = 0
  for j in range(len(L)):
    if i == L[j]-1 or i == L[j] or i == L[j]+1:
      cnt += 1
      if cnt > ans: ans = cnt
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = map(int, input().split())
    a_cnt = collections.Counter(a)
    
    x = a_cnt.most_common()[0][0]
    ans1 = ans2 = ans3 = 0
    ans1 = a_cnt[x-2] + a_cnt[x-1] + a_cnt[x]
    ans2 = a_cnt[x-1] + a_cnt[x] + a_cnt[x+1]
    ans3 = a_cnt[x] + a_cnt[x+1] + a_cnt[x+2]
    
    print(max(ans1, ans2, ans3))
    
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = map(int, input().split())
    a_cnt = collections.Counter(a)
    
    x = a_cnt.most_common()[0][0]
    ans1 = ans2 = ans3 = 0
    for key, count in a_cnt.most_common():
        if x-2 <= key <= x:
            ans1 += count
        if x-1 <= key <= x+1:
            ans2 += count
        if x <= key <= x+2:
            ans3 += count
    
    print(max(ans1, ans2, ans3))
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

a_max = max(A)
a_min = min(A)
dummy = -float("inf")

for x in range(a_min+1, a_max):
    cnt = 0
    for i in range(len(A)):
        if A[i] -1 <= x and A[i] + 1 >= x:
            cnt += 1
            if dummy < cnt:
                dummy = cnt
print(dummy)

Submission status: Wrong Answer

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

a_max = max(A)
a_min = min(A)
dummy = -float("inf")

for x in range(a_min+1, a_max-1):
    cnt = 0
    for i in range(len(A)):
        if A[i] -1 <= x and A[i] + 1 >= x:
            cnt += 1
            if dummy < cnt:
                dummy = cnt
print(dummy)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_lst = list(map(int, input().split()))
max_a = max(a_lst)
count_lst = [0] * (max_a + 2)

for i in range(n):
    a = a_lst[i]
    index1 = a - 1
    index2 = a
    index3 = a + 1

    count_lst[index1] += 1
    count_lst[index2] += 1
    count_lst[index3] += 1

maximum = max(count_lst)
print(maximum)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
s = sorted(a)
k = s[(n//2)-1]
ans = 0
for i in s:
  if i == k or i == k-1 or i == k+1:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, *A = map(int, open(0).read().split())

C = {}
for a in A:
    if a in C.keys():
        C[a] += 1
    else:
        C[a] = 1
B = list(C.items())
B.sort(key=lambda x: x[0])

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

Submission status: Wrong Answer

Solution code:
N, *A = map(int, open(0).read().split())

C = {}
for a in A:
    if a in C.keys():
        C[a] += 1
    else:
        C[a] = 1
B = list(C.items())
B.sort(key=lambda x: x[0])

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

Submission status: Wrong Answer

Solution code:
N, *A = map(int, open(0).read().split())

C = {}
for a in A:
    if a in C.keys():
        C[a] += 1
    else:
        C[a] = 1
B = list(C.items())
B.sort(key=lambda x: x[0])

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

Submission status: Wrong Answer

Solution code:
N, *A = map(int, open(0).read().split())

A.sort()
B = {}
for a in A:
    if a in B.keys():
        B[a] += 1
    else:
        B[a] = 1

C = list(B.keys())
ans = 1
for i in range(1, len(C)-1):
    count = 1
    if C[i-1] == C[i]-1:
        count += B[C[i-1]]
    if C[i+1] == C[i]+1:
        count += B[C[i+1]]
    ans = max(ans, count)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections

N, *A = map(int, open(0).read().split())

if N == 1:
    print(1)
    sys.exit()

B = collections.Counter(A).most_common()
B.sort(key=lambda x: x[0])

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
_, counts = zip(*C.most_common())

cnt = 0
for c in counts[:3]:
    cnt += c
print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
a=lnii()

c=Counter(a)
a_max=max(a)

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

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
a=lnii()

c=Counter(a)
a_max=max(a)

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

for i in range(N):
    tmp = a[i]
    memo[tmp-1] += 1
    memo[tmp] += 1
    memo[tmp+1] += 1

ans = max(memo)

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = z()
A = zz()
c = collections.Counter(A)
ans = 0
for x in range(max(A)):
    tmp = c[x]
    try:
        tmp += c[x-1]
    except:
        pass
    try:
        tmp += c[x+1]
    except:
        pass
    ans = max(tmp, ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(x) for x in input().split()]

M = max(a)

C = [0] * (M + 1)

for i in range(N):
    C[a[i]] += 1 

ans = 0

for i in range(1,M):
    wa = C[i - 1] + C[i] + C[i + 1]
    ans = max(ans, wa)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
l = sorted(list(map(int, input().split())) )
c = collections.Counter(l)
L = [0]*(10**5+1)
M = [0]*(10**5+1)
 
for x,y in c.items():
    L[x-1] += y
 
M[0] = L[0]
M[10**5] = L[10**5]
for i in range(1,10**5):
    M[i] = L[i-1] + L[i] + L[i+1]
print(max(M))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
l = sorted(list(map(int, input().split())) )
c = collections.Counter(l)
L = [0]*10**5
M = [0]*10**5

for x,y in c.items():
    L[x-1] += y

M[0] = L[0]
M[10**5-1] = L[10**5-1]
for i in range(1,10**5-1):
    M[i] = L[i-1] + L[i] + L[i+1]
print(max(M))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
A.sort()
C = Counter(A)
ma = max(2, A[-1])
L = [0]*(ma+1)
for i in range(ma+1):
    l = C.get(i)
    if l == None:
        l = 0
    L[i] = l
print(L)
ans = [0]*(ma-1)
ans[0] = L[0]+L[1]+L[2]
for i in range(1, ma-1):
    ans[i] = ans[i-1]-L[i-1]+L[i+2]
# print(ans)
print(max(ans))

Submission status: Wrong Answer

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

print(max(s))

Submission status: Wrong Answer

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

cc=collections.Counter(a)
ll=list(cc.values())
ans=0
if len(ll)<=2:
    ans=sum(ll)
for i in range(1,len(ll)-1):
    tt=ll[i-1]+ll[i]+ll[i+1]
    ans=max(ans,tt)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
# 文字数のカウント
cnt=dict()
for a in A:
    if a in cnt.keys():
        cnt[a]+=1
    else:
      cnt[a]=1

# 頻出数を探す
cnt_sort = sorted(cnt.items(), key=lambda x:x[1], reverse=True)


# 頻出数3つとその±1の数字を候補とする(最大9つ)
candidates=set()
for i in range(min(3,len(cnt))):
    candidates.add(cnt_sort[i][0])
    candidates.add(cnt_sort[i][0]-1)
    candidates.add(cnt_sort[i][0]+1)
# 配列に渡された配列内に，±1で数xに出来る数がいくつあるか判定
def neigh(array, x):
    cnt = 0
    for a in array:
        if a == x:
          cnt+=1
        elif a-1 == x:
          cnt+=1
        elif a+1 == x:
          cnt+=1
    return cnt

res=[]
for c in candidates:
    res.append(neigh(A,c))

print(max(res))

Submission status: Wrong Answer

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

# 文字数のカウント
cnt=dict()
for a in A:
  if a in cnt.keys():
    cnt[a]+=1
  else:
    cnt[a]=1
    
# 頻出数を探す
cnt_sort = sorted(cnt.items(), key=lambda x:x[1])
cnt_sort.reverse()

# 頻出数10つとその±1の数字を候補とする
candidates=set()
for i in range(min(10,len(cnt))):
  candidates.add(cnt_sort[i][0])
  candidates.add(cnt_sort[i][0]-1)
  candidates.add(cnt_sort[i][0]+1)

# 配列に渡された配列内に，±1で数xに出来る数がいくつあるか判定
def neigh(array, x):
  cnt = 0
  for a in array:
    if a == x:
      cnt+=1
    elif a-1 == x:
      cnt+=1
    elif a+1 == x:
      cnt+=1
  return cnt

res=[]
for c in candidates:
  res.append(neigh(A,c))
  
print(max(res))

Submission status: Wrong Answer

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

# 文字数のカウント
cnt=dict()
for a in A:
  if a in cnt.keys():
    cnt[a]+=1
  else:
    cnt[a]=1
    
# 頻出数を探す
cnt_sort = sorted(cnt.items(), key=lambda x:x[1])
cnt_sort.reverse()

# 頻出数5つとその±1の数字を候補とする(最大15個)
candidates=set()
for i in range(min(5,len(cnt))):
  candidates.add(cnt_sort[i][0])
  candidates.add(cnt_sort[i][0]-1)
  candidates.add(cnt_sort[i][0]+1)

# 配列に渡された配列内に，±1で数xに出来る数がいくつあるか判定
def neigh(array, x):
  cnt = 0
  for a in array:
    if a == x:
      cnt+=1
    elif a-1 == x:
      cnt+=1
    elif a+1 == x:
      cnt+=1
  return cnt

res=[]
for c in candidates:
  res.append(neigh(A,c))
  
print(max(res))

Submission status: Wrong Answer

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

# 文字数のカウント
cnt=dict()
for a in A:
  if a in cnt.keys():
    cnt[a]+=1
  else:
    cnt[a]=1
    
# 頻出数を探す
cnt_sort = sorted(cnt.items(), key=lambda x:x[1])
cnt_sort.reverse()

# 頻出数3つとその±1の数字を候補とする(最大9つ)
candidates=set()
for i in range(min(3,len(cnt))):
  candidates.add(cnt_sort[i][0])
  candidates.add(cnt_sort[i][0]-1)
  candidates.add(cnt_sort[i][0]+1)

# 配列に渡された配列内に，±1で数xに出来る数がいくつあるか判定
def neigh(array, x):
  cnt = 0
  for a in array:
    if a == x:
      cnt+=1
    elif a-1 == x:
      cnt+=1
    elif a+1 == x:
      cnt+=1
  return cnt

res=[]
for c in candidates:
  res.append(neigh(A,c))
  
print(max(res))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#
# abc072 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """7
3 1 4 1 5 9 2"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10
0 1 2 3 4 5 6 7 8 9"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """1
99999"""
        output = """1"""
        self.assertIO(input, output)


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

    an = {}
    for a in A:
        an.setdefault(a, 0)
        an[a] += 1

    ans = 1
    for x in range(min(A), max(A)+1):
        t = 0
        for k, v in an.items():
            if x == k-1 or x == k or x == k+1:
                t += v
        ans = max(ans, t)

    print(ans)


if __name__ == "__main__":
    unittest.main()
    # resolve()

Submission status: Wrong Answer

Solution code:
#
# abc072 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """7
3 1 4 1 5 9 2"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10
0 1 2 3 4 5 6 7 8 9"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """1
99999"""
        output = """1"""
        self.assertIO(input, output)


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

    an = {}
    for a in A:
        an.setdefault(a, 0)
        an[a] += 1

    ans = 1
    for x in range(min(A)+1, max(A)):
        t = 0
        for k, v in an.items():
            if x == k-1 or x == k or x == k+1:
                t += v
        ans = max(ans, t)

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Wrong Answer

Solution code:
#
# abc072 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """7
3 1 4 1 5 9 2"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10
0 1 2 3 4 5 6 7 8 9"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """1
99999"""
        output = """1"""
        self.assertIO(input, output)


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

    an = {}
    for a in A:
        an.setdefault(a, 0)
        an[a] += 1

    ans = 1
    for x in range(min(A)+1, max(A)):
        t = 0
        for k, v in an.items():
            if k == x - 1 or k == x or k == x+1:
                t += v
        ans = max(ans, t)

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Wrong Answer

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

print(max(lis))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
ans = 0
tmp = c.most_common()[0][1]
tmp2 = c.most_common(tmp)
for i in range(len(tmp2)):
    tmp3 = tmp2[i][1] + c[tmp2[i][0] + 1] + c[tmp2[i][0] + 2]
    tmp4 = tmp2[i][1] + c[tmp2[i][0] - 1] + c[tmp2[i][0] - 2]
    ans = max(ans,tmp3,tmp4)
print(str(ans))

Submission status: Wrong Answer

Solution code:
import sys

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))


n = ri()
li = rl()
cnt_li = [0]*10**5
ans = 0
for i in range(10**5):
    cnt_li[i] = li.count(i)
for i in range(10**5-1):
    ans = max(ans, cnt_li[max(0, i-1)] + cnt_li[i] + cnt_li[i+1])
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

nums=[0]*(10**5+1)
for i in a:
    nums[i]+=1

ans0=nums[0]+nums[1]+nums[2]
ans=1
for i in range(2,10**5-1):
    ans1=ans0-nums[i-2]+nums[i+1]
    ans=max(ans,ans1)
    ans0=ans1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

max_a=max(a)
min_a=min(a)
a0=a.count(min_a)
a1=a.count(min_a+1)
ans=1
for i in range(min_a+1,max_a):
    a2=a.count(i+1)
    ans=max(ans,(a0+a1+a2))
    a0=a1
    a2=a1
    if i ==max_a-1:
        print(ans)
        sys.exit()

print(N)

Submission status: Wrong Answer

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

max_a=max(a)
min_a=min(a)
a0=a.count(min_a)
a1=a.count(min_a+1)
ans=1
for i in range(min_a+1,max_a):
    a2=a.count(i+1)
    ans=max(ans,(a0+a1+a2))
    a0=a1
    a2=a1

print(ans)

Submission status: Wrong Answer

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

nums = [0]*(10**5+1)
for i in a: nums[i] += 1

t = sum(nums[1:4])
ans = t
for i in range(4,10**5+1):
  t = t - nums[i-3] + nums[i]
  if ans < t: ans = t
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
now = A[0]
start_idx = 0
while now <= A[-1] + 1:
    tmp_max = 0
    flag = True
    for i in range(start_idx, N):
        if flag and now - 1 == A[i]:
            flag = False
            start_idx = i
        if now - 1 <= A[i] <= now + 1:
            tmp_max += 1
        else:
            break
    ans = max(tmp_max, ans)
    now += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
sys.setrecursionlimit(4100000)



if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    max_v = -1
    for i in range(max(A)):
        cnt = 0
        for a in A:
            for d in [-1, 0, 1]:
                if a+d==i:
                    cnt += 1
            max_v = max(cnt, max_v)
    
    print(max_v)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
sys.setrecursionlimit(4100000)

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    
    max_a = max(A)
    cnt = [0]*(max_a+1)
    memo = []
    for a in A:
        for d in [-1, 0, 1]:
            memo.append(a+d)
    ans = list(Counter(memo).values())[0]
    print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
sys.setrecursionlimit(4100000)



if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    
    max_a = max(A)
    maxv = -1
    cnt = [0]*(max_a+1)
    for i in range(max_a):
        for a in A:
            for d in [-1, 0, 1]:
                if a+d==i:
                    cnt[i] += 1
                    break
    
    print(max(cnt))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
sys.setrecursionlimit(4100000)



if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    
    max_a = max(A)
    maxv = -1
    cnt = [0]*(max_a+1)
    for i in range(max_a):
        for a in A:
            for d in [-1, 0, 1]:
                if a+d==i:
                    cnt[i] += 1
    
    print(max(cnt))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt=[0]*(max(A)+2)
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()))
cnt=[0]*N
for i in range(N):
  cnt[i]+=A.count(i)

ans=0
for i in range(1,N-1,1):
  ans=max(ans, sum(cnt[i-1:i+2]))
print(ans)

Submission status: Wrong Answer

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

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)):
  tmp = 0
  for a in A:
    if a-1<=i<=a+1:
      tmp+=1
  ans = max(ans, tmp)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
M = 1

c = collections.Counter(a)

for x in range(max(a)):
	d = c[x] + c[x-1] + c[x+1]
	if d >= M:
		M = d

print(M)

Submission status: Wrong Answer

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

c = collections.Counter(a)

for x in range(max(a)):
	d = c[x] + c[x-1] + c[x+1]
	if d > M:
		M = d

print(M)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
c = [0]*100000
ans = 0
for a in A:
    c[a] += 1

for i in range(1, 9999):
    cnt = c[i-1] + c[i] +c[i+1]
    ans = max(ans, cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def main():
  input = sys.stdin.readline
  maxa=0
  N=int(input())
  L=list(map(int,input().split()))
  c=[0]*100000
  for i in L:
    c[i-1]+=1
  R=tuple(set(L))
  for i in range(1,99999):
    s=c[i]+c[i-1]+c[i+1]
    maxa=max(maxa,s)
  print(maxa)
if __name__ == '__main__':
    main()