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()))
count_dict = collections.Counter(A)
d = []
for k,v in count_dict.items():
	d.append([k,v])
d.sort(key = lambda d : -d[1])
f = []
for i in range(len(d)):
	if d[i][1] == d[0][1]:
		for j in range(3):
			f.append(d[i][0]+j-1)
	else:
		break
f = list(set(f))
ans = 0
for i in f:
	count = 0
	for j in range(N):
		if A[j] == i or A[j]+1 == i or A[j]-1 == i:
			count += 1
		ans = max(ans,count)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
count_dict = collections.Counter(A)
d = []
for k,v in count_dict.items():
	d.append([k,v])
d.sort(key = lambda d : -d[1])
f = []
for i in range(len(d)):
	if d[i][1] == d[0][1]:
		for j in range(3):
			f.append(d[i][0]+j-1)
	else:
		break
f = set(f)
ans = 0
for i in f:
	count = 0
	for j in range(N):
		if A[j] == i or A[j]+1 == i or A[j]-1 == i:
			count += 1
		ans = max(ans,count)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
count_dict = collections.Counter(A)
d = []
for k,v in count_dict.items():
	d.append(k)
	d.append(k-1)
	d.append(k+1)

d = list(set(d))
print(d)
ans = 0
for i in d:
	count = 0
	for j in range(N):
		if A[j] == i or A[j]+1 == i or A[j]-1 == i:
			count += 1
		ans = max(ans,count)
print(ans)

Submission status: Wrong Answer

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

numCount = [0 for _ in range(10**5 + 1)]

for a in A:
    numCount[a] += 1

ans = 0
for i in range(1, 10**5 - 2):
    if ans < sum(numCount[i: i + 3]):
        ans = sum(numCount[i: i + 3])

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    x, t = LI()
    print(max(0, x-t))
    return

#B
def B():
    s = S()
    print("".join(s[::2]))
    return

#C
def C():
    II()
    a = LI()
    lis = [0] * (max(a) + 2)
    for ai in a:
        lis[ai - 1] += 1
        lis[ai] += 1
        lis[ai + 1] += 1
    print(max(lis))
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Wrong Answer

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

a=sorted(a)
a.append(a[-1]+1)
arr=[]
tmp=a[0]
cnt=0
for i in range(N+1):
    if a[i]==tmp:
        cnt+=1
    elif a[i]==tmp+1:
        arr.append(cnt)
        tmp=a[i]
        cnt=1
    else:
        arr.append(cnt)
        arr.append(0)
        tmp=a[i]
        cnt=1
num=0
if len(arr)>=3:
    for i in range(len(arr)-2):
        num=max(num,sum(arr[i:i+3]))
else:
    num=sum(arr)
print(num)

Submission status: Wrong Answer

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

a_sorted = sorted(a)
a_v = list(Counter(a_sorted).values())
a_k = list(Counter(a_sorted).keys())
count_max = a_v[0]
for i in range(1, len(a_v) - 1):
    count = 0
    if a_k[i] - a_k[i - 1] == 1: 
        count += a_v[i - 1]
    if a_k[i + 1] - a_k[i] == 1:
        count += a_v[i + 1]
    count += a_v[i]
    if count > count_max:
        count_max = count
print(count_max)

Submission status: Wrong Answer

Solution code:
# ABC 72, C - together
from collections import Counter

n = int(input())
A = [int(el) for el in input().split(' ')]

max_count = 0
for x in range(min(A)+1, max(A)):
    count = 0
    for i in range(len(A)):
        if A[i] == x or A[i] - 1 == x or A[i] + 1 == x:
            count += 1

    if count > max_count:
        max_count = count
print(max_count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

D = defaultdict(lambda: 0)
for a in A:
    D[a] += 1

M = set()
highest = max(D.values())
for k, v in D.items():
    if v == highest:
        M.add(k)

ans = 0
for m in M:
    ans = max(
        ans,
        D[m - 2] + D[m - 1] + D[m],
        D[m - 1] + D[m] + D[m + 1],
        D[m] + D[m + 1] + D[m + 2],
    )
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

D = defaultdict(lambda: 0)
for a in A:
    D[a] += 1

M = set()
highest = max(D.values())
for k, v in D.items():
    if v == highest:
        M.add(k)

ans = 0
for m in M:
    ans = max(ans, D[m - 1] + D[m] + D[m + 1])
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
saidai=0
for i in range(N):
  cnt=0
  if i in a or i-1 in a or i+1 in a:
    cnt+=a.count(i-1)
    cnt+=a.count(i)
    cnt+=a.count(i+1)
    if saidai<cnt:
      saidai=cnt
print(saidai)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
saidai=0
for i in range(max(a)):
  cnt=0
  cnt+=a.count(i-1)
  cnt+=a.count(i)
  cnt+=a.count(i+1)
  if saidai<cnt:
    saidai=cnt
print(saidai)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
max_count = 0
count = 0
i = 0
x_before = 0
while i < N:
    x = a[i]
    j = i
    if x_before != x:
        while j < len(a):
            if x == a[j] or x+1 == a[j] or x+2 == a[j]:
                count += 1
                j += 1
            else:
                break
        if max_count < count:
            max_count = count
    x_before = x
    count = 0
    i += 1
print(max_count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = [int(zz) for zz in input().split()]
b = Counter(A)
p = list(set(A))
ans = 0
for i in range(len(p)-2):
    q = b[p[i]]+b[p[i+1]]+b[p[i+2]]
    if ans < q:
        ans = q

if N == 2:
    if A[0]-1 <= A[1] <= A[0]+1:
        ans = 2
    else:
        ans = 1
elif N == 1:
        ans = 1
print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
	n=int(input())
	a=list(map(int,input().split()))
	l=min(a)+1
	g=max(a)
	if n==1:
		ans=1
	else:
		ans=0
		for i in list(set(a)):
			ans=max(ans,a.count(i))
		for i in range(l,g):
			ans=max(ans,a.count(i-1)+a.count(i)+a.count(i+1))
	print(ans)

resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
	n=int(input())
	a=list(map(int,input().split()))
	l=min(a)+1
	g=max(a)
	if n==1:
		ans=1
	else:
		ans=0
		
		for i in range(l,g):
			ans=max(ans,a.count(i-1)+a.count(i)+a.count(i+1))
	print(ans)
resolve()

Submission status: Wrong Answer

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


main()

Submission status: Wrong Answer

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


main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = [0] * (10 ** 5)
    for a in A:
        C[a - 1] += 1
    ans = 0
    for i in range(len(C) - 2):
        ans = max(ans, C[i] + C[i + 1] + C[i + 2])
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = [0] * (10 ** 5)
    for a in A:
        C[a - 1] += 1
    ans = 0
    for i in range(len(C) - 3):
        ans = max(ans, C[i] + C[i + 1] + C[i + 2])
    print(ans)


main()

Submission status: Wrong Answer

Solution code:
import bisect
n=int(input())
al=list(map(int,input().split()))
al.sort
sa=set(al)
ans=0
for a in sa:
    ans=max(ans,bisect.bisect_right(al,a+1)-bisect.bisect_left(al,a-1))
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:
N = int(input())
A = list(map(int, input().split()))

all_data = list(set(A))

num = 0

for i in all_data:
  tmp = all_data.count(i) + all_data.count(i+1) + all_data.count(i-1)
  num = max(num, tmp)
  
print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

a.sort()

#print (a)

a = [-2] + a

lst = []
count = 1
for i in range(1,N+1):
    if a[i] == a[i-1]:
        count += 1
    else:
        lst += [[a[i], count]]
        count = 1

# print (lst)

ans = 0
lst += [[-10,0], [-20,0]]
# print (lst)
for i in range(0, len(lst)-2):
    count = lst[i][1]
    if lst[i][0] + 1 == lst[i+1][0]:
        count += lst[i+1][1]
        if lst[i][0] +2 == lst[i+2][0]:
            count += lst[i+2][1]
    ans = max(ans, count)

print (ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

a.sort()

#print (a)

a = [-2] + a

lst = []
count = 1
for i in range(1,N+1):
    if a[i] == a[i-1]:
        count += 1
    else:
        lst += [[a[i], count]]
        count = 1

# print (lst)

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

print (ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

a.sort()

#print (a)

a = [-2] + a

lst = []
count = 1
for i in range(1,N+1):
    if a[i] == a[i-1]:
        count += 1
    else:
        lst += [[a[i], count]]
        count = 1

# print (lst)

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

print (ans)

Submission status: Wrong Answer

Solution code:
import collections as cl
n = int(input())
a = [int(x) for x in input().split()]

plus = [x+1 for x in a]
minus = [x-1 for x in a]
mix = plus  + minus + a #インクリメントしたものデクリメントしたものそのままにしたものを1つの配列に格納
res = cl.Counter(mix) #各要素の個数を数え上げてその最大値となる最初の値を出力する
print(res[res[0]])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import *

n = int(input())
a = sorted(map(int, input().split()))
freq = Counter(a).most_common()

ans = 0
for i in range(2,len(freq)):
    three = freq[i][1]

    for j in freq[i-2:i]:
        if j[0] == freq[i][0] - 2 or freq[i][0] - 1:
            three += j[1]

    ans = max(ans, three)

print(ans if n > 1 else 1)

Submission status: Wrong Answer

Solution code:
from collections import *

n = int(input())
a = sorted(map(int, input().split()))
freq = Counter(a).most_common()

ans = 0
for i in range(2,len(freq)):
    three = freq[i][1]
    
    for j in freq[i-2:i]:
        if j[0] == freq[i][0] - 1 or freq[i][0] + 1:
            three += j[1]
            
    ans = max(ans, three)

print(ans if n > 1 else 1)

Submission status: Wrong Answer

Solution code:
from collections import *

n = int(input())
a = sorted(map(int, input().split()))
freq = Counter(a).most_common()

ans = 0
for i in range(2,len(freq)):
    three = freq[i-2][1] + freq[i-1][1] + freq[i][1]

    ans = max(ans, three)

print(ans if n > 1 else 1)

Submission status: Wrong Answer

Solution code:
from collections import *

n = int(input())
a = sorted(map(int, input().split()))
freq = Counter(a).most_common()

ans = 0
for i in range(2,len(freq)):
    three = freq[i-2][1] + freq[i-1][1] + freq[i][1]

    ans = max(ans, three)

print(ans)

Submission status: Wrong Answer

Solution code:

n = int(input())
num_list = [ int(v) for v in input().split() ]

num_list2 = [0 for i in range(max(num_list)+1)]
num_list3 = [0 for i in range(max(num_list)+1)]
for i in range(n):
	num_list2[num_list[i]] += 1


for i in range(1,max(num_list)):
	num_list3[i] = num_list2[i-1] + num_list2[i] + num_list2[i+1]
print(max(num_list3))

Submission status: Wrong Answer

Solution code:
from collections import Counter

N, *a = map(int, open(0).read().split())
c = sorted(Counter(a).most_common())
ans = 0 if len(c) > 2 else len(c)
for i in range(len(c) - 2):
    x = c[i]
    y = c[i + 1]
    z = c[i + 2]
    
    cnt = y[1]
    cnt += x[1] if x[0] + 1 == y[0] else 0
    cnt += z[1] if z[0] - 1 == y[0] else 0
    ans = max(ans, cnt)
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N, *a = map(int, open(0).read().split())
c = sorted(Counter(a).most_common())
ans = len(c)
for i in range(len(c) - 2):
    x = c[i]
    y = c[i + 1]
    z = c[i + 2]
    
    cnt = y[1]
    cnt += x[1] if x[0] + 1 == y[0] else 0
    cnt += z[1] if z[0] - 1 == y[0] else 0
    ans = max(ans, cnt)
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N, *a = map(int, open(0).read().split())
c = sorted(Counter(a).most_common())
ans = 0
for i in range(len(c) - 2):
    x = c[i]
    y = c[i + 1]
    z = c[i + 2]
    
    cnt = y[1]
    cnt += x[1] if x[0] + 1 == y[0] else 0
    cnt += z[1] if z[0] - 1 == y[0] else 0
    ans = max(ans, cnt)
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N, *a = map(int, open(0).read().split())
c = [y for _, y in sorted(Counter(a).most_common())]
if len(c) > 2:
	print(max(sum(c[i:i + 3]) for i in range(len(c) - 2)))
else:
    print(len(c))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
Xlow = A.count(0)
Xmid = A.count(1)
Xhi = A.count(2)
X = 0
for i in range(3, max(A)+2):
	X = max(X, Xlow + Xmid + Xhi)
	Xlow, Xmid = Xmid, Xhi
	Xhi = A.count(i)
print(X)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = list(map(int,input().split()))
#print(max(lst),min(lst))
count = 0
ans = 0
for j in range(min(lst), max(lst)):
  count = 0
  for i in range(N):
    if j == lst[i] or j+1 == lst[i] or j-1 == lst[i]:
      count += 1
  #print(count, ans)
  if ans < count:
    ans = count

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A = sorted(a)
cnt = 1
cnt_list = []
X = A[0]
for i in range(len(A)-1):
    if A[i+1] - X <= 2:
        cnt += 1
    else:
        cnt_list.append(cnt)
        cnt = 1
        X = A[i+1]
else:
    cnt_list.append(cnt)

print(max(cnt_list))

Submission status: Wrong Answer

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

try:
    imode = statistics.mode(a)
except statistics.StatisticsError:
    imode = statistics.median_low(a)
    
num_ofmode = a.count(imode)

print(max(a.count(imode-2) + a.count(imode-1) + num_ofmode, a.count(imode-1) + num_ofmode + a.count(imode+1), num_ofmode + a.count(imode+1) + a.count(imode+2)))

Submission status: Wrong Answer

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

try:
    imode = statistics.mode(a)
except statistics.StatisticsError:
    imode = statistics.median_low(a)
    
num_ofmode = a.count(imode)

print(imode)
print(max(a.count(imode-2) + a.count(imode-1) + num_ofmode, a.count(imode-1) + num_ofmode + a.count(imode+1), num_ofmode + a.count(imode+1) + a.count(imode+2)))

Submission status: Wrong Answer

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

N = int(input())
L = [int(v) for v in input().split()]

t = [0] * N
for i in range(N):
    t[i] = i - L[i] + 1

index = 0
c = 0
while index < N:
    if index + 1 < N and t[index] == 0 and t[index + 1] == 0:
        t[index] = -1
        t[index + 1] = 1
        c += 1
        index += 2
    elif index + 1 < N and t[index] == 0 and t[index + 1] < 0:
        c += 1
        t[index] = t[index + 1] - 1
        t[index + 1] = 1
        index += 2
    elif index - 1 >= 0 and t[index] == 0 and t[index - 1] > 0:
        c += 1
        t[index] = t[index - 1] + 1
        t[index - 1] = -1
        index += 2
    else:
        index += 1

print(c)

Submission status: Wrong Answer

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

N = int(input())
L = [int(v) for v in input().split()]
m = max(L)
NL = [0] * (m + 1)

for i in range(N):
    v = L[i]
    NL[v] += 1

nz = [i for i in range(len(NL)) if NL[i] != 0]
if len(nz) == 1:
    print(NL[nz[0]])
elif len(nz) == 2:
    if abs(nz[0] - nz[1]) <= 2:
        print(NL[nz[0]] + NL[nz[1]])
    else:
        print(max(NL[nz[0]], NL[nz[1]]))
else:
    t = NL[0] + NL[1] + NL[2]
    ans = max(1, t)
    for i in range(1, len(NL) - 2):
        t = t - NL[i] + NL[2]
        ans = max(ans, t)
            
    print(ans)

Submission status: Wrong Answer

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

N = int(input())
L = [int(v) for v in input().split()]
m = max(L)
NL = [0] * (m + 1)

for i in range(N):
    v = L[i]
    NL[v] += 1

nz = [i for i in range(len(NL)) if NL[i] != 0]
if len(nz) == 1:
    print(NL[nz[0]])
elif len(nz) == 2:
    if abs(nz[0] - nz[1]) <= 2:
        print(NL[nz[0]] + NL[nz[1]])
    else:
        print(max(NL[nz[0]], NL[nz[1]]))
else:
    t = NL[0] + NL[1] + NL[2]
    ans = t
    for i in range(1, len(NL) - 2):
        t = t - NL[i] + NL[2]
        ans = max(ans, t)
            
    print(ans)

Submission status: Wrong Answer

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

MI, MA = min(A),max(A)
num = MA - MI + 1
L = [0] * num

if N <= 3:
    print(N)
    exit()

for ctr in A:
    L[ctr-MI] += 1

ans,tmp = sum(L[0:3]),sum(L[0:3])
for j in range(num-3):
    tmp = tmp - L[j] + L[j+3]
    ans = max(ans,tmp)

print(ans)

Submission status: Wrong Answer

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

MI, MA = min(A),max(A)
num = MA - MI + 1
L = [0] * num

if N <= 3:
    print(N)
    exit()

for i in range(num):
    L[i] = A.count(MI+i)

ans,tmp = sum(L[0:3]),sum(L[0:3])
for j in range(num-3):
    tmp = tmp - L[j] + L[j+3]
    ans = max(ans,tmp)

print(ans)

Submission status: Wrong Answer

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

cnt = []
for i in range(min(A),max(A)+1):
    cnt.append(A.count(i))

ans = 1
for i in range(1, len(cnt)-1):
    if ans < cnt[i-1] + cnt[i] + cnt[i+1]:
        ans = cnt[i-1] + cnt[i] + cnt[i+1]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
a_min = min(a)
a_max = max(a)
if a_max - a_min <= 2:
  print(N)
else:
  b = [0] * (a_max-a_min+1)
  for i in range(N):
    b[a[i]-a_min] += 1
  #print(b)
  s = b[0] + b[1] + b[2]
  s_max = s
  for i in range(len(b)-3):
    s = b[3+i]-b[i]
    if s > s_max:
      s_max = s
  print(s_max)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
a_min = min(a)
a_max = max(a)
if a_max - a_min <= 2:
  print(N)
else:
  b = []
  for i in range(a_max-a_min+1):
    b.append(a.count(a_min+i))
  #print(b)
  s = b[0] + b[1] + b[2]
  s_max = s
  for i in range(len(b)-3):
    s = b[3+i]-b[0]
    if s > s_max:
      s_max = s
  print(s_max)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

d = {}

for i in a:
  for j in range(i - 1, i + 2): #aの値の両隣まで
    d[j] = d.get(j, 0) + 1#getは第一引数で指定したキーがなかったら第二引数で指定した値を戻す
    
    
max(d.values())

Submission status: Wrong Answer

Solution code:
n = int(input())

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

d = {}

for i in a:
  for j in range(i-1, i+2): 
    d[j] = d.get(j,0) + 1 
    
    
max(d.values())

Submission status: Wrong Answer

Solution code:
n = int(input())

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

d = {}

for i in a:
  for j in range(i-1, i+2): 
    d[j] = d.get(j,0) + 1
max(d.values())

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math

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

a.sort()

counts = {}
for i in range(N):
    if a[i] in counts.keys():
        counts[a[i]] += 1
    else:
        counts[a[i]] = 1

counts_list = []
tmp = 0
for num in range(max(a)+1):
    try:
        tmp += counts[num]
        # counts_list.append(tmp)
    except:
        pass

    counts_list.append(tmp)
# print(counts_list)
ans = -1
for i in range(len(counts_list)-3):
    ans = max(ans,counts_list[i+3]-counts_list[i])
    # print(ans)

print(ans)

Submission status: Wrong Answer

Solution code:

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

ave = sum(a) // n

count_max = 0
for l in [ave-1, ave, ave+1]:
    if ave-1 < 0:
        continue
    else:
        count=0
        for k in a:
            if l-1 <= k <= l+1:
                count += 1 
    count_max = max(count_max, count)

print(count_max)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(num) for num in input().split()]

ave = sum(a) // n

count_max = 0
for l in [ave-2, ave-1, ave, ave+1, ave+2]:
    count=0
    for k in a:
        if l-1 <= k <= l+1:
            count += 1 
    count_max = max(count_max, count)

print(count_max)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(num) for num in input().split()]

ave = sum(a) // n

count_max = 0
for l in [ave-1, ave, ave+1]:
    count=0
    for k in a:
        if l-1 <= k <= l+1:
            count += 1 
    count_max = max(count_max, count)

print(count_max)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0]*100000
AA = list(map(int, input().split()))
minA = 100000
maxA = 0
for a in AA:
  A[a] += 1
  minA = min(minA, a)
  maxA = max(maxA, a)
ans = 0
for i in range(minA-1, min(maxA+1, N-2)):
  ans = max(ans, A[i]+A[i+1]+A[i+2])
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 range(N):
	num[a[i]] += 1


max_a = 0	

ans = 0
	
for i in range(len(num) - 2):
	temp_max = num[i] + num[i+1] + num[i+2]
	if temp_max > max_a:
		max_a = temp_max
	
print(max_a)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
k = a[0]
cnt = 0
ans = 1
for i in range(n):
    if a[i]<=k+2:
        cnt += 1
    else:
        ans = max(ans,cnt)
        cnt = 1
        k = a[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
k = a[0]
cnt = 0
ans = 0
for i in range(n):
    if a[i]<=k+2:
        cnt += 1
    else:
        ans = max(ans,cnt)
        cnt = 1
        k = a[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
def binarysearch1(x):
  ng=-1
  ok=n
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if a[mid]>=x+2:
      ok=mid
    else:
      ng=mid
  return ok
def binarysearch2(x):
  ok=-1
  ng=n
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if a[mid]>x-1:
      ng=mid
    else:
      ok=mid
  return ok
ans=0
for i in range(-1,10**5+2):
  ans=max(ans,binarysearch1(i)-binarysearch2(i))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
def binarysearch1(x):
  ok=-1
  ng=n
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if a[mid]>=x+2:
      ok=mid
    else:
      ng=mid
  return ok
def binarysearch2(x):
  ok=-1
  ng=n
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if a[mid]>=x-1:
      ok=mid
    else:
      ng=mid
  return ok
ans=0
for i in range(-1,10**5+2):
  ans=max(ans,binarysearch1(i)-binarysearch2(i))
print(ans)

Submission status: Wrong Answer

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

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

d = a
a.sort()
b = list(range(0,a[-1]))
a = a + b
a.sort()


def arraycount(arr):
    arr_target = [[]]
    cnt = 1
    for i in range(1,len(arr)):
        if arr[i] == arr[i-1]:
            cnt += 1
        else:
            arr_target.append([arr[i-1],cnt])
            cnt = 1
    arr_target.append([arr[len(arr)-1],cnt])
    del arr_target[0]
    return arr_target

a = arraycount(a)
ans = 0

for i in range(1,len(a)-1):
    ans = max(ans,a[i-1][1]+a[i][1]+a[i+1][1]-3)

if len(d) == 2:
    if abs(d[1] - d[0]) <= 1:
        ans = 2
    else:
        ans = 1

if len(d) == 1:
    ans = 1

print(ans)

Submission status: Wrong Answer

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

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

d = a
a.sort()
b = list(range(0,a[-1]))
a = a + b
a.sort()


def arraycount(arr):
    arr_target = [[]]
    cnt = 1
    for i in range(1,len(arr)):
        if arr[i] == arr[i-1]:
            cnt += 1
        else:
            arr_target.append([arr[i-1],cnt])
            cnt = 1
    arr_target.append([arr[len(arr)-1],cnt])
    del arr_target[0]
    return arr_target

a = arraycount(a)
ans = 0

for i in range(1,len(a)-1):
    ans = max(ans,a[i-1][1]+a[i][1]+a[i+1][1]-3)

if len(d) == 2:
    if abs(a[0][0] - a[1][0]) <= 1:
        ans = 2
    else:
        ans = 1

if len(d) == 1:
    ans = 1

print(ans)

Submission status: Wrong Answer

Solution code:

# -*- coding: utf-8 -*-

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

d = a
a.sort()
b = list(range(0,a[-1]))
a = a + b
a.sort()


def arraycount(arr):
    arr_target = [[]]
    cnt = 1
    for i in range(1,len(arr)):
        if arr[i] == arr[i-1]:
            cnt += 1
        else:
            arr_target.append([arr[i-1],cnt])
            cnt = 1
    arr_target.append([arr[len(arr)-1],cnt])
    del arr_target[0]
    return arr_target

a = arraycount(a)
ans = 0

for i in range(1,len(a)-1):
    ans = max(ans,a[i-1][1]+a[i][1]+a[i+1][1]-3)

if len(d) == 2:
    if abs(a[0][0] - a[0][1]) <= 1:
        ans = 2
    else:
        ans = 1

if len(d) == 1:
    ans = 1

print(ans)

Submission status: Wrong Answer

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

count = [0] * 10**5

for e in a :
    if e != 1 :
        count[e - 1] += 1
    count[e] += 1
    if e != 10**5 - 1 :
        count[e + 1] += 1

print(max(count))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
values=[]
for i in range(min(a), max(a)+1):
    values.append(a.count(i))
    
max_value=0
for i in range(len(values)-2):
    max_value = max(max_value, values[i]+values[i+1]+values[i+2])
print(max_value)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
a = list(map(int, input().split()))
values=[]
for i in range(min(a), max(a)):
    values.append(a.count(i))
    
max_value=0
for i in range(len(values)-2):
    max_value = max(max_value, values[i]+values[i+1]+values[i+2])
print(max_value)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

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

b = []

for i in range(n):
    b.append(a[i])
    b.reverse()
print(" ".join(map(str,b)))

Submission status: Wrong Answer

Solution code:
#ABC072C
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=[0]*(max(A)+1)
back=A[0]
count=0
for a in A:
	if back==a:
		count+=1
	else:
		B[back]=count
		back=a
		count=1
B[back]=count
num=0
for n in range(max(A)-1):
	if num<sum(B[n:n+3]):
		num=sum(B[n:n+3])
print(num)