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: Accepted

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

count = [0] * (10 ** 5 + 2)

for x in a:
    count[x] += 1
    count[x + 1] += 1
    count[x + 2] += 1
print(max(count))

Submission status: Accepted

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

def func(a):
  count = [0] * (max(a)+1)

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

  max_n = 0
  for j in range(1, len(count)-1):
      max_n = max(max_n, count[j] + count[j-1] + count[j+1])
  max_n = max(max_n, count[-1] + count[-2])

  return max_n

print(n if len(set(a)) == 1 else func(a))

Submission status: Accepted

Solution code:
N = int(input())
l = [0]*100003
for a in map(int, input().split()):
  l[a+1] += 1
  l[a] += 1
  if a-1 < 0:
    continue
  else:
    l[a-1] += 1

print(max(l))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect

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

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

ans = 0
for i in range(n):
    idx = bisect.bisect_right(al, al[i] + 2)
    tmp = idx - i
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())
*A, = map(int, input().split())
print(max(collections.Counter(A + [a-1 for a in A] + [a+1 for a in A]).values()))

Submission status: Accepted

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

a_plus1 = copy.copy(a)
a_minus1 = copy.copy(a)
for x in range(n):
    a_plus1[x] += 1
for y in range(n):
    a_minus1[y] -= 1
a_total = a + a_plus1 + a_minus1
cnt = Counter(a_total)
a_max = list(cnt.values())
print(max(a_max))

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    a = LI()
    max_a = max(a)
    if max_a == 0 or max_a == 1:
        print(len(a))
        sys.exit()
    t = [0]*(max_a+1)
    for i in a:
        t[i] += 1
    ans = 0
    for i in range(1, len(t)-1):
        temp = t[i-1] + t[i] + t[i+1]
        ans = max(ans, temp)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections

n = int(input())
la = [int(w) for w in input().split()]

cnt = collections.Counter(la)

ans = 0
for c in cnt:
    t = cnt[c-1] + cnt[c] + cnt[c+1]
    ans = max(ans, t)

print(ans)

Submission status: Accepted

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

ans_l = [0]*(10**5 + 2)

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

print(max(ans_l))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = 100002*[0]

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

print(max(B))

Submission status: Accepted

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

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

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

print(max(ans))

Submission status: Accepted

Solution code:
import collections

n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
ans=0
for k,v in c.items():
    ans=max(ans,(v + c.get(k-1,0) + c.get(k+1,0)))
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    n, *a = map(int, read().split())
    ac = Counter(a)
    acs = sorted(ac.items())
    r = ac.most_common()[0][1]
    if len(acs) == 2:
        if acs[1][0] - acs[0][0] == 1:
            r = acs[0][1] + acs[1][1]

    for i1 in range(1, len(acs) - 1):
        if abs(acs[i1 - 1][0] - acs[i1+1][0]) <= 2:
            r = max(r, acs[i1-1][1] + acs[i1][1] + acs[i1+1][1])
        elif abs(acs[i1 - 1][0] - acs[i1][0]) <= 1:
            r = max(r, acs[i1-1][1] + acs[i1][1])
        elif abs(acs[i1 + 1][0] - acs[i1][0]) <= 1:
            r = max(r, acs[i1+1][1] + acs[i1][1])
    print(r)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
maxi=-1
dic={}
for i in a:
    if i in dic:
        dic[i]+=1
    else:
        dic[i]=1
for i in range(max(a)+1):
    maxi=max(maxi,(dic[i-1] if i-1 in dic else 0)+(dic[i] if i in dic else 0)+(dic[i+1] if i+1 in dic else 0))
print(maxi)

Submission status: Accepted

Solution code:
import collections

N = int(input())
a = [int(i) for i in input().split()]
g = a[:]
for i in g:
    a.append(i-1)
    a.append(i+1)



dict = collections.Counter(a)

for a, b in dict.most_common():
    print(b)
    break

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
input()
(*a, ) = map(int, input().split())
d = (-1, 0, 1)
ans = [0] * (10**5 + 1)
for i in a:
    for j in d:
        if 0 <= i + j <= 10**5:
            ans[i + j] += 1
print(max(ans))

Submission status: Accepted

Solution code:
import collections

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

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

l = collections.Counter(a)
l = list(l.values())
print(max(l))

Submission status: Accepted

Solution code:
from collections import Counter
N, = list(map(int,input().split()))
a  = list(map(int,input().split()))
c  = Counter()
for ai in a:
    for b in range(ai-1,ai+2):
        c[b] += 1
print(max(c.values()))

Submission status: Accepted

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

c_dic = {}
for i in a:
    if i not in c_dic:
        c_dic[i] = 1
    else:
        c_dic[i] += 1
    
    if i + 1 not in c_dic:
        c_dic[i + 1] = 1
    else:
        c_dic[i + 1] += 1

    if i - 1 not in c_dic:
        c_dic[i - 1] = 1
    else:
        c_dic[i - 1] += 1

print(max(c_dic.values()))

Submission status: Accepted

Solution code:
from collections import Counter as C

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

ans = 0
for k in a:
    ans = max(ans, a[k-1] + a[k] + a[k+1])
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
MAX_A = 100_001
N = int(input())
A = list(map(int, input().split()))
_A = [0] * MAX_A
for a in A:
    _A[a] += 1
    if a - 1 >= 0:
        _A[a - 1] += 1
    if a + 1 < MAX_A:
        _A[a + 1] += 1
print(max(_A))

Submission status: Accepted

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

X={i:0 for i in range(-1,max(A)+2)}
for a in A:
    X[a]+=1
    X[a-1]+=1
    X[a+1]+=1

print(max(X.values()))

Submission status: Accepted

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

print(max(c.values()))

Submission status: Accepted

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

A_={}
for _ in range(-1,10**5+10):
    A_[_]=0

for a in A:
    a_b = a-1
    a_a = a+1
    A_[a] +=1
    A_[a_b] +=1
    A_[a_a] +=1    

ans = 0
ans_idx = 0
for k in A_.keys():
    a = A_[k]
    if ans < a:
        ans = a
        ans_idx = k
        
# print(ans_idx,ans)
print(ans)

Submission status: Accepted

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

if n == 1:
    print(1)
    exit()

if len(set(a)) == 1:
    print(n)
    exit()

n_dict = {}
min_n = 10**9
max_n = 0
for i in range(n):
    t = a[i]
    if t in n_dict:
        n_dict[t] += 1
    else:
        n_dict[t] = 1
    
    max_n = max(t, max_n)
    min_n = min(t, min_n)

ans = 0
for x in range(min_n+1, max_n+1):
    tmp = 0
    if x-1 in n_dict: tmp += n_dict[x-1]
    if x in n_dict: tmp += n_dict[x]
    if x+1 in n_dict: tmp += n_dict[x+1]
    
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
from collections import Counter
d = Counter(a)
ans = 0
for key,val in d.items():
    ans = max(ans,d[key]+d[key-1]+d[key+1])
print(ans)

Submission status: Accepted

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

result_list = []
for a in l:
    result_list.extend([a-1,a,a+1])
    
result_list

import collections

count = collections.Counter(result_list) # dictionary としてCounter({5: 1, 1: 3, 3: 2, 2: 2, 4: 2})
hindo_jun = count.most_common() 

print(hindo_jun[0][1])

Submission status: Accepted

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

c = [0 for i in range(1+10**5)]

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

ans = 0
for i in range(1+10**5):
    if i==0:
        if ans < c[i]+c[i+1]:
            ans = c[i]+c[i+1]
    elif i==10**5:
        if ans < c[-2]+c[-1]:
            ans = c[-2]+c[-1]
    elif ans < c[i-1] + c[i] + c[i+1]:
        ans = c[i-1] + c[i] + c[i+1]

print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    As = list(map(int, input().split()))
    cnts = [0]*(10**5+2)
    for a in As:
        cnts[a] += 1
        cnts[a+1] += 1
        cnts[a+2] += 1
    ans = max(cnts)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
arr = [0] * 100002

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

print(max(arr))

Submission status: Accepted

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

i = 0
ans = 1
while True:
    cnt1 = 0
    cnt2 = 0
    while a[i + cnt1] == a[i]:
        cnt1 += 1
        cnt2 += 1
        if i + cnt1 == n:
            ans = max(ans, cnt1)
            break
    if i + cnt1 == n:
        break
    while a[i + cnt2] <= a[i] + 2:
        cnt2 += 1
        if i + cnt2 == n:
            break
    ans = max(ans, cnt2)
    i += cnt1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = [0] * 10**5
for v in a:
    cnt[v] += 1

res = 0
for i in range(10**5-2):
    res = max(res, cnt[i] + cnt[i+1] + cnt[i+2])

print(res)

Submission status: Accepted

Solution code:
import sys,collections
input = sys.stdin.readline

N = int(input())
a = list(map(int,input().split()))
ac = collections.Counter(a)
dc = sorted(ac.items(),key = lambda x:(-x[1],x[0]))

ans = 0
for i in range(len(dc)):
    key = dc[i][0]
    val = dc[i][1]
    if ans > 3*val:
        print(ans)
        exit()
    ans = max(ans,ac[key-1]+ac[key]+ac[key+1])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
C = [0]*(10**5)
for ai in A:
    C[ai] += 1

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

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
a_list = [int(x) for x in input().split()]
d = defaultdict(int)
for a in a_list:
    for i in range(-1, 2):
        d[a + i] += 1
print(sorted(d.values())[-1])

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
b = []
for i in a:
    b.append(i + 1)
    b.append(i)
    b.append(i - 1)
##辞書型 キーに要素、値に出現回数を出力
c = Counter(b)
##most_comonn (要素, 出現回数)という形のタプルを出現回数順に並べたリストを返す
##出現回数が最も多いものは[0],出現回数のみを出力するので[1]
print(c.most_common()[0][1])

Submission status: Accepted

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

count = [0]*(max(a)+1)
for i in a: count[i]+=1

if len(count) <= 2:
  print(sum(count))
  exit()
  
ans = 0
for i in range(2,max(a)):
  if count[i-1]+count[i]+count[i+1] > ans:
    ans = count[i-1]+count[i]+count[i+1]
print(ans)

Submission status: Accepted

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

a_count = collections.Counter(a)

total = 0
for i in a_count.keys():
    total = max(total,a_count[i-1] + a_count[i] + a_count[i+1])
print(total)

Submission status: Accepted

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

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

res = max(x)
print(res)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
b = []
for i in a:
  b.append(i+1)
  b.append(i)
  b.append(i-1)
c = Counter(b)
print(c.most_common()[0][1])

Submission status: Accepted

Solution code:


#import sys
#import os
#import re
#import datetime

N = int(input())
#print(input().split())
a = list(map(int, input().split()))
#print(a)
countA = {}
for v in a:
	for i in (-1,0,1):
		#print("i = {}".format(i))
		if(v - i in countA):
			countA[v - i] = countA[v - i] + 1
		else:
			countA[v - i] = 1
print(max(countA.values()))

#town = {}
#for _ in range(N):
#	S, P = input().split()
#	town[S] = int(P)
#
#sum2 = sum(town.values()) / 2
#for S, P in town.items():
#	if P > sum2:
#		print(S)
#		break
#else:
#	print('atcoder')

Submission status: Accepted

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

lis = sorted(lis)

count = [0]*100001

for i in range(n):
    count[lis[i]] += 1

ans = 0

for j in range(1,100000):
    t = count[j-1]+ count[j]+ count[j+1]
    ans = max(ans, t)
    
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

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

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    a = list(mi())
    l = [0]*(10**5)
    m = -1
    for i in range(N):
        l[a[i]] += 1
    for i in range(10**5-2):
        t = l[i]+l[i+1]+l[i+2]
        m = max(m, t)
    print(m)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(k) for k in input().split()]
cnt = [0]*(10**5+1)
for i in a:
  cnt[i] += 1
s = cnt[0] + cnt[1] + cnt[2]
ans = 1
for i in range(1,10**5):
  s = cnt[i-1] + cnt[i] + cnt[i+1]
  #print(s)
  ans = max(s,ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
lst=sorted(map(int,input().split()))

count=[0]*100001
for i in lst:
    if i==0:
        count[1]+=1
    else:
        count[i-1]+=1
        count[i]+=1
        count[i+1]+=1
        
print(max(count))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

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

if n >= 3:
    d = [0 for _ in range(100001)]
    for i in range(n):
        d[a[i]] += 1
    ans = 0 
    for i in range(100001-2):
        tmp = d[i] + d[i+1] + d[i+2]
        if ans <= tmp:
            ans = tmp 

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = 0
start, end = min(A), max(A) + 1
for v in range(start, end):
    ans = max(C[v - 1] + C[v] + C[v + 1], ans)
print(ans)

Submission status: Accepted

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

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

for x in a:
    num[x] += 1

ans = num[0] + num[1] + num[2]

for i in range(1, 10**5):
    tmp = num[i-1] + num[i] + num[i+1]
    if tmp > ans:
        ans = tmp

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

ans = 0
amin = min(a)
amax = max(a)
for x in range(amin, amax+1):
   ans = max(ans, c[x-1]+c[x]+c[x+1])

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict


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

    d = defaultdict(int)
    for aa in a:
        for i in range(-1, 2):
            d[aa+i] += 1

    ans = 0
    for k in d:
        if d[k] > ans:
            ans = d[k]

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

N=int(input())
A=np.array(list(map(int, input().split())))
L=np.zeros(10**5+1)
for i in range(N):
  L[A[i]]+=1

a_max=max(A)
ans=0

for i in range(10**5-1):
  ans=max(ans,L[i]+L[i+1]+L[i+2])
  if i==a_max:
    break
print(int(ans))

Submission status: Accepted

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

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

if len(nums) <= 2:
  print(sum(nums))
  exit()
  
ans = 0
for i in range(1,max(a)):
  if ans < nums[i-1] + nums[i] + nums[i+1]:
    ans = nums[i-1] + nums[i] + nums[i+1]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
a = list(map(int, input().split()))
ans = []
for x in a:
    ans += [x-1, x, x+1]
c = Counter(ans)
print(c.most_common()[0][1])

Submission status: Accepted

Solution code:
n = int(input())
lst = list(map(int, input().split()))
dic = {}
for i in range(n):
  a = lst[i]
  dic.setdefault(a - 1, 0)
  dic[a - 1] += 1
  dic.setdefault(a, 0)
  dic[a] += 1
  dic.setdefault(a + 1, 0)
  dic[a + 1] += 1
print(max(list(dic.values())))

Submission status: Accepted

Solution code:
input()
c=[0]*100002
for i in map(int,input().split()):
  for j in (0,1,2): c[i+j]+=1
print(max(c))

Submission status: Accepted

Solution code:
n,*l=map(int,open(0).read().split())
c=[0]*(10**5+3)
for i in l:
  for j in (-1,0,1): c[i+j]+=1
print(max(c))

Submission status: Accepted

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

for i in a:
    l[i] +=1
    l[i+1] +=1
    l[i+2] +=1

print(max(l))

Submission status: Accepted

Solution code:
# from pprint import pprint
import math

import collections

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

b = [[_a - 1, _a, _a + 1] for _a in a]

numbers = {}
for i in range(n):
    c = collections.Counter(b[i])

    for k, v in c.items():
        if k in numbers.keys():
            numbers[k] += 1
        else:
            numbers.update({k: 1})

ans = sorted(numbers.items(), key=lambda x: x[1], reverse=True)

print(ans[0][1])

Submission status: Accepted

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

l=[0]*((10**5)+2)

for v in a:
    l[v]+=1
    l[v+1]+=1
    l[v+2]+=1

print(max(l))

Submission status: Accepted

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

Submission status: Accepted

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

d=dict()

ans=0
count=0

from collections import defaultdict
d = defaultdict(lambda: 0, d)

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

p=0
while(p<100010):
    count=d[p-1]+d[p]+d[p+1]
    p=p+1
    if(count>ans):
        ans=count
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
am=max(a)
num=[0]*(am+1)
for i in a:
  num[i]+=1
#print(num)
mx=0
for i in range(1,am):
  #print(num[i-1:i+2])
  m=sum(num[i-1:i+2])
  if m>mx:
    mx=m
if len(num)<=3:
  mx=sum(num)
print(mx)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-06-26 15:12:37 +0900
# LastModified: 2020-06-26 15:33:28 +0900
#


import os
import sys
from collections import Counter
# import numpy as np
# import pandas as pd


def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    cnt_list = Counter(a)

    a_max = a[-1]
    a_min = a[0]
    cnt_max = 0
    for center in range(a_min-1, a_max+2):
        cnt = 0
        if center in cnt_list.keys():
            cnt += cnt_list[center]
        if center-1 in cnt_list.keys():
            cnt += cnt_list[center-1]
        if center+1 in cnt_list.keys():
            cnt += cnt_list[center+1]
        if cnt > cnt_max:
            cnt_max = cnt
    print(cnt_max)



if __name__ == "__main__":
    main()

Submission status: Accepted

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

r=0
l=0
ans=0
while r<n:
    if a[r]-a[l]<=2:
        if r-l+1>ans:
            ans=r-l+1
        r+=1
    else:
        l+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

l = [0] * 100002
for i in a:
    l[i+1] += 1
    l[i+2] += 1
    l[i] += 1
print(max(l))

Submission status: Accepted

Solution code:
from collections import Counter
n, *a = map(int, open(0).read().split())
l = Counter(a)
for ai in a:
    l[ai+1] += 1
    l[ai-1] += 1
print(l.most_common()[0][1])

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
if n == 1:
    print(1)
elif n == 2:
    if abs(a[0] - a[1]) <= 2:
        print(2)
    else:
        print(1)
else:
    d = {}
    for i in range(max(a) + 3):
        d[i] = 0
    for i in a:
        d[i] += 1
    ans = 1
    pre = 0
    for i in range(max(a) + 1):
        pre = d[i] + d[i + 1] + d[i + 2]
        if ans < pre:
            ans = pre
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = tuple(map(int, input().split()))
from collections import Counter
CA = Counter(A)

mc = 0
for x in range(1, 10**5):
    mc = max(mc, CA[x-1] + CA[x] + CA[x+1])
print(mc)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
Alist=[0]*(10**5+1)
for a in A:
    Alist[a]+=1
ans=1
for i in range(min(A),max(A)):
    ans=max(ans,Alist[i]+Alist[i+1]+Alist[i+2])
if min(A)==max(A):
    ans=n
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, *a = map(int, read().split())
cnt = [0] * (10 ** 5 + 10)

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

print(max(cnt))

Submission status: Accepted

Solution code:
def resolve():
    from collections import defaultdict
    N = int(input())
    A = [int(i) for i in input().split()]
    d = defaultdict(int)
    for a in A:
        d[a] += 1
    maxA = 0
    d = dict(d)
    for key in d.keys():
        sumA = d.get(key)
        if key - 1 in d:
            sumA += d.get(key - 1)
        if key + 1 in d:
            sumA += d.get(key + 1)
        maxA = max(maxA, sumA)
    print(maxA)

resolve()

Submission status: Accepted

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

for i in range(n):
    a_n.append(a[i])
    a_n.append(a[i]-1)
    a_n.append(a[i]+1)


counter=Counter(a_n)

print(a_n.count(counter.most_common()[0][0]))

Submission status: Accepted

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

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

Submission status: Accepted

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

count=[0 for _ in range(max(A)+1)]
for i in range(n):
  count[A[i]]+=1
  
answer=0
if n>3:
  for i in range(0,n-2):
    tmp=sum(count[i:i+3])
    if tmp>answer:
      answer=tmp
elif n==2:
  if len(count)>3:
    answer=1
  else:
    answer=2
elif n==1:
  answer=1

print(answer)

Submission status: Accepted

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

def main(n,a):
    hist=[0]*(10**5+1)
    for i in range(n):
        hist[a[i]]+=1
    
    max3=0
    for i in range(10**5-1):
        max3=max(max3,hist[i]+hist[i+1]+hist[i+2])
    return max3

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(ans)

Submission status: Accepted

Solution code:
from math import*
from bisect import*
import copy

n=int(input())
arr=list(map(int,input().split()))
arr.sort()
brr=copy.deepcopy(arr)
brr=list(set(brr))
brr.sort()
#print(arr)
#print(brr)
ans=0
#print(bisect_right(arr,6))
for i in range(len(brr)):
	d=bisect_left(arr,brr[i])
	c=bisect_right(arr,brr[i]+2)
#	print(d,c)
	if ans<c-d:
		ans=c-d
print(ans)

Submission status: Accepted

Solution code:
# Vicfred
# https://atcoder.jp/contests/abc072/tasks/arc082_a
# greedy, bucket sort
class Counter(dict):
    def __missing__(self, i):
        return 0

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

counter = Counter()

for item in a:
    counter[item] += 1
    counter[item+1] += 1
    counter[item-1] += 1

maxima = max(counter.values())

print(maxima)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

def main():
    n = int(input())
    a = Counter(map(int, input().split()))
    akeys = a.keys()
    mx = max(akeys)
    cnt = 0
    for i in akeys:
        c = a[i]
        if i+1 in akeys:
            c += a[i+1]
        if i+2 in akeys:
            c += a[i+2]
        cnt = max(cnt, c)
    print(cnt)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = 100002*[0]

for a in map(int,input().split()):
  A[a-1]+=1
  A[a]+=1
  A[a+1]+=1

print(max(A))

Submission status: Accepted

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

for a in map(int,input().split()):
  A[a-1]+=1
  A[a]+=1
  A[a+1]+=1

print(max(A))

Submission status: Accepted

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

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

print(max(B))

Submission status: Accepted

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

import collections
c = collections.Counter(a)
_max = 0
for i in range(max(a)+1):
  _sum = c[i-1] + c[i] + c[i+1]
  if _max < _sum:
    _max = _sum
print(_max)

Submission status: Accepted

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

import collections
c = collections.Counter(a)
ans = 0

if len(c) == 1:
  ans = list(c.values())[0]
else:
  for x in range(min(a),max(a)):
    ans_candidate = c[x] + c[x+1] + c[x+2]

    if ans < ans_candidate:
      ans = ans_candidate
print(ans)

Submission status: Accepted

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

cnt = Counter()
for a in A:
    cnt[a-1] += 1
    cnt[a]   += 1
    cnt[a+1] += 1

print(cnt.most_common(1)[0][1])

Submission status: Accepted

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

for i in a:
    x[i] += 1
    x[i+1] += 1
    x[i+2] += 1 
    
print(max(x))

Submission status: Accepted

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

for i in a:
    al[i] += 1
    al[i+1] += 1
    al[i+2] += 1

print(max(al))