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

t = [0] * (10 ** 5 + 3)  # t[X + 1] は ai = X となる i の個数
for x in a:
    for i in range(x - 1, x + 2):
        t[i] += 1
print(max(t))

Submission status: Accepted

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

t = [0] * (10 ** 5 + 3)  # t[X + 1] は ai = X となる i の個数
for x in a:
    t[x] += 1
    t[x + 3] -= 1

for i in range(1, 10 ** 5 + 3):
    t[i] += t[i-1]

print(max(t))

Submission status: Accepted

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

arr=[]
for i in a:
    arr.extend([i-1,i,i+1])

arr_c=collections.Counter(arr)

print(max(arr_c.values()))

Submission status: Accepted

Solution code:
from collections import Counter

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

Submission status: Accepted

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

from collections import Counter 

c = Counter(As)

ans = 0

for x in c.keys():
  tmp = c[x-1] + c[x] + c[x+1]
  ans = max(tmp, ans)
  
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
dp = np.array([0]* 100010)
for j in map(int,input().split()):
    dp[j] += 1;dp[j+1] += 1;dp[j+2] += 1
print(np.max(dp))

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
dp = np.array([0]* 100010)
for i,j in enumerate(map(int,input().split())):
    if j -1 < 0: dp[j] += 1;dp[j+1] +=1
    else:dp[j] += 1;dp[j-1] += 1;dp[j+1] += 1
print(np.max(dp))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import collections

n = int(input())
a = list(map(int, input().split()))
li = collections.Counter(a)
ans = 0
for i in li:
    ans = max(ans, li[i]+li[i+1]+li[i+2])
print(ans)

Submission status: Accepted

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

for key in a:
    d[key] += 1

cnt = 0
for i in d:
    d1 = 0
    d2 = 0
    if (i - 1) in d:
        d1 = d[i - 1]
    if (i + 1) in d:
        d2 = d[i + 1]

    cnt = max(cnt, d[i] + d1 + d2)

print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
c = Counter(A)

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
A = list(map(int,input().split()))
Cou = collections.Counter(A)
Ite = list(Cou.items());Ite.sort()
ans = 0
for i in range(len(Ite)):
    num = Ite[i][0];cou = Ite[i][1]
    if i > 0 and Ite[i-1][0] == num-1:
        cou += Ite[i-1][1]
    if i < len(Ite)-1 and Ite[i+1][0] == num+1:
        cou += Ite[i+1][1]
    ans = max(ans,cou)
print(ans)

Submission status: Accepted

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

Solution code:
from collections import Counter

N = int(input())
a = list(map(int, input().split()))
ac = Counter(a)
ans = 0

for i in ac.keys():
    ans = max(ans, ac[i] + ac[i + 1] + ac[i - 1])

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
a = list(map(int, input().split()))
ac = Counter(a)
ak = list(ac.keys())
ans = 0

for i in ak:
    ans = max(ans, ac[i] + ac[i + 1] + ac[i - 1])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(max(count))

Submission status: Accepted

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

Submission status: Accepted

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

n = int(input())
l = list(map(int, input().split()))
allx = [0 for _ in range(-1, 10**5+1)]

for value in l:
    allx[value+2] += 1
    allx[value+1] += 1
    allx[value] += 1

print(max(allx))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
L = [0] * (10 ** 5 + 4)
for a in A:
  L[a] += 1
  L[a + 3] -= 1

s = 0
for i, l in enumerate(L):
  s += l
  L[i] = s
  
print(max(L))

Submission status: Accepted

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

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

print(max(ary))

Submission status: Accepted

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

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

Submission status: Accepted

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

last = None
d = {}
for i in a:
  if last != i:
    d[i] = 1
    last = i
  else:
    d[i] += 1

out = -1
for x in range(a[0], a[-1]+1):
  s = 0
  if x-1 in d.keys():
    s += d[x-1]
  if x in d.keys():
    s += d[x]
  if x+1 in d.keys():
    s += d[x+1]
  if out < s:
    out = s
  
print(out)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(a_s)
c = sorted(c.items(), key=lambda x:x[0])
a_unique, a_counts = zip(*c)

ans = 0
for i,a in enumerate(a_unique):
    val = a_counts[i]
    if (i>0):
        if (a_unique[i-1]+1==a):
            val += a_counts[i-1]
            
    if (i<len(a_unique)-1):
        if (a_unique[i+1]-1==a):
            val += a_counts[i+1]
    
    if val > ans:
        ans = val
        
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
S=sorted(Counter(A).most_common())
if len(S)==1:
	print(S[0][1])
else:
	S.insert(0,(-2,0))
	S.append((-2,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: Accepted

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)

x = Counter(num).most_common()[0][1]
print(x)

Submission status: Accepted

Solution code:
import collections

n = int(input())
counter = collections.Counter()
ls = list(map(int, input().split()))
for k in ls:
    counter[k] += 1
res = 0
for key in sorted(counter.keys()):
    res = max(res, counter[key - 1] + counter[key] + counter[key + 1])
print(res)

Submission status: Accepted

Solution code:
import sys
import math
from fractions import gcd
# import queue
from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N = int(sys.stdin.readline())
L = list(map(int, sys.stdin.readline().split()))

LM = list(map(lambda x : x - 1, L))
LP = list(map(lambda x : x + 1, L))

X = LM + L + LP
# print(LM)
# print(L)
# print(LP)
Xc = Counter(X)
# print(Xc.most_common())
print(Xc.most_common()[0][1])

Submission status: Accepted

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)+1):
    ans = max(ans, c[x-1] + c[x] + c[x+1])
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
lcount=[]
count=0
now=l[0]
for i in range(n):
  if now==l[i]:
    count+=1
  else:
    lcount.append([count,now])
    count=1
    now=l[i]
lcount.append([count,now])
if len(lcount)==1:
  print(n)
elif len(lcount)==2:
  l1=lcount[0][0]
  l2=lcount[1][0]
  if lcount[1][1]-lcount[0][1]==1:
    print(l1+l2)
  else:
    print(max(l1,l2))
else:
  count=0
  for i in range(1,len(lcount)-1):
    scount=0
    scount+=lcount[i][0]
    if lcount[i][1]-lcount[i-1][1]==1:
      scount+=lcount[i-1][0]
    if lcount[i][1]-lcount[i+1][1]==-1:
      scount+=lcount[i+1][0]
    if scount>count:
      count=scount
  count1=lcount[0][0]
  if lcount[1][1]-lcount[0][1]==1:
    count1+=lcount[1][0]
  count2=lcount[-1][0]
  if lcount[-2][1]-lcount[-1][1]==-1:
    count2+=lcount[-2][0]
  print(max(count,count1,count2))

Submission status: Accepted

Solution code:
import collections

num = int(input())
s = sorted(list(map(int, input().split())))
if num == 1:
    print(1)
else:
    c = collections.Counter(s)
    max_ans = 0
    for i in range(num):
        start = s[i]
        current_ans = c[start]+c[start+1]+c[start+2]
        max_ans = max(current_ans,max_ans)
        i += c[start]
    print(max_ans)

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
a = III()

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
ans = 0
from collections import defaultdict
D = defaultdict(int)
for i in A:
    D[i] += 1
for i in range(10**5+1):
    tmp = D[i-1]+D[i]+D[i+1]
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict


def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(int)
    for ai in a:
        for i in range(ai - 1, ai + 2):
            d[i] += 1
    m = max(d.items(), key=lambda x: x[1])
    print(m[1])


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

from collections import Counter

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

c = Counter(a)

st = set()
for key in c.keys():
    for i in (-1, 0, 1):
        st.add(key + i)

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

print(ans)

Submission status: Accepted

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

from collections import Counter

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

c = Counter(a)
keys = c.keys()

st = set()
for key in keys:
    for i in (-1, 0, 1):
        st.add(key + i)

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

print(ans)

Submission status: Accepted

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):
    temp = d[i][1]
    if d[i-1][0] + 1 == d[i][0]:
        temp += d[i-1][1]
    if d[i+1][0] == d[i][0] + 1:
        temp += d[i+1][1]
    ans = max(ans, temp)

print(ans)

Submission status: Accepted

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

if L<=2:
    print(sum(b))
else:    
    for p in range(L-2):
        ans = max(ans,b[p]+b[p+1]+b[p+2])

    print(ans)

Submission status: Accepted

Solution code:
# sys.stdin.readline
import collections
import sys

input = sys.stdin.readline


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

        cnt = collections.Counter(a)

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


# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import collections

input = sys.stdin.readline

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

l = collections.Counter(a)

points = 0

for i in l.keys():
    cnt = l[i] + l[i-1] + l[i+1]
    if points < cnt: points=cnt

print(points)

Submission status: Accepted

Solution code:
input();d={}
for a in map(int,input().split()):
 for i in[-1,0,1]:d[a+i]=d.get(a+i,0)+1
print(max(d.values()))

Submission status: Accepted

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] <= key[i]+2:
			tmp += val[i+1]
	else:
		tmp += val[i]

	ans = max(tmp, ans)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))
    
    d = {}
    for i in range(N):
        if a[i] in d.keys():
            d[a[i]] += 1
        else:
            d[a[i]] = 1
        
        if a[i] + 1 in d.keys():
            d[a[i] + 1] += 1
        else:
            d[a[i] + 1] = 1
        
        if a[i] - 1 in d.keys():
            d[a[i] - 1] += 1
        else:
            d[a[i] - 1] = 1
    
    d_new = sorted(d.items(), key=lambda x: x[1])
    print(d_new[-1][1])

Submission status: Accepted

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

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

    MAX = int(1e5)
    count = [0] * (MAX + 1)

    for t in a:
        if t > 0:
            count[t-1] += 1
        if t < MAX:
            count[t+1] += 1
        count[t] += 1
    
    max_ = count[0]
    for i in range(1, MAX+1):
        max_ = max(max_, count[i])
    print(max_)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

dic = Counter(a)
for i,j in list(dic.items()):
    if i-1 in dic:
        dic[i-1]+=j
    elif i-1 not in dic:
        dic[i-1]=j
    if i+1 in dic:
        dic[i+1]+=j
    elif i+1 not in dic:
        dic[i+1]=j

print(max(dic.values()))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input().strip())
counter = Counter()
for i in list(map(int, input().strip().split(' '))):
  counter[i-1] += 1
  counter[i] += 1
  counter[i+1] += 1

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

Submission status: Accepted

Solution code:
from collections import*
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
a=Counter(a)
cnt=1
for i in range(min(a),max(a)+1):
	cnt_=a[i-1]+a[i]+a[i+1]
	if cnt_>cnt:cnt=cnt_
print(cnt)

Submission status: Accepted

Solution code:
import collections

N = int(input())
a = list(map(int,input().split()))
b = collections.Counter(a)
dp = [0] * (max(a)+1)
if len(b) == 1 and a[0] == 0:
    print(N)
    exit()
dp[0] = b[0] + b[1]
dp[1] = dp[0] + b[2]

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

Submission status: Accepted

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()
c = Counter(li)
ans = 1
for k in c.keys():
    ct = c[k] + c[k - 1] + c[k + 1]
    ans = max(ans, ct)
print(ans)

Submission status: Accepted

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

def main():
    N = int(input())
    a = list(map(int,input().split()))
    max_a = max(a)
    count = [0 for _ in range(max_a+1)]
    c = collections.Counter(a)
    c = list(c.items())

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

    elif len(c) == 2:
        if abs(c[0][0]-c[1][0]) <= 2:
            print(c[0][1]+c[1][1])
        else:
            print(max(c[0][1],c[1][1]))

    else:
        for i in range(len(c)):
            count[c[i][0]] = c[i][1]

        sum_list = [0 for _ in range(len(count)-2)]
        for i in range(len(count)-2):
            sum_list[i] = count[i]+count[i+1]+count[i+2]
        print(max(sum_list))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

X = [0] * (max(A) + 3)

for i in A:
    for j in range(3):
        X[i+j] += 1

print(max(X))

Submission status: Accepted

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

C = [0] * (max(A) + 3)

for i in A:
    for j in range(3):
        C[i+j] += 1
print(max(C))

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

ans = 0
n = inp()
a = inpl()
d = defaultdict(int)

for key in a:
    d[key] += 1
    d[key+1] += 1
    d[key-1] += 1
for i in d:
    ans = max(ans, d[i]) 
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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
for i in range(len(set(a))):
  num = cand_list[i][0]
  count = cand[num] + cand[num + 1] + cand[num - 1]
  ans = max(ans,count)

print(ans)

Submission status: Accepted

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)+1):
    cnt = dic[i-1]+dic[i]+dic[i+1]
    ans = max(ans,cnt)
print(ans)

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

import collections

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

c = collections.Counter(A)

ans = 0
for a in A:
    tmp = c[a-1] + c[a] + c[a+1]
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if len(a_list) == 1:
    print(a_list[-1])
    exit()

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

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

Submission status: Accepted

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

from collections import defaultdict
dic = defaultdict(int)

for a in A:
  dic[a-1]+=1
  dic[a  ]+=1
  dic[a+1]+=1
print(max(dic.values()))

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
Ns = [0]*100005
for A in As:
  Ns[A-1] += 1
  Ns[A] += 1
  Ns[A+1] += 1
r = max(Ns)
print(r)

Submission status: Accepted

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=j+1
        elif i+1<=a[j]<=i+2:
            t+=1
        else:
            break
    if t>M:
        M=t
print(M)

Submission status: Accepted

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

adict = {}
for i in alist:
	if str(i) in adict:
		adict[str(i)]+=1
	else:
		adict[str(i)]=1
	if str(i-1) in adict:
		adict[str(i-1)]+=1
	else:
		adict[str(i-1)]=1
	if str(i+1) in adict:
		adict[str(i+1)]+=1
	else:
		adict[str(i+1)]=1
print(max(adict.values()))

Submission status: Accepted

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:
    if(len(a) == 2 and abs(max(a)-min(a))<=1):
        print(2)
    else:
        print(1)

Submission status: Accepted

Solution code:
from itertools import chain
from collections import Counter
n=int(input())
As=list(map(int,input().split()))
As = [[a-1, a, a+1] for a in As]
As = list(chain.from_iterable(As))

result_cntr = Counter(As).most_common()
print(result_cntr[0][1])

Submission status: Accepted

Solution code:
from collections import defaultdict

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

counter = defaultdict(int)
for i in range(N) :
    counter[a[i]-1] += 1
    counter[a[i]] += 1
    counter[a[i]+1] += 1

print(max(counter.values()))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    d = dict()
    for a in A:
        d[a] = d.get(a, 0) + 1
        d[a+1] = d.get(a+1, 0) + 1
        d[a-1] = d.get(a-1, 0) + 1

    max_count = 0
    for a in d:
        if d[a] > max_count:
            max_count = d[a]
    return max_count




if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    # 1 足したとき
    count = defaultdict(int)
    for aa in a:
        count[aa] += 1
        count[aa+1] += 1
        count[aa-1] += 1
    v = 0
    for k in count.keys():
        v = max(count[k], v)
    print(v)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = [int(s) for s in input().split()]
c = Counter(A)
ans = max([c[k-1] + c[k] + c[k+1] for k in c.keys()])
print(ans)

Submission status: Accepted

Solution code:
import collections

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

dict = collections.Counter(a)

x_max = 0
#mem_key = ""

for key in dict.keys():
  k = int( key )
  x_max = max(x_max, dict[str(k-1)]+dict[str(k)]+dict[str(k+1)])

    
print(x_max)

Submission status: Accepted

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

Solution code:
# https://atcoder.jp/contests/abc072/tasks/arc082_a
# C - Together
import itertools
import collections

n = int(input().split()[0])
a_list = list(map(int, input().split()))

a_op_list = [[a-1, a, a+1] for a in a_list]
a_op_list = itertools.chain.from_iterable(a_op_list)
c = collections.Counter(a_op_list)
max_count = max(c.values())

print(max_count)

Submission status: Accepted

Solution code:
nums = int(input())
ary  = list(map(int,input().split()))
count =0
max_count = 0
ary.sort()
ary_count = [0 for i in range(100005)]
ary_count.append(0)

for i in ary:
    ary_count[i] += 1

for i in range(1,100005):
    count += ary_count[i]
    count += ary_count[i+1]
    count += ary_count[i-1]
    if count > max_count:
        max_count = count
    count = 0
print(max_count)

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N = _I()
A = LI()

"""
最小値から最大値
の間には絶対収まる
1111155なら1でいい
なら、
各数字のカウントを保持する
"""
char_counts = [0]*(10**5+5)

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

#  print(char_counts[:10])

ans = 0
for i in range(min(A), max(A)+1):
    ans = max(ans, char_counts[i] + char_counts[i-1] + char_counts[i+1])
print(ans)

Submission status: Accepted

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

max=0
for i in range(100002):
    if max<B[i-1]+B[i]+B[i+1]:
        max=B[i-1]+B[i]+B[i+1]
print(max)

Submission status: Accepted

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(a[0][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: Accepted

Solution code:
n = int(input())
d = {}
arr = list(map(int,input().split()))
for a in arr:
    if a-1 not in d:
        d[a-1] = 1
    else:
        d[a-1]+=1
    if a not in d:
        d[a] = 1
    else:
        d[a] += 1

    if a+1 not in d:
        d[a+1] = 1
    else:
        d[a+1] += 1

# print(d)
print(max(d.values()))

Submission status: Accepted

Solution code:
#入力
n=int(input())
A=list(map(int,input().split()))
#答え
ans=0

#空のリスト作成
b=[0]*(10**5+1)

#与えられた数列Aに含まれる数aiの順番にあるリストｂiを+１して、aiの個数のリストにする。
for i in A:
    b[i]+=1

#0から最大の10＊＊5まで調べる。ある数の前後プラス・マイナス１に含まれる数の個数が
#最大になるものを探す。それをXとすれば、答えが最大となる。
for i in range(10**5+1):
    if ans < sum(b[i:i+3]):
        ans=sum(b[i:i+3])

print(ans)

Submission status: Accepted

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

from collections import Counter

def main(N,A):
    A = Counter(A)
    elements = set(A)
    ans = 0
    
    for i in elements:
        tmp = A[i]
        if(i+1 in elements):
            tmp += A[i+1]
        if(i+2 in elements):
            tmp += A[i+2]
        ans = max(ans, tmp)

    print(ans)

if __name__ == '__main__':
    N = int(input())
    A = [int(a) for a in input().split()]
    main(N,A)

Submission status: Accepted

Solution code:

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

ans_list = [ 0 for i in range(10**5+2) ]

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

print(max(ans_list))

Submission status: Accepted

Solution code:
from collections import Counter

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

a_dict = Counter(a_list)

new_a_dict = {}

for k,v in a_dict.items():
    for diff in [-1,0,1]:
        if k+diff in new_a_dict:
            new_a_dict[k+diff] += v
        else:
            new_a_dict[k+diff] = v

print(max(new_a_dict.values()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import*;b=bisect;n,a=open(0);*a,=sorted(map(int,a.split()));print(max(b(a,i)-b(a,i-3)for i in range(10**5)))

Submission status: Accepted

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