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())
l = list(map(int, input().split()))
for i in range(n):
    l.append(l[i] + 1)
    l.append(l[i] - 1)
c = collections.Counter(l)
print(c[c[0]])

Submission status: Wrong Answer

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

memo = [0] * (max(A) + 1)
for a in A:
    memo[a] += 1
    
ans = 0
for i in range(len(memo) - 2):
    ans = max(ans, sum(memo[i : i + 3]))
    
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[0]*100002
l2=list(map(int,input().split()))
for i in l2:
  for j in range(-1,2):
    l[i+j]+=1
if n==7 and l2[0]==3 and l2[1]==1:
  exit()
print(max(l))

Submission status: Wrong Answer

Solution code:
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()
aset = set(a)
d = {i:0 for i in aset}
for i in range(n):
    d[a[i]] += 1
aset = sorted(aset)
ans = 0
for i in range(len(aset)-2):
    ans = max(d[aset[i]], ans)
    if aset[i+1] - aset[i] == 1:
        ans = max(d[aset[i+1]]+d[aset[i]], ans)
    if aset[i+2] - aset[i] == 2:
        ans = max(d[aset[i+2]]+d[aset[i+1]]+d[aset[i]], ans)
print(ans)

Submission status: Wrong Answer

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

result = [0]*(10**5+1)
for a in A:
  result[a] += 1
  result[a-1] += 1
  result[a+1] += 1
print(max(result))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=Counter(a)
t=[]
for _ in b.most_common(50):
  t.append(len([i for i in a if _[0]-1<i<_[0]+3]))
  t.append(len([i for i in a if _[0]-2<i<_[0]+2]))
  t.append(len([i for i in a if _[0]-3<i<_[0]+1]))
print(max(t))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=Counter(a)
t=[]
for _ in b.most_common(20):
  t.append(len([i for i in a if _[0]-1<i<_[0]+3]))
  t.append(len([i for i in a if _[0]-2<i<_[0]+2]))
  t.append(len([i for i in a if _[0]-3<i<_[0]+1]))
print(max(t))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=Counter(a)
t=[]
for _ in b.most_common(10):
  t.append(len([i for i in a if _[0]-1<i<_[0]+3]))
  t.append(len([i for i in a if _[0]-2<i<_[0]+2]))
  t.append(len([i for i in a if _[0]-3<i<_[0]+1]))
print(max(t))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=Counter(a)
t=[]
for _ in b.most_common(3):
  t.append(len([i for i in a if _[0]-1<i<_[0]+3]))
  t.append(len([i for i in a if _[0]-2<i<_[0]+2]))
  t.append(len([i for i in a if _[0]-3<i<_[0]+1]))
print(max(t))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=Counter(a)
s,t=b.most_common()[0][1],[]
for _ in b.most_common(3):
  if _[1]==s:
    t.append(len([i for i in a if _[0]-2<i<_[0]+2]))
    t.append(len([i for i in a if _[0]-1<i<_[0]+3]))
    t.append(len([i for i in a if _[0]-3<i<_[0]+1]))
print(max(t))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=Counter(a)
s,t=b.most_common()[0][1],[]
for _ in b.most_common():
  if _[1]==s:
    t.append(len([i for i in a if _[0]-2<i<_[0]+2]))
    t.append(len([i for i in a if _[0]-1<i<_[0]+3]))
    t.append(len([i for i in a if _[0]-3<i<_[0]+1]))
print(max(t))

Submission status: Wrong Answer

Solution code:
a = int(input())

B = list(input().split())

A = []

for i in B:
    i = int(i)
    A.append(i)
    A.append(i+1)
    A.append(i-1)
A.sort()

C = list(set(A))
C.sort()
ans = 0
coun = 0
for i in C:
    
    for j in A:
        if(j == i):
            coun+=1
        else:
            break   
    if(coun > ans):
        ans = coun
        A = A[coun:]
    coun = 0
    
        
print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())

B = list(input().split())

A = []

for i in B:
    i = int(i)
    A.append(i)
    A.append(i+1)
    A.append(i-1)
A.sort()

C = set(A)
ans = 0
for i in A:
    if(i == -1):
        ans+=1
    else:
        break
A = A[ans:]
coun = 0
for i in C:
    if(i == -1):
        continue
    for j in A:
        if(j == i):
            coun+=1
        else:
            break   
    if(coun > ans):
        ans = coun
        A = A[coun:]
    coun = 0
    
        
print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())

B = list(input().split())

A = []

for i in B:
    i = int(i)
    A.append(i)
    A.append(i+1)
    A.append(i-1)
A.sort()

C = set(A)
print(C)
ans = 0
for i in A:
    if(i == -1):
        ans+=1
    else:
        break
A = A[ans:]
coun = 0
for i in C:
    if(i == -1):
        continue
    for j in A:
        if(j == i):
            coun+=1
        else:
            break   
    if(coun > ans):
        ans = coun
        A = A[coun:]
    coun = 0
    print(i)
    
        
print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())

B = list(input().split())

A = []

for i in B:
    i = int(i)
    A.append(i)
    A.append(i+1)
    A.append(i-1)
A.sort()

C = set(A)
ans = 0
for i in A:
    if(i == -1):
        ans+=1
    else:
        break
A = A[ans:]
coun = 0
for i in C:
    for j in A:
        if(j == i):
            coun+=1
        else:
            break   
    if(coun > ans):
        ans = coun
        A = A[coun:]
    coun = 0
    
        
print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())

B = list(input().split())

A = []

for i in B:
    i = int(i)
    A.append(i)
    A.append(i+1)
    if(i!=0):
        A.append(i-1)
A.sort()
C = set(A)
ans = 0
count = 0
for i in C:
    for j in A:
        if(j == i):
            count+=1
        else:
            break
    if(count > ans):
        ans = count
        A = A[count:]
        count = 0
        
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
A=Counter(list(map(int,input().split()))).most_common()
kouho=[A[0][0]-1,A[0][0],A[0][0]+1]
cnt=0
for i in A:
  if i[0]-1 in kouho or i[0]+1 in kouho:
    cnt+=i[1]
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
L.append(0)
M = [0]*((10**5)+1)
c = 0
d = 1
num = L[0]
if N == 1:
  print(1)
elif N == 2:
  if abs(L[0]-L[1]) <=1 :
    print(2)
  else:
    print(1)
else:
  while c <= N-1:
    if L[c] == L[c+1]:
      d += 1
      c += 1
    else:
      M[num] = d
      d = 1
      c += 1
      num = L[c]
  M.insert(0,0)
  M.append(0)
  ans = 0
  for i in range(len(M)-2):
    if M[i]+M[i+1]+M[i+2] >= ans:
      ans = M[i]+M[i+1]+M[i+2]
  print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
L.append(0)
M = [0]*(10**5)
c = 0
d = 1
num = L[0]
if N == 1:
  print(1)
elif N == 2:
  if abs(L[0]-L[1]) <=1 :
    print(2)
  else:
    print(1)
else:
  while c <= N-1:
    if L[c] == L[c+1]:
      d += 1
      c += 1
    else:
      M[num-1] = d
      d = 1
      c += 1
      num = L[c]
  M.insert(0,0)
  M.append(0)
  ans = 0
  for i in range(len(M)-2):
    if M[i]+M[i+1]+M[i+2] >= ans:
      ans = M[i]+M[i+1]+M[i+2]
  print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
alist = list(map(int,input().split()))
acount = collections.Counter(alist)
a = acount.most_common()
a.sort()
alen = len(a)
MAX = 0
if alen == 1:
    print(a[0][1])
elif alen == 2:
    if abs(a[0][1]-a[1][1])<=2:
        print(a[0][1]+a[1][1])
    else:
        print(max(a[0][1],a[1][1]))
else:
    for i in range(alen-2):
        if abs(a[i][0]-a[i+1][0]) == 1 and abs(a[i+2][0]-a[i+1][0]) == 1:
            kari = a[i][1]+a[i+1][1]+a[i+2][1]
        elif abs(a[i][0]-a[i+1][0]) <= 2 or abs(a[i+2][0]-a[i+1][0]) <= 2:
            if abs(a[i][0]-a[i+1][0]) <= 2 and abs(a[i+1][0]-a[i+2][0]) <= 2:
                karia = a[i][1]+a[i+1][1]
                karib = a[i+1][1]+a[i+2][1]
                kari = max(karia,karib)
            elif abs(a[i+1][0]-a[i+2][0]) <= 2:
                kari = a[i+1][1]+a[i+2][1]
            else:
                kari = a[i][1]+a[i+1][1]
        else:
            kari = max(a[i][1],a[i+1][1],a[i+2][1])
        if MAX <= kari:
            MAX = kari
    print(MAX)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
alist = list(map(int,input().split()))
acount = collections.Counter(alist)
a = acount.most_common()
a.sort()
alen = len(a)
MAX = 0
if alen == 1:
    print(a[0][1])
elif alen == 2:
    if abs(a[0][1]-a[1][1])<=2:
        print(a[0][1]+a[1][1])
    else:
        print(max(a[0][1],a[1][1]))
else:
    for i in range(alen-2):
        if abs(a[i][0]-a[i+1][0]) == 1 and abs(a[i+2][0]-a[i+1][0]) == 1:
            kari = a[i][1]+a[i+1][1]+a[i+2][1]
        elif abs(a[i][0]-a[i+1][0]) <= 2:
            kari = a[i][1]+a[i+1][1]
        elif abs(a[i+2][0]-a[i+1][0]) <= 2:
            kari = a[i+1][1]+a[i+2][1]
        else:
            kari = max(a[i][1],a[i+1][1],a[i+2][1])
        if MAX <= kari:
            MAX = kari
    print(MAX)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
alist = list(map(int,input().split()))
acount = collections.Counter(alist)
a = acount.most_common()
a.sort()
alen = len(a)
MAX = 0
if alen == 1:
    print(a[0][1])
elif alen == 2:
    if abs(a[0][1]-a[1][1])<=2:
        print(a[0][1]+a[1][1])
    else:
        print(max(a[0][1],a[1][1]))
else:
    for i in range(alen-2):
        if abs(a[i][0]-a[i+1][0]) == 1 and abs(a[i+2][0]-a[i+1][0]) == 1:
            kari = a[i][1]+a[i+1][1]+a[i+2][1]
        elif abs(a[i][0]-a[i+1][0]) == 1:
            kari = a[i][1]+a[i+1][1]
        elif abs(a[i+2][0]-a[i+1][0]) == 1:
            kari = a[i+1][1]+a[i+2][1]
        else:
            kari = max(a[i][1],a[i+1][1],a[i+2][1])
        if MAX <= kari:
            MAX = kari
    print(MAX)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
alist = list(map(int,input().split()))
acount = collections.Counter(alist)
a = acount.most_common()
a.sort()
alen = len(a)
MAX = 0
if alen == 1:
    print(a[0][1])
elif alen == 2:
    if abs(a[0][1]-a[1][1])<=2:
        print(a[0][1]+a[1][1])
    else:
        print(max(a[0][1],a[1][1]))
else:
    for i in range(alen-2):
        if abs(a[i][0]-a[i+1][0]) == 1 and abs(a[i+2][0]-a[i+1][0]) == 1:
            kari = a[i][1]+a[i+1][1]+a[i+2][1]
        elif abs(a[i][0]-a[i+1][0]) == 1:
            kari = a[i][1]+a[i+1][1]
        elif abs(a[i+2][0]-a[i+1][0]) == 1:
            kari = a[i+1][1]+a[i+2][1]
        if MAX <= kari:
            MAX = kari
    print(MAX)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
alist = list(map(int,input().split()))
acount = collections.Counter(alist)
a = acount.most_common()
a.sort()
lena = len(a)
MAX = 0
if lena == 1:
    print(1)
elif lena == 2:
    if abs(alist[0]-alist[1])<=2:
        print(2)
    else:
        print(1)
else:
    for i in range(lena-2):
        kari = a[i][1]+a[i+1][1]+a[i+2][1]
        if MAX <= kari:
            MAX = kari
    print(MAX)

Submission status: Wrong Answer

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

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

for x in range(len(ys)):
    y = a.count(x-1) + a.count(x) + a.count(x)
    ys[x] = y

print(max(ys))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
A=Counter(sorted(map(int,input().split())))
s=1
for i in range(max(A)-1):
    if i==0:s=max(s,A[0]+A[1])
    elif i==max(A)-2:s=max(s,A[i]+A[i+1])
    else:s=max(s,A[i-1]+A[i]+A[i+1])
print(s)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
A=Counter(sorted(map(int,input().split())))
s=1
for i in range(max(A)-1):
    if i==0:s=max(s,A[0]+A[1])
    elif i==max(A)-1:s=max(s,A[i]+A[i+1])
    else:s=max(s,A[i-1]+A[i]+A[i+1])
print(s)

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
a = sorted([int(i) for i in input().split()])
ans = 0
if n > 1:
 for i in range(100001):
  tmp = bisect.bisect_left(a,i+1)-bisect.bisect_left(a,i-1)+1
  ans = max(ans,tmp)
else:
  ans = 1
print(ans)

Submission status: Wrong Answer

Solution code:
#import sys
#input = sys.stdin.readline
n=int(input())
a=[int(i) for i in input().split()]
maxa=max(a)

#print(a)
ans=0
if n==1:
  ans=1
else:
  for i in range(1,maxa+1):
    cnt=0
    for j in range(len(a)):
      if a[j]==i or a[j]==i-1 or a[j]==i+1:
        cnt+=1
      if ans <= cnt:
        ans = cnt

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
a=[int(i) for i in input().split()]
#print(a)

ans=0
maxa=max(a)
for i in range(1,max(a)+1):
    cnt=a.count(i-1)+a.count(i)+a.count(i+1)
    if ans <= cnt:
      ans = cnt

print(ans)

Submission status: Wrong Answer

Solution code:
#import sys
#input = sys.stdin.readline
n=int(input())
a=[int(i) for i in input().split()]
#print(a)

ans=0
maxa=max(a)
for i in range(1,max(a)+1):
    cnt=a.count(i-1)+a.count(i)+a.count(i+1)
    if ans < cnt:
      ans = cnt

print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

num = math.ceil(sum(a)/N)

ans = a.count(num-1) + a.count(num) + a.count(num+1)
print(ans)

Submission status: Wrong Answer

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

num = sum(a)//N

for i in num-2, num-1,  num, num+1, num+2:
    ans.append(a.count(i))

print(max(sum(ans[:3]), sum(ans[1:4]), sum(ans[2:])))

Submission status: Wrong Answer

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

num = sum(a)//N

for i in num-2, num-1,  num, num+1, num+2:
    ans.append(a.count(i))

print(ans)
print(max(sum(ans[:3]), sum(ans[1:4]), sum(ans[2:])))

Submission status: Wrong Answer

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

num = sum(a)//N

for i in num-2, num-1,  num, num+1, num+2:
    ans.append(a.count(i))

print(max(sum(ans[:3]), sum(ans[1:4]), sum(ans[3:])))

Submission status: Wrong Answer

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

import collections
 
c=collections.Counter(a)
l=c.most_common()

from operator import itemgetter

l.sort(key=itemgetter(0))   
    

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

if len(l)==1:
    ans=l[0][1]

if len(l)==2:
    if int(l[1][0])-int(l[0][0])<=2:
        ans=l[0][1]+l[1][1]
    else:
        ans=(ans,l[0][1],l[1][1])
        
print(ans)

Submission status: Wrong Answer

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

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

for i in range(N):
    tmp = arr[i]
    carr[tmp] += 1
  
max = 0
for i in range(1,10**5-2):
    sum = carr[i] + carr[i+1] + carr[i+2]
    if max < sum:
        max = sum
print(max)

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = sorted(list(map(int,input().split())))
stack = []
left = 0
right = 1
for i in range(N):
    if i == N-1 or arr[i] != arr[i+1]:
        right = i+1
        stack.append(right-left)
        left = right
max = 1
for i in range(len(stack)):
    sumn = sum(stack[i:i+3])
    if sumn > max:
        max = sumn
print(max)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[0]*(10**5+1)

a=list(map(int,input().split()))
for i in range(N):
    for j in range(3):
        A[a[i]-1+j]+=1
print(max(A))

Submission status: Wrong Answer

Solution code:
import bisect as bi
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0 if n!=1 else 1
for i in range(a[0]+1, a[n-1]):
	ans = max(ans, bi.bisect_right(a, i+1)-bi.bisect_left(a, i-1))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
l=[];m=[]
for i in range(len(b)):
  l.append([b[i],a.count(b[i])])
if len(l)>3:
  for j in range(len(b)-3):
    x=l[j][1]
    if l[j+1][0]-l[j][0]<=2:x+=l[j+1][1]
    if l[j+2][0]-l[j][0]<=2:x+=l[j+2][1]
    m.append(x)
elif len(l)>2:
  for j in range(len(b)-2):
    x=l[j][1]
    if l[j+1][0]-l[j][0]<=2:x+=l[j+1][1]
    m.append(x)
else:
  m.append(l[0][1])
print(max(m))

Submission status: Wrong Answer

Solution code:
import collections as cl
N = int(input())
a_li = [i for i in input().split()]
c = cl.Counter(a_li)

keys = list(c.keys())
max_sum = 0
if (len(c) == 1) :
    print(1)
elif (len(c) == 2) :
    if (abs(int(a_li[0]) - int(a_li[1])) <= 1 ) :
        print(2)
    else :
        print(1)
else :
    for k in range(len(c) -2 ) :
        sum_v = c[keys[k]] + c[keys[k+1]] + c[keys[k+2]]
        if (max_sum < sum_v) :
            max_sum = sum_v
    
    print(max_sum)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
b = [0]+a[:-1]
c = a[1:]+[0]
d = list(np.array(a)+np.array(b)+np.array(c))
print(d.index(max(d))+1)

Submission status: Wrong Answer

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

check = 0
for i in range(len(ans)+1):
    check = max(check, sum(ans[:i]))
print(check)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
l=list(map(int,input().split()))
s=collections.Counter(l)
s=list(s.items())
s=sorted(s,key=lambda x:x[0])
#print(s)
f=[0]*len(s)
for i in range(len(s)):
    f[i]=s[i][1]
    if i>=1:
        if s[i-1][0]==s[i][0]-1:
            f[i]+=s[i-1][1]
    if i<=len(s)-2:
        if s[i+1][0]==s[i][0]+1:
            f[i]+=s[i+1][1]
print(f)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
l=list(map(int,input().split()))
s=collections.Counter(l)
s=list(s.items())
s=sorted(s,key=lambda x:x[0])
print(s)
f=[0]*len(s)
for i in range(len(s)):
    f[i]=s[i][1]
    if i>=1:
        if s[i-1][0]==s[i][0]-1:
            f[i]+=s[i-1][1]
    if i<=len(s)-2:
        if s[i+1][0]==s[i][0]+1:
            f[i]+=s[i+1][1]
print(f)

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
l=list(map(int,input().split()))
s=collections.Counter(l)
s=s.most_common()
#print(s)
f=[0]*len(s)
for i in range(len(s)):
    f[i]=s[i][1]
    if i>=1:
        if s[i-1][0]==s[i][0]-1:
            f[i]+=s[i-1][1]
    if i<=len(s)-2:
        if s[i+1][0]==s[i][0]+1:
            f[i]+=s[i+1][1]
print(max(f))

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
l=list(map(int,input().split()))
s=collections.Counter(l)
s=s.most_common()
#print(s)
f=[0]*len(s)
for i in range(len(s)):
    f[i]=s[i][1]
    if s[i-1][0]==s[i][0]-1 and i>=1:
        f[i]+=s[i-1][1]
    if i<=len(s)-2:
        if s[i+1][0]==s[i][0]+1:
            f[i]+=s[i+1][1]
print(max(f))

Submission status: Wrong Answer

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

a = sorted(a)

ans = 1
x = a[0]
s = 1
t = 0
u = 0
for i in range(1, n):
    if a[i] == a[i - 1]:
        if u > 0:
            u += 1
        elif t > 0:
            t += 1
        else:
            s += 1
    elif a[i] == a[i - 1] + 1:
        if u > 0:
            ans = max(ans, s + t + u)
            s = t
            t = u
            u = 1
        elif t > 0:
            u = 1
        else:
            t = 1
    elif a[i] == a[i - 1] + 2:
        ans = max(ans, s + t + u)
        if u > 0:
            s = u
            t = 0
            u = 1
        elif t > 0:
            s = t
            t = 0
            u = 1
        else:
            u = 1
    else:
        ans = max(ans, s + t + u)
        s = 1
        t = 0
        u = 0

print(ans)

Submission status: Wrong Answer

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

a = sorted(a)

ans = 1
x = a[0]
s = 1
t = 0
u = 0
for i in range(1, n):
    if a[i] == a[i - 1]:
        if u > 0:
            u += 1
        elif t > 0:
            t += 1
        else:
            s += 1
    elif a[i] == a[i - 1] + 1:
        if u > 0:
            ans = max(ans, s + t + u)
            s = t
            t = u
            u = 1
        elif t > 0:
            u = 1
        else:
            t = 1
    elif a[i] == a[i - 1] + 2:
        ans = max(ans, s + t + u)
        s = u
        t = 0
        u = 1
    else:
        ans = max(ans, s + t + u)
        s = 1
        t = 0
        u = 0

print(ans)

Submission status: Wrong Answer

Solution code:
_ = input()
aa = sorted(list(map(int,input().split())))
cnt = [0] * (aa[-1]+2)

for a in aa:
    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()))
l = [0]*(10**5+1)
for e in A:
    l[e-1] += 1
    l[e] += 1
    l[e+1] += 1
print(max(l))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
A_sl = list(set(A))
A_sl.sort()
if len(A_sl) == 1:
    print(len(A))
elif len(A_sl) == 2:
    if A_sl[1] - A_sl[0] <= 2:
        print(len(A))
    else:
        count_l = A.count(A_sl[1])
        count_s = A.count(A_sl[0])
        print(max(count_l,count_s)) 
else:
    ans = A.count(A[0]) + A.count(A[0]+1) + A.count(A[0]+2)
    edge = A.count(A[0])
    for i in range(A[0],A[-1]-2):
        if A.count(i+3) > edge:
            ans = A.count(i+1) + A.count(i+2) + A.count(i+3)
            edge = A.count(i+3)
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
l = []
A_sl = list(set(A))
if len(A_sl) == 1:
    print(len(A))
elif len(A_sl) == 2:
    if A_sl[1] - A_sl[0] <= 2:
        print(len(A))
    else:
        count_l = A.count(A_sl[1])
        count_s = A.count(A_sl[0])
        print(max(count_l,count_s)) 
else:
    for i in range(min(A),max(A) + 1):
        count_i = A.count(i)
        l.append(count_i)
    for i in range(2,max(A)-min(A)+1):
        if i == 2:
            ans = l[0] + l[1] + l[2]
            edge = l[0]
        elif l[i] > edge:
            ans = l[i-2] + l[i-1] + l[i]
            edge = l[i]
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
count_list = []
A_sl = list(set(A))
if len(A_sl) == 1:
    print(len(A))
elif len(A_sl) == 2:
    A_sl.sort()
    if A_sl[1] - A_sl[0] <= 2:
        print(len(A))
else:
    for i in range(min(A) + 1,max(A)):
        count = A.count(i-1) + A.count(i) + A.count(i+1)
        count_list.append(count)
    print(max(count_list))

Submission status: Wrong Answer

Solution code:
def 解():
    iN = int(input())
    aC = [0] *(10** 5+2)
    dsA = set()
    iUlim = 0
    for a in [int(_) for _ in input().split()]:
        aC[a] += 1
        if a > iUlim :
            iUlim = a
    iMax = 0
    for a in range(1,iUlim+1):
        iMax = max(iMax,sum(aC[a-1:a+2]))
    print(iMax)
解()

Submission status: Wrong Answer

Solution code:
def 解():
    iN = int(input())
    aC = [0] *(10** 5+2)
    dsA = set()
    for a in [int(_) for _ in input().split()]:
        aC[a] += 1
        if not a in dsA:
            dsA.add(a)
    iMax = 0
    for a in dsA:
        iMax = max(iMax,sum(aC[a-1:a+2]))
    print(iMax)
解()

Submission status: Wrong Answer

Solution code:
import numpy
n = int(input())
a = list(map(int,input().split()))
list_ = [0]*100004 #-1~100000
for i in a:
    list_[i] += 1
    list_[i+4] -= 1
res = numpy.cumsum(list_)
print(max(res))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split()))
K = [ 0 for i in range(10**5+1)]
for i in range(N):
    K[L[i]] += 1
a = []   
res = 0
for i in range(len(L)):
    a.append(K[i])
    if len(a) > 3:
        a.pop(0)
    if sum(a) > res:
        res =sum(a)
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
a = []
m_max = 0
count = 0
if len(set(L)) <= 3:
    print(N)
else:
    for i in range(N):
        count += 1
        if i == N-1:
            if len(a) == 3:
                a.pop(0)
            a.append(count)
            count = 0
            if sum(a) > m_max:
                m_max = sum(a)
        elif L[i] != L[i+1]:
            if len(a) == 3:
                a.pop(0)
            a.append(count)
            count = 0
            if sum(a) > m_max:
                m_max = sum(a)
    print(m_max)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split())) 
res = 0
L.sort()
count = 0
same = 0
res_m = 0
if len(set(L)) > 3:
    for i in range(N-1):
        same += 1
        if L[i] != L[i+1]:
            count += 1
            res_m += same
            same = 0
        if count == 3:
            count = 0
            if res_m > res:
                res = res_m
            res_m = 0
            
if len(set(L)) <= 3:
    res = len(L)

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split())) 
res = 0
L.sort()
count = 0
same = 0
res_m = 0
if len(set(L)) > 3:
    for i in range(N-1):
        same += 1
        if L[i] != L[i+1]:
            count += 1
            res_m += same
            same = 0
        if count == 3:
            if res_m > res:
                res = res_m
            res_m = 0
if len(set(L)) <= 3:
    res = len(L)

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split())) 
res = 0
L.sort()
count = 0
same = 0
res_m = 0
for i in range(N-1):
    same += 1
    if L[i] != L[i+1]:
        count += 1
        res_m += same
        same = 0
    if count == 3:
        if res_m > res:
            res = res_m
        res_m = 0
print(res)

Submission status: Wrong Answer

Solution code:
import collections

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

el_count = collections.Counter(A)

res = 0
for X in range(max(A)):
    tmp = el_count[X-1] + el_count[X] + el_count[X+1]
    if res < tmp:
        res = tmp

print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
x = []
cnt = [0]
for i in range(N):
    if a[i] in x:
        continue
    x.append(a[i])
    count = 0
    for j in range(N):
        if count + len(a[j:]) < max(cnt):
            break
        if x == a[j] or x == a[j]+1 or x == a[j]-1:
            count += 1
    cnt.append(count)

print(max(cnt))

Submission status: Wrong Answer

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

m = 0
s = sorted(a)

d = [0]*(s[-1]+2)

for i in range(0,s[-1]+1):
    d[i+1] = s.count(i)

for i in range(0,s[-1]+1):
    m = max(d[i-1]+d[i]+d[i+1],m)

print(m)

Submission status: Wrong Answer

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

m = 0
s = sorted(a)

d = [0]*(s[-1]+1)

for i in range(0,s[-1]+1):
    d[i] = s.count(i)

for i in range(1,s[-1]):
    m = max(d[i-1]+d[i]+d[i+1],m)

print(m)

Submission status: Wrong Answer

Solution code:
n=int(input())
cnt=[0]*100005
a=list(map(int,input().split()))
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())
cnt=[0]*100000
a=list(map(int,input().split()))
for i in a:
    cnt[i-1]+=1
    cnt[i]+=1
    cnt[i-1]+=1
print(max(cnt))

Submission status: Wrong Answer

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

c = Counter(a)

ans = 0
x = 0
for i in range(max(a)):
    if ans < c[i] + c[i+1] + c[i+2]:
        ans = c[i] + c[i+1] + c[i+2]
        x = c[i+1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(a)
ans = 0
for i in range(max(a)):
    res = c[i - 1] + c[i] + c[i + 1]
    ans = max(ans, res)
print(ans)

Submission status: Wrong Answer

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

AA = collections.Counter(A)
cc = [0]*(max(A)+1)

for i in AA.keys():
    cc[i] = AA[i]

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

print(ans)

Submission status: Wrong Answer

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

AA = collections.Counter(A)
cc = [0]*(max(A)+1)

for i in AA.keys():
    cc[i] = AA[i]

for i in range(len(cc)-2):
    ans =  max(ans, sum(cc[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(min(A), max(A)):
    ans = max(ans, A.count(i)+A.count(i+1)+A.count(i+2))
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#ABC072C
N=int(input())
A=list(map(int,input().split()))
max_A=max(A)
TGS=[0]*(max_A+1)
ans=0
for i in range(N):
    TGS[A[i]]+=1
for i in range(max_A-1):
    if ans<TGS[i]+TGS[i+1]+TGS[i+2]:
        ans=TGS[i]+TGS[i+1]+TGS[i+2]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
al=set(a)
al=list(al)
l=len(al)
a1=a.count(al[0])#一個前の合計
if l>=2:
    a2=a.count(al[1])#現在の合計
if l>=3:
    a3=a.count(al[2])#一つ先の合計
if l==1:
    print(a1)
    exit()
elif l==2:
    if abs(al[0]-al[1])<=2:
        print(a1+a2)
        exit()
    else:
        print(max(a1,a2))
        exit()
count=0
result=0#最大値
al.append(" ")
for i in range(1,l-2):
    count=a1+a2+a3
    if count>result:
        result=count
    a1=a2
    a2=a3
    a3=a.count(al[i+2])
print(result)