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()))
A=collections.Counter(a)
b=list(A.values())
b.sort()
cnt=b[0]
for i in range(len(b)-2):
  cnt=max(cnt,b[i]+b[i+1]+b[i+2])  
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
import collections
c=collections.Counter(a)
d=sorted(c)
maxi=0
if n>=3 and len(d)>=3:
    for i in range(len(d)-2):
        total=c[d[i]]+c[d[i+1]]+c[d[i+2]]
        maxi=max(maxi,total)
    print(maxi)
if n>=3 and len(d)==2:
    print(3 if abs(d[0]-d[1])<=2 else 2)
if n>=3 and len(d)==1:
    print(3)
if n==2:
    print(2 if abs(a[0]-a[1])<=2 else 1)
if n==1:
    print(1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
import collections
c=collections.Counter(a)
d=sorted(c)
maxi=0
if n>=3:
    for i in range(len(d)-2):
        total=c[d[i]]+c[d[i+1]]+c[d[i+2]]
        maxi=max(maxi,total)
    print(maxi)
if n==2:
    print(2 if abs(a[0]-a[1])>=2 else 1)
if n==1:
    print(1)

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = list(map(int, input().split()))
arr2 = [0]*(max(arr)+1)
if len(arr2) <= 3:
    arr2 = [0]*4
for i in range(N):
    arr2[arr[i]] += 1
ans = arr2[1] + arr2[2] + arr2[3]
tmp = ans
for i in range(4,len(arr2)):
    tmp = tmp - arr2[i-3] + arr2[i]
    if ans < tmp:
        ans = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(a)

cm = c.most_common()
key = []
count = 0
for tup in cm:
    if tup[1] >= count:
        key.append(tup[0])
        count = tup[1]
    else:
        break

ans = 0
for i in key:
    maxx = max(c[i - 2] + c[i - 1] + c[i], c[i - 1] + c[i] + c[i + 1], c[i] + c[i + 1] + c[i + 2])
    if maxx > ans:
        ans = maxx

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = Counter(list(map(int,input().split())))
keysA =  list(A.keys())
len_keysA = len(keysA)

if len_keysA == 1:
  print(N)
  exit()
ans = -float('inf')
for i in range(len_keysA):
  tmp_ans = A[keysA[i]]
  if i != 0 and abs(A[keysA[i]]-A[keysA[i-1]]) <= 1: tmp_ans += A[keysA[i-1]]
  if i != len_keysA-1 and abs(A[keysA[i]]-A[keysA[i+1]]) <= 1: tmp_ans += A[keysA[i+1]]  
  ans = max(ans, tmp_ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = Counter(list(map(int,input().split())))
keysA =  list(A.keys())
len_keysA = len(keysA)

if len_keysA == 1:
  print(N)
  exit()
ans = -float('inf')
for i in range(len_keysA):
  if i == 0: ans = max(ans, A[keysA[i]]+A[keysA[i+1]])
  elif i == len_keysA-1: ans = max(ans, A[keysA[i-1]]+A[keysA[i]])
  else: ans = max(ans, A[keysA[i-1]]+A[keysA[i]]+A[keysA[i+1]])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
sys.setrecursionlimit(10**6)

N = int(input())
A = list(map(int,input().split()))
a = Counter(A)
s=0
if len(A)==1:
    print(1)
    exit()
for key, val in a.items():
    if key==len(a)-2:
        break
    if a[key]+a[key+1]+a[key+2] >= s:
        if a[key]+1==a[key+1] and a[key+1]+1 == a[key+2]:
            s = a[key]+a[key+1]+a[key+2]
print(s)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
sys.setrecursionlimit(10**6)

N = int(input())
A = list(map(int,input().split()))
a = Counter(A)
s=0
if len(A)==1:
    print(1)
    exit()
for key, val in a.items():
    if key==len(a)-2:
        break
    if a[key]+a[key+1]+a[key+2] >= s:
        s = a[key]+a[key+1]+a[key+2]
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split(' ')]
A.sort()
B = [0]*(A[N-1]+2)

for a in A:
    B[a] += 1
    B[a-1] += 1
    B[a+1] += 1

print(max(B))

Submission status: Wrong Answer

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

    c = [0] * (100000 + 1)
    for ai in A:
        c[ai-1] += 1
        c[ai] += 1
        c[ai+1] += 1

    print(max(c))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

N=int(input())

a=[int(t.strip()) for t in input().split()]

num=[]
num= [0] * (max(a)+2)
for i in range(N):
	num[a[i]] += 1
	
maximum=0
inx=0
for i in range(len(num)-2):
	tmp=num[i] + num[i+1] +num[i+2]
	if maximum < tmp:
		maximum = tmp
		inx=i+1

print(maximum)		
#print(num)

Submission status: Wrong Answer

Solution code:
import sys

N=int(input())

a=[int(t.strip()) for t in input().split()]

num=[]
num= [0] * (max(a)+1)
for i in range(N):
	num[a[i]] += 1
	
maximum=0
inx=0
for i in range(len(num)-2):
	tmp=num[i] + num[i+1] +num[i+2]
	if maximum < tmp:
		maximum = tmp
		inx=i+1

print(maximum)

Submission status: Wrong Answer

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

mx = max(A)

score = [0]*(mx+2)

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

print(max(score))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
a = list(map(int, input().split()))
counter = collections.Counter(a)
max_count = 0
for i in range(0, max(a)):
    max_count = max(max_count, counter[i - 1] + counter[i] + counter[i + 1])
print(max_count)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=sorted(list(map(int,input().split())))
C=[0]*(max(A)+1)

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

T=0
for i in range(1,max(A)):
    T=max(T,C[i-1]+C[i]+C[i+1])

print(T)

Submission status: Wrong Answer

Solution code:
n=int(input())
items=list(map(int,input().split()))
items.sort()
cnt_list=[]
for i in set(items):
  cnt=0
  for j in range(1,n-1):
    if abs(items[j]-i)<=1:
      cnt+=1
    if items[j]-i>1:
      break
  cnt_list.append(cnt)
print(max(cnt_list))

Submission status: Wrong Answer

Solution code:
n=int(input())
items=list(map(int,input().split()))
items.sort()
cnt_list=[]
for i in set(items):
  cnt=0
  for j in range(1,n-1):
    if abs(items[j]-i)<=1:
      cnt+=1
    if items[j]-i>1:
      print("break")
      break
  cnt_list.append(cnt)
  print(i,"cnt: ", cnt)
print(max(cnt_list))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(lambda x: int(x), input().split()))
a.sort()
cnt=[]
val=[]
last=-1
for i in a:
    if i == last:
        cnt[-1]+=1
    else:
        cnt.append(1)
        val.append(i)
        last = i

low_val=-10
low_cnt=0
mid_val=0
mid_cnt=0
ans=0
for i, v in enumerate(val):
    if v>=low_val+3:
        ans=max(ans, low_cnt+mid_cnt+cnt[i])
        low_val=v
        low_cnt=cnt[i]
        mid_val=0
        mid_cnt=0
    elif v==low_val+2:
        ans=max(ans, low_cnt+mid_cnt+cnt[i])
        if mid_val>0:
            low_val=mid_val
            low_cnt=mid_cnt
            mid_val=v
            mid_cnt=cnt[i]
        else:
            low_val=v
            low_cnt=cnt[i]
            mid_val=0
            mid_cnt=0
    if v==low_val+1:
        mid_val=v
        mid_cnt=cnt[i]
ans=max(ans, low_cnt+mid_cnt)
print(ans)

Submission status: Wrong Answer

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

res = 0
for i in range(n):
	neo_nums = []
	target = nums[i]
	for num in nums :
		if abs(target - num) >= 2:
			break
		if num == target :
			neo_nums.append(num)
		elif num+1 == target :
			neo_nums.append(num)
		elif num-1 == target :
			neo_nums.append(num)
	new = len(neo_nums)
	res = new if new > res else res
print(res)

Submission status: Wrong Answer

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

res = 0
for i in range(n):
	neo_nums = []
	target = nums[i]
	for num in nums :
		if target - num >= 2:
			break
		if num == target :
			neo_nums.append(num)
		elif num+1 == target :
			neo_nums.append(num)
		elif num-1 == target :
			neo_nums.append(num)
	new = len(neo_nums)
	res = new if new > res else res
print(res)

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(a)
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n = int(input())
    as_ = list(map(int, input().split()))
    counter_a_tmp = collections.Counter(as_)
    counter_a = collections.defaultdict(int)
    for key, count in counter_a_tmp.items():
        counter_a[key] = count

    ans = 0
    if max(as_) == 0:
        print(n)
    else:
        for i in range(0, max(as_) - 1):
            ans = max(ans, counter_a[i] + counter_a[i + 1] + counter_a[i + 2])

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n = int(input())
    as_ = list(map(int, input().split()))
    counter_a_tmp = collections.Counter(as_)
    counter_a = collections.defaultdict(int)
    for key, count in counter_a_tmp.items():
        counter_a[key] = count

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# ABC072 C - Together
from collections import Counter
N = int(input())
A = list(map(str,input().split()))
L = [0]*100000
C = Counter(A)
C = C.items()

if N == 1:
    ans = 1
else:
    for c in C:
        idx,v = c
        idx = int(idx)
        L[idx-1] = v

    ans = 0
    for i in range(N-1):
        if i == 0:
            ans = L[0] + L[1]
            continue
        ans = max(ans,L[i-1]+L[i]+L[i+1])

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
import copy
b=copy.copy(a)
c=copy.copy(a)
for i in range(n):
    b[i]+=1
    c[i]-=1
s=a+b+c
s.sort()
d=[]
#print(s)
i=0;x=1
while i < 3*n-1:
    
    if s[i]==s[i+1]:
        x+=1
    else:
        d.append(x)
        x=1
    i+=1
if s[-1]==s[-2]:
    d[-1]+=1
elif s[-1]!=s[-2]:
	d.append(1)
print(max(d))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
C = Counter(A)
M = C.most_common()[0][0]
a = 1

for i in range(M-1,M+2):
  a = max(a,A.count(i-1)+A.count(i)+A.count(i+1))

print(a)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=1
d={}
for i in range(a[-1]):
    d[i]=a.count(i)
for i in range(1,a[-1]-1):
    cnt=d[i-1]+d[i]+d[i+1]
    ans=max(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
ans=1
d={}
for i in range(a[-1]):
    d[i]=a.count(i)
for i in range(1,a[-1]-1):
    cnt=d[i-1]+d[i]+d[i+1]
    ans=max(ans,cnt)
print(ans)

Submission status: Wrong Answer

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

l=[0]*(max(a)+1)
for i in range(n):
    l[a[i]-1]+=1
#print(l)
ans=0
for i in range(len(l)-2):
    ans=max(ans,l[i]+l[i+1]+l[i+2])
if len(l)==1:
    print(l[0])
elif len(l)==2:
    print(sum(l))
else:
    ans=max(ans,l[0]+l[1],l[-1]+l[-2])
    print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

cnt = 0
for i in range(1, N - 1):
    tmp = a.count(i) + a.count(i + 1) + a.count(i - 1)
    if cnt <= tmp:
        cnt = tmp

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = [0] * (10 ** 5 + 2)

for i in a:
    b[i - 1] += 1
    b[i] += 1
    b[i - 1] += 1
print(max(b))

Submission status: Wrong Answer

Solution code:
from statistics import median

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

sarr = []

ac = 0
bc = 0
cc = 0
m = int(round(median(arr)))

for i in range(n):
    if abs(arr[i] - m) <= 1:
        ac += 1
    if abs(arr[i] - m - 1) <= 1:
        bc += 1
    if abs(arr[i] - m + 1) <= 1:
        cc += 1


print(max(ac, bc, cc))

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
cnt = [0]*100001
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()))
C = [0]*(max(A)+1)
ans = 0
if len(A) <= 3:
  ans = len(set(A))
else:
  for a in A:
    C[a] += 1
  for i in range(len(C)-2):
    ans = max(sum(C[i:i+3]), ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
C = [0]*(max(A)+1)
for a in A:
  C[a] += 1
ans = 0
if len(A) <= 3:
  ans = len(set(A))
else:
  for i in range(len(C)-2):
    ans = max(sum(C[i:i+3]), ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
C = [0]*(max(A)+1)
for a in A:
  C[a] += 1
ans = 0
if len(A) <= 3:
  ans = len(set(A))
else:
  for i in range(len(C)-2):
    print(C[i:i+3])
    ans = max(sum(C[i:i+3]), ans)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/abc072/tasks/arc082_a

from functools import reduce
n = int(input())
l = list(map(int, input().split()))

def get_process(arg):
    def process(accumulator, currentValue):
        if currentValue == arg or currentValue+1 == arg or currentValue-1 == arg:
            return accumulator + 1
        else:
            return accumulator
    return process

x = reduce(get_process(l[0]+1), l, 0)
y = reduce(get_process(l[0]), l, 0)
z = reduce(get_process(l[0]-1), l, 0)

print(max(x, y, z))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ary = [0 for _ in range(10**5)]

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

print(max(ary))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
a_s = input().split()
for i in range(N):
    a_s[i] = int(a_s[i])
a_s = np.array(a_s)

a_unique = np.unique(a_s)
a_counts = []
for i,a in enumerate(a_unique):
    a_counts.append(sum(a_s==a))

ans = 0
for i in range(len(a_unique)):
    val = a_counts[i]
    if i>0:
        if a_unique[i-1]+1==a_unique[i]:
            val += a_counts[i-1]
            
    if i<len(a_unique)-1:
        if a_unique[i+1]-1==a_unique[i]:
            val += a_counts[i+1]
            
    if val > ans:
        ans = val
        
    if ans > sum(a_counts[i+1:]):
        break
        
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
S=sorted(Counter(A).most_common())
S.insert(0,(-1,0))
S.append((-1,0))
c=1
for i in range(1,len(S)-2):
	r=S[i-1][1] if S[i-1][0]==S[i][0]-1 else 0
	l=S[i+1][1] if S[i+1][0]==S[i][0]+1 else 0
	c=max(c,S[i][1]+r+l)
print(c)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

for i in range(N):
    num.append(a[i])
    num.append(a[i]+1)
    num.append(a[i]-1)

c = Counter(num)
maximum = c[0]

if c[maximum] == 0:
    print(1)

else:
    print(c[maximum])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
c = Counter(arr)
ans = 0
for x in range(max(arr)):
    t = c[x-1] + c[x] + c[x+1]
    ans = max(ans, t)
print(ans)

Submission status: Wrong Answer

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

d = dict()

for i in a:
    d[i] = d.get(i, 0) + 1

d = sorted(d.items(), key=lambda x:x[0])

d = [(0, 0)] + d + [(0, 0)]

ans = 1

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

print(ans)

Submission status: Wrong Answer

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

d = dict()

for i in a:
    d[i] = d.get(i, 0) + 1

d = sorted(d.items(), key=lambda x:x[0])

ans = 1

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

print(ans)

Submission status: Wrong Answer

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

d = dict()

for i in a:
    d[i] = d.get(i, 0) + 1

d = sorted(d.items(), key=lambda x:x[0])

ans = 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
L=max(a)+1
b=[0]*L

for i in a:
    b[i]+=1

ans=0
for p in range(L-2):
    ans = max(ans,b[p]+b[p+1]+b[p+2])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter as C
n=int(input())
B=list(map(int,input().split()))
if n==1:
  print(1)
  exit()
if n==2:
  print(2 if abs(B[1]-B[0])<=2 else 1)
  exit()
A=C(B+[i for i in range(-1,max(B)+1)]).most_common()
m=0
for i in range(len(A)-2):
  m=max(m,A[i][1]+A[i+1][1]+A[i+2][1]-3)
print(m)

Submission status: Wrong Answer

Solution code:
from collections import Counter as C
n=int(input())
B=list(map(int,input().split()))
if n==1:
  print(1)
  exit()
if n==2:
  print(2 if abs(B[1]-B[0])<=2 else 1)
  exit()
A=C(B+[i for i in range(1,max(B)+1)]).most_common()
m=0
for i in range(1,len(A)-1):
  m=max(m,A[i-1][1]+A[i][1]+A[i+1][1]-3)
print(m)

Submission status: Wrong Answer

Solution code:
from collections import Counter as C
n=int(input())
B=list(map(int,input().split()))
if n==1:
  print(1)
  exit()
if n==2:
  print(2 if abs(B[1]-B[0])<=2 else 1)
  exit()
A=C(B+[i for i in range(1,max(B)+1)]).most_common()
print(A)
m=0
for i in range(1,len(A)-1):
  m=max(m,A[i-1][1]+A[i][1]+A[i+1][1]-3)
  print(A[i-1][1]+A[i][1]+A[i+1][1]-3)
print(m)

Submission status: Wrong Answer

Solution code:
from collections import Counter as C
n=int(input())
B=list(map(int,input().split()))
if n==1:
  print(1)
  exit()
if n==2:
  print(2 if abs(B[1]-B[0])<=1 else 1)
  exit()
A=C(B+[i for i in range(1,max(B)+1)]).most_common()
m=0
for i in range(1,len(A)-1):
  m=max(m,A[i-1][1]+A[i][1]+A[i+1][1]-3)
print(m)

Submission status: Wrong Answer

Solution code:
from collections import Counter as C
n=int(input())
B=list(map(int,input().split()))
if n==1:
  print(1)
  exit()
if n==2:
  print(2 if abs(B[1]-B[0])<=1 else 1)
  exit()
A=C(B+[i for i in range(max(B))]).most_common()
m=0
for i in range(1,len(A)-1):
  m=max(m,A[i-1][1]+A[i][1]+A[i+1][1]-3)
print(m)

Submission status: Wrong Answer

Solution code:
import collections as c

N = int(input())
A = c.Counter(list(map(int,input().split())))
key = list(A.keys())
val = list(A.values())


ans = 0
for i in range(len(key)):
	tmp = 0

	if i <= len(key) - 3:
		tmp += val[i]
		if key[i+1] <= key[i]+2:
			tmp  += val[i+1]
		if key[i+2] <= key[i]+2:
			tmp += val[i+2]
	elif i == len(key) - 2:
		tmp += val[i]
		if key[i+1] <= 2:
			tmp += val[i+1]
	else:
		tmp += val[i]

	ans = max(tmp, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
c = collections.Counter(data)
ans = 0
max_v = max(data)
for i in range(max_v-1):
    ans = max(ans,c[i]+c[i+1]+c[i+2])
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(1, n-1):
  cnt = sum([1 for j in a if i-1 <= j <= i+1])
  if ans < cnt:
    ans = cnt
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
li = na()
li.sort()
now = li[0]
ans = 1
ct = 1
i = 0
k = 0
flag = False
while i < n - 1:
    i += 1
    if li[i] == now:
        ct += 1
    if li[i] == now + 1:
        if flag:
            ct += 1
        else:
            flag = True
            k = i
            ct += 1
    if li[i] == now + 2:
        if flag:
            ct += 1
        else:
            flag = True
            k = i
            ct += 1
    if not flag and i == n - 1:
        ans = max(ans, ct)
        break
    if li[i] > now + 2:
        flag = False
        i = k
        now = li[i]
        ans = max(ans, ct)
        ct = 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
li = na()
li.sort()
now = li[0]
ans = 1
ct = 1
i = 0
k = 0
flag = False
while i != n - 1:
    i += 1
    if li[i] == now:
        ct += 1
    elif li[i] == now + 1:
        if flag:
            ct += 1
        else:
            flag = True
            k = i
            ct += 1
    elif li[i] == now + 2:
        if flag:
            ct += 1
        else:
            flag = True
            k = i
            ct += 1
    else:
        if not flag:
            break
        flag = False
        i = k
        now = li[i]
        ans = max(ans, ct)
        ct = 1
print(ans)

Submission status: Wrong Answer

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

ans = 0

tmp = 0

Anum = [0] * (A[-1]+1)

for i in A:
    if i == tmp:
        Anum[i] += 1
    else:
        tmp = i
        Anum[i] = 1
if A[-1] != 1:
    for i in range(A[-1]-1):
        tmp = Anum[i] + Anum[i+1] + Anum[i+2]
        if ans < tmp:
            ans = tmp
else:
    ans = len(A)
print(ans)

Submission status: Wrong Answer

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

ans = 0

tmp = 0

Anum = [0] * (A[-1]+1)

for i in A:
    if i == tmp:
        Anum[i] += 1
    else:
        tmp = i
        Anum[i] = 1

for i in range(A[-1]-1):
    tmp = Anum[i] + Anum[i+1] + Anum[i+2]
    if ans < tmp:
        ans = tmp

#print(Anum)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
cand = collections.Counter(a)
cand_list = cand.most_common(len(set(a)))
ans = 0
n = min(len(set(a)),10)
for i in range(n):
  num = cand_list[i][0]
  count = cand[num]
  if num + 1 in a:
    count += cand[num + 1]
  if num - 1 in a:
    count += cand[num - 1]
  if ans < count:
    ans = count

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
cand = collections.Counter(a)
cand_list = cand.most_common(len(set(a)))
ans = 0
n = min(len(set(a)),5)
for i in range(n):
  num = cand_list[i][0]
  count = cand[num]
  if num + 1 in a:
    count += cand[num + 1]
  if num - 1 in a:
    count += cand[num - 1]
  if ans < count:
    ans = count

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)+1,max(A)+1):
  cnt = 0
  if i in A:
    cnt += A.count(i)
  if i-1 in A:
    cnt += A.count(i-1)
  if i+1 in A:
    cnt += A.count(i+1)
  ans = max(ans,cnt) 
if n == 1:
  print(1)
else:
  print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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

a.sort()
count1=0
count2=0
ans=0
x=a[0]
y=0
for i in range(n):
    if a[i]==x:
        count1+=1
    elif a[i]==x+1 or a[i]==x+2:
        count1+=1
        count2+=1
        if y==0:
            y=i
    else:
        ans=max(ans,count1)
        count1=count2+1
        count2=0
        x=a[y]
if ans==0:
    print(n)
else:
    print(ans)

Submission status: Wrong Answer

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

a.sort()

a_list = [0] * (a[-1]+1)
#print(a_list)
cnt = 0
tmp = 0

for i in range(a[-1]+1):
    #print(a[tmp])
    while a[tmp] == i:
        #print(i)
        cnt += 1
        tmp += 1
        if tmp == len(a):
            break
    a_list[i] = cnt
    cnt = 0


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

Submission status: Wrong Answer

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

a.sort()

a_list = [0] * (a[-1]+1)
#print(a_list)
cnt = 0
tmp = 0

for i in range(a[-1]+1):
    #print(a[tmp])
    while a[tmp] == i:
        #print(i)
        cnt += 1
        tmp += 1
        if tmp == len(a):
            a_list[i] = cnt
            break
    a_list[i] = cnt
    cnt = 0


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

Submission status: Wrong Answer

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

a.sort()

a_list = [0] * (a[-1]+1)
#print(a_list)
cnt = 0
tmp = 0

for i in range(a[-1]+1):
    #print(a[tmp])
    while a[tmp] == i:
        #print(i)
        cnt += 1
        tmp += 1
        if tmp == len(a):
            a_list[i] = cnt
            break
    a_list[i] = cnt
    cnt = 0


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

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
a.sort()
M=0
s=0
for i in range(a[0],a[N-1]+1):
    t=0
    for j in range(s,N):
        if a[j]==i:
            t+=1
            s=i+1
        elif i+1<=a[j]<=i+2:
            t+=1
        else:
            break
    if t>M:
        M=t
print(M)

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(n):
    b[a[i]]+=1

maxim = -1
maximid=-1
if(n>=3):
    c = [b[i]+b[i+1]+b[i+2] for i in range(n-2)]
    for i in range(n-2):
        if(maxim<c[i]):
            maxim = c[i]
            maximid = i+1
    print(maxim)
else:
    print(a[0])

Submission status: Wrong Answer

Solution code:
import collections

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

dict = collections.Counter(a)

#print(n)
#print(a)
#print(dict)
#print(dic[str(1)])

x_max = 0
mem_key = ""

for key in dict.keys():
  k = int( key )
  l = dict[str(k-1)]
  m = dict[str(k)]
  n = dict[str(k+1)]
  #print(k,m,l,n)
  #print(l+m+n)
  if l+m+n >= x_max:
    x_max = l+m+n
    mem_key = key
    
print(x_max)
print(mem_key)

Submission status: Wrong Answer

Solution code:
import collections
N =  int(input())
a = list(map(int,input().split()))
a = collections.Counter(a)
a = sorted(a.items())
li = [0]*N
tmp = 0
if len(a)==1:
    print(1)
    exit()

for i in range(len(a)-1):
    tmp += a[i][1]
    if a[i][0]-1==a[i-1][0]:
        tmp += a[i-1][1]
    if a[i][0]+1==a[i+1][0]:
        tmp += a[i+1][1]
    li[i] = tmp
    tmp = 0

if a[-1][0]-1==a[-2][0]:
    li.append(a[-1][1]+a[-2][1])
print(max(li))

Submission status: Wrong Answer

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

ans_list = [ 0 for i in range(max(num_list)+2) ]

for i in num_list:
    ans_list[i-1] += 1
    ans_list[i] += 1
    ans_list[i+1] += 1

print(max(ans_list))

Submission status: Wrong Answer

Solution code:
from bisect import*
n = int(input())
*a,=map(int,input().split())
a.sort()
ans = 0
for i in range(2,10**5):
	ans = max(ans,bisect(a,i+1)-bisect_left(a,i-1))
print(ans)

Submission status: Wrong Answer

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

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

for a in A:
    L[a - 1] += 1
    L[a] += 1
    L[a + 1] += 1

print(sorted(L)[-1])