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:
#abc072 c
n=int(input())
a=list(map(int,input().split()))
num=dict()

for i in a:
    x=i+1
    y=i-1
    if i not in num:
        num[i]=1
    else:
        num[i]+=1
    if x not in num:
        num[x]=1
    else:
        num[x]+=1
    if y not in num:
        num[y]=1
    else:
        num[y]+=1

ans=0
for i in num.values():
    ans=max(ans,i)
print(ans)

Submission status: Accepted

Solution code:
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)
B = sorted(B)

from collections import Counter
c = Counter(B)
print(c.most_common(1)[0][1])

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
count = 0
p1 = []
for i in range(n):
  p1.append(a[i]-1)
p2 = []
for i in range(n):
  p2.append(a[i]+1)
chk = a+p1+p2
chk.sort()
#print(chk)
ans =[]
count = 0
for i in range(3*n-1):
  if chk[i+1] == chk[i]:
    count += 1
  else:
    ans.append(count)
    count = 0
print(max(ans)+1)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()])
ans = 1
dic = {}
for i in range(10**5):
    dic[i] = 0
for i in a:
    dic[i] += 1
for i in range(1,10**5-1):
    ans = max(ans, dic[i-1] + dic[i] + dic[i+1])
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

B = A.copy()
B[1:] += A[:-1]
B[:-1] += A[1:]

answer = B.max()
print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
A=[0]*(10**5+1)
b=input().split()
numbers=[int(a) for a in b]
for a in numbers:
    A[a]+=1
list=[]
for z in range(10**5-1):
    y=A[z]+A[z+1]+A[z+2]
    list.append(y)
print(max(list))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
readline=sys.stdin.readline
n=int(readline())
aa=list(map(int,readline().split()))
laa=len(aa)
cnt=[0]*(10**5+2)
for n in range(laa):
  i=aa[n]
  if i > 0:
    cnt[i-1]+=1
  cnt[i]+=1
  cnt[i+1]+=1

ans=0

for _ in cnt:
  ans=max(ans,_)

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
res = 0
for i in range(1, 10**5):
    res = max(res, l[i-1]+l[i]+l[i+1])
print(res)

Submission status: Accepted

Solution code:
import collections

n = int(input())
A = list(map(int, input().split()))
Am = [x - 1 for x in A]
As = [x + 1 for x in A]
A.extend(Am)
A.extend(As)
c = collections.Counter(A)
print(c.most_common()[0][1])

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d=defaultdict(int)
MIN=10**10
MAX=0
for i in range(n):
    d[a[i]]+=1
    MIN=min(MIN,a[i])
    MAX=max(MAX,a[i])

ans=0
for g in range(MIN,MAX+1):
    ans=max(d[g-1]+d[g]+d[g+1],ans)
print(ans)

Submission status: Accepted

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

imos = [0] * (10 ** 5 + 10)

for i in range(N):
    l, r, s = a[i] - 1, a[i] + 1, 1
    l += 1
    r += 1
    # print(l, r)
    imos[l] += s
    imos[r + 1] -= s

for i in range(N + 1):
    imos[i + 1] = imos[i] + imos[i + 1]

# print(imos[: max(a) + 3])

print(max(imos[: max(a) + 3]))

Submission status: Accepted

Solution code:
n=int(input())
a= list(map(int, input().split()))
b=[0]*100001

for i in range(n):
    b[a[i]]+=1
ans=0
for i in range(99999):
    count=b[i]+b[i+1]+b[i+2]
    ans=max(count,ans)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
l=[0]*(10**5+1)
v=list(map(int,input().split()))
for i in range(n):
  x=v[i]
  if x==0:
    l[0]+=1
    l[1]+=1
  elif x==10**5:
    l[x-1]+=1
    l[x]+=1
  else:
    l[x-1]+=1
    l[x]+=1
    l[x+1]+=1
l.sort()
print(l[-1])

Submission status: Accepted

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

Submission status: Accepted

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

N = int(input())
a = list(map(int, input().split(' ')))
counts = {i: 0 for i in range(10**5)}
for ai in a:
    if (ai != 0): counts[ai-1] += 1
    counts[ai] += 1
    if (ai != 99999): counts[ai+1] += 1
ans = 0
for i in range(10**5):
    if counts[i] > ans:
        ans = counts[i]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
l = [0] * (10**5 + 2)
for x in a:
  l[x-1] += 1
  l[x] += 1
  l[x+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)
B = sorted(C.items())
t = max(C.values())
if len(B) < 3:
    for i in range(len(B)-1):
        m = B[i][1]
        if B[i+1][0] - B[i][0] < 3:
            m += B[i+1][1]
        if t < m:
            t = m
else:
    for i in range(len(B)-2):
        m = B[i][1]
        if B[i+1][0] - B[i][0] < 3:
            m += B[i+1][1]
        if B[i+2][0] - B[i][0] == 2:
            m += B[i+2][1]
        if t < m:
            t = m
print(t)

Submission status: Accepted

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
maxi = 0
for k,v in c.items():
  if k-1 in c:
    v += c[k-1]
  if k+1 in c:
    v += c[k+1]
  maxi = max(maxi,v)
print(maxi)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
d = list(c.keys())
q = 1
for i in range(1,len(d)-1):
	if d[i+1] - d[i] == 1 and d[i] - d[i-1] == 1:
		s = c[d[i-1]] + c[d[i]] + c[d[i+1]]
		q = max(q,s)
	if i == 1:
		if d[i] - d[i-1] == 1:
			s = c[d[i-1]] + c[d[i]]
			q = max(q, s)
	if d[i+1] - d[i] == 1:
		s = c[d[i+1]] - c[d[i]]
		q = max(q, s)
if len(d) == 1:
	q = c[d[0]]
if len(d) == 2:
	if d[1] - d[0] == 1:
		q = c[d[1]] + c[d[0]]
	else:
		q = max(1, c[d[1]], c[d[0]])
print (q)

Submission status: Accepted

Solution code:
from collections import Counter
import itertools


n = int(input())
l = list(map(int, input().split()))
l_2d = [[i-1, i, i+1] for i in l]
l_flatten = itertools.chain.from_iterable(l_2d)
l = list(l_flatten)
c = Counter(l)
ans = c.most_common()[0][1]
print(ans)

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    from collections import defaultdict
    dd = defaultdict(int)
    
    a=LI()
    for i in range(N):
        
        dd[a[i]]+=1
        dd[a[i]-1]+=1
        dd[a[i]+1]+=1
        
    ans=0
    for k,v in dd.items():
        ans=max(ans,v)
        
    print(ans)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=[-1,0]
i=0
while i<=n-1:
    res=0
    cnt=0
    while i+res<=n-1 and a[i+res]-a[i]<=2:
        if a[i+res]==a[i]:
            cnt+=1
        res+=1
    if res>ans[1]:
        ans[1]=res
        ans[0]=i
    i+=cnt
print(ans[1])

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
set_a = list(set(a))
#set_a = sorted(set_a)
count_a = Counter(a)

result = []
for i in set_a:
    result.append(count_a[i]+count_a[i-1]+count_a[i+1])
print(max(result))

Submission status: Accepted

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

result = []
for i in range(min(a),max(a)+1):
    result.append(count_a[i]+count_a[i-1]+count_a[i+1])
print(max(result))

Submission status: Accepted

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

d = {}

for i in data:
    if d.get(i) is None:
        d[i] = 1
    else:
        d[i] += 1
    if d.get(i+1) is None:
        d[i+1] = 1
    else:
        d[i+1] += 1
    if d.get(i-1) is None:
        d[i-1] = 1
    else:
        d[i-1] += 1

print(max(d.values()))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(_) for _ in input().split()]
numCnt = [0] * 100001
for i in a:
    numCnt[i] += 1
ans = 0
for i in range(1, 100000):
    ans = max(ans, numCnt[i-1] + numCnt[i] + numCnt[i+1])

print(ans)

Submission status: Accepted

Solution code:
import collections
N=int(input())
a=list(map(int, input().split()))
a.sort(reverse=True)
piv1=a[len(a)-1]    #最小
piv2=a[0]            #最大
#print(a)
max=0
c=collections.Counter(a)
value=list(c.values())
key=list(c.keys())
for i in range(piv1,piv2+1):
    #print(c[i],c[i+1],c[i+2])
    if max<c[i]+c[i+1]+c[i+2]:
        max=c[i]+c[i+1]+c[i+2]
print(max)

Submission status: Accepted

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

num = [0] * 100005
for i in range(N):
    num[a[i]] += 1
ans = 0
for i in range(100001):
    ans = max(ans, num[i-1] + num[i] + num[i+1])
print(ans)

Submission status: Accepted

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

d = [0] * (10**5)

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

ans = 1

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

print(ans)

Submission status: Accepted

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

d = [0]*(10**5+3)

for a in A:
    d[a-1] += 1
    d[a] += 1
    d[a+1] += 1
print(max(d))

Submission status: Accepted

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

alp1 = []
for a in al:
    alp1.append(a + 1)

alm1 = []
for a in al:
    alm1.append(a - 1)

ass = alm1 + al + alp1

d = {}
for i in ass:
    d.setdefault(i, 0)
    d[i] += 1

print(max(d.values()))

Submission status: Accepted

Solution code:
import collections as c
n = int(input())
a = [[int(x) - 1, int(x), int(x) + 1] for x in input().split()]
a = [a[i][j] for i in range(n) for j in range(3)]
l = c.Counter(a)
print(max(list(l.values())))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *a = map(int, read().split())
A = np.array(a)

counter = np.bincount(A)
B = counter.copy()
B[1:] += counter[:-1]
B[:-1] += counter[1:]

print(B.max())

Submission status: Accepted

Solution code:
import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *a = map(int, read().split())
a.sort()

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

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=Counter(a)
x=[(-2,0)]+sorted(c.items(), key=lambda x:x[0])+[(0,0)]
l=len(x)-1
ans=0
for i in range(1,l):
    cnt=x[i][1]
    if x[i+1][0]-x[i][0]==1:
        cnt+=x[i+1][1]
    if x[i][0]-x[i-1][0]==1:
        cnt+=x[i-1][1]
    ans=max(cnt,ans)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

n = int(input())
aList = list(map(int, input().split()))
num = collections.Counter(aList)
ans = 0
for x in range(10 ** 5):
    count = num[x - 1] + num[x] + num[x + 1]
    if ans < count:
        ans = count
print(ans)

Submission status: Accepted

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

max_count = 0

L = [0]*10**5
for i in A:
    L[i] += 1

for i in range(10**5+1):
    count = 0
    for j in range(-1,2):
        if i+j >= 0 and i+j < 10**5:
            count += L[i+j]
    max_count = max(count, max_count)
print(max_count)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = [0 for i in range(a[n-1]+2)]
for i in a:
    ans[i] += 1
    ans[i+1] += 1
    if i-1 > 0:
        ans[i-1] += 1
ans.sort()
print(ans[len(ans)-1])

Submission status: Accepted

Solution code:
n = int(input())
d = [0] * 100000
dat = list(map(int, input().split()))
for i in range(n):
    d[dat[i]] += 1
res = 1
for i in range(1, n - 1):
    res = max(res, d[i-1] + d[i] + d[i+1])
print(res)

Submission status: Accepted

Solution code:
N = int(input())
list_a = [int(x) for x in input().split()]

list_X = []

for X in list_a :
    list_X.append(X)
    list_X.append(X+1)
    list_X.append(X-1)

from collections import Counter
print(max(Counter(list_X).values()))

Submission status: Accepted

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

for i in a:
    x.append(i)
    x.append(i+1)
    x.append(i-1)

counter = Counter(x)
print(max(counter.values()))

Submission status: Accepted

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

def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    num_freq = collections.Counter(a_list)

    vals = []
    for X in set(a_list):
        v = 0
        if X in num_freq:
            v += num_freq[X]
        if X - 1 in num_freq:
            v += num_freq[X-1]
        if X + 1 in num_freq:
            v += num_freq[X+1]
        vals.append(v)
    print(max(vals))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    length = int(input())
    numbers = list(map(int, input().split()))
    count = [0] * 10 ** 5
    for num in numbers:
        count[num] += 1
    answer = 0
    for i in range(10 ** 5):
        answer = max(answer, sum(count[i:i + 3]))
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
x = Counter(a)
cnt = sorted(x.items(), key=lambda x: x[0], reverse=True)
ans = 0
for i in range(len(cnt)):
    x = cnt[i][1]
    if i != 0:
        if cnt[i][0] == cnt[i-1][0] - 1:
            x += cnt[i-1][1]
    if i != len(cnt) - 1:
        if cnt[i][0] == cnt[i+1][0] + 1:
            x += cnt[i+1][1]
    ans = max(ans, x)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
a = np.array(input().split(), np.int64)

h = {}
for i in range(len(a)):
    if a[i] - 1 not in h:
        h[a[i] - 1] = 0
    h[a[i] - 1] += 1
    if a[i] not in h:
        h[a[i]] = 0
    h[a[i]] += 1
    if a[i] + 1 not in h:
        h[a[i] + 1] = 0
    h[a[i] + 1] += 1
print(max(h.values()))

# -1, 0, 1, ..., 100001
# 3 1 4 1 5 9 2
#  0 ..
#  1 ...
#  2 ....
#  3 ...
#  4 ...
#  5 ..
#  6 .
#  7
#  8 .
#  9 .
# 10 .

# print(a)

Submission status: Accepted

Solution code:
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
cnt=defaultdict(lambda :0)

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

print(max(cnt.values()))

Submission status: Accepted

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


N = int(input().strip())
a_list = list(map(int, input().rstrip().split()))
#----------
a_set=set(a_list)
count_dic={}
for X in a_set:
    count_dic[str(X)] = 0
    count_dic[str(X+1)] = 0
    count_dic[str(X-1)] = 0

count = 0
for X in a_list:
    count_dic[str(X)] += 1
    count_dic[str(X+1)] += 1
    count_dic[str(X-1)] += 1
    
print(max(count_dic.values()))

Submission status: Accepted

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

d={}
for i in range(n):
    d[a[i]-1] = d.get(a[i]-1,0)+1
    d[a[i]] = d.get(a[i],0)+1
    d[a[i]+1] = d.get(a[i]+1,0)+1
print(max(d.values()))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

from collections import defaultdict
d=defaultdict(int)

for num in a:
        if num!=0:
                d[num-1]+=1
        d[num]+=1
        d[num+1]+=1

ans=0
for k,v in d.items():
        if v> ans:
                ans=v
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(n):
  if a[i]!=0:
    b[a[i]]+=1
    b[a[i]-1]+=1
    b[a[i]+1]+=1
  else:
    b[a[i]]+=1
    b[a[i]-1]+=0
    b[a[i]+1]+=1
print(max(b))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(max(ans))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
dic = {}
for a in A:
  if a in dic:
    dic[a] += 1
  else:
    dic[a] = 1
  if a-1 in dic:
    dic[a - 1] += 1
  else:
    dic[a - 1] = 1
  if a + 1 in dic:
    dic[a + 1] += 1
  else:
    dic[a + 1] = 1
m = 0
for v in dic.values():
  if m < v:
    m = v
print(m)

Submission status: Accepted

Solution code:
def together(n , a):

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

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

    return max(listans)


def main():
    n = int(input())
    a = list(map(int,input().split()))
    print(together(n , a))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
N=int(input())
A=list(map(int,input().split()))
F=[0]*(10**5+1)

for i in range(N):
    if A[i]==0:
        F[0]+=1
        F[1]+=1
    else:
        F[A[i]-1]+=1
        F[A[i]]+=1
        F[A[i]+1]+=1
        
print(max(F))

Submission status: Accepted

Solution code:
from collections import Counter

s = [0] * int(input()) * 3
for i, si in enumerate(map(int, input().split())):
    s[3 * i + 0] = si
    s[3 * i + 1] = si - 1
    s[3 * i + 2] = si + 1
print(Counter(s).most_common(1)[0][1])

Submission status: Accepted

Solution code:
N = int(input())
a_lst = [int(x) for x in input().split()]

dict = {}

for a in a_lst:
    if not a - 1 in dict.keys():
        dict[a - 1] = 1
    else:
        dict[a - 1] += 1
    if not a in dict.keys():
        dict[a] = 1
    else:
        dict[a] += 1
    if not a + 1 in dict.keys():
        dict[a + 1] = 1
    else:
        dict[a + 1] += 1
val_lst = list(dict.values())
val_lst.sort(reverse=True)
print(val_lst[0])

Submission status: Accepted

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

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

print(max(l))

Submission status: Accepted

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

# ある値がaに存在するとき、その＋ー1の値を足す
## ans_list[-1]となる場合向けにlistは1個余分に値を設けておく
ans_list = [0] * (10 ** 5 + 2)

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

ans = max(ans_list)

print(ans)

Submission status: Accepted

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

for n in range(N):
  list_[A[n]] += 1

ans = 0
for n in range(0,len(list_)-2):
  _ = list_[n-1] + list_[n] + list_[n+1]
  ans = max(ans,_)

print(ans)

Submission status: Accepted

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

ans = 0
for i in l:
  a = bisect.bisect_right(l,i+1)-bisect.bisect_left(l,i-1)
  ans = max(ans,a)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = np.array(input().split(), dtype = np.int64)

counter = np.bincount(a)
b = counter.copy()
b[1:] += counter[:-1]
b[:-1] += counter[1:]

ans = b.max()
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
Ac = Counter(A)
setA = list(set(A))
r = 0
for i in range(len(setA)):
    r = max(r, Ac[setA[i]-1]+Ac[setA[i]]+Ac[setA[i]+1])
print(r)

Submission status: Accepted

Solution code:
from collections import Counter
from operator import itemgetter

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

for i in range(len(A)):
    A.append(A[i]+1)
    A.append(A[i]-1)

B = Counter(A)
B = list(B.items())
B1 = sorted(B,key=itemgetter(1),reverse = True)  
#print(B1)
print(B1[0][1])

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)

a_count=collections.Counter(a)
print(max(a_count.values()))

Submission status: Accepted

Solution code:
import bisect
n = int(input())
lst1 = list(map(int,input().split()))

lst1.sort()

p = 0
ans = 1
if n == 1:
    print(1)
    exit()
while True:
    left = bisect.bisect_left(lst1,p)
    right = bisect.bisect_right(lst1,p+2)
    ans = max(ans,right-left)
    if right>=n:
        break
    p = max(p+1,lst1[left+1])
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
a = input()
a_list = list(map(int, input().split()))
ans = 0
b_list = []
c_list = []

for i in a_list:
    b_list.append(i+1)
    c_list.append(i-1)

ans_list = a_list + b_list + c_list
counter = Counter(ans_list)
print(counter.most_common()[0][1])

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)

c = collections.Counter(a)
print(c.most_common()[0][1])

Submission status: Accepted

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

ans = 0
x = dict()
#O(N)
for i in range(N):
    if a[i] in x:
        x[a[i]] += 1
    else:
        x[a[i]] = 1
    if (a[i]-1) in x:
        x[a[i]-1] += 1
    else:
        x[a[i]-1] = 1
    if (a[i]+1) in x:
        x[a[i]+1] += 1
    else:
        x[a[i]+1] = 1
for idx in x:
    ans = max(ans,x[idx])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
a = list(map(int,input().split()))
b = []
c = []
for i in range(len(a)):
	b.append(a[i]+1)
for i in range(len(a)):
	c.append(a[i]-1)
a += b + c
counter = Counter(a)
#print(counter.most_common()[0][0])
print(a.count(counter.most_common()[0][0]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

N = int(input())
a_n = [int(i) for i in input().split()]
ans = []
for i, a_i in enumerate(a_n):
    ans.extend([a_i-1, a_i, a_i+1])
c = collections.Counter(ans)
print(c.most_common()[0][1])

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)
c = collections.Counter(a)
print(c.most_common()[0][1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

def solve(n, A):
    count = defaultdict(int)
    for a in A:
        count[a - 1] += 1
        count[a] += 1
        count[a + 1] += 1
    return max(count.values())

_n = int(input())
_A = list(map(int, input().split()))
print(solve(_n, _A))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int,input().split()))
cnt = [0]*(10**5)
for i in a:
    cnt[i] += 1
ans_max =0
for i in range(100000-2):
    #ans_max = max(ans_max,sum(cnt[i:i+3]))
        ans_max = max(ans_max,cnt[i]+cnt[i+1]+cnt[i+2])

print(ans_max)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
    d[a-1] = d.setdefault(a-1,0) + 1
    d[a] = d.setdefault(a,0) + 1
    d[a+1] = d.setdefault(a+1,0) + 1
print(max(d.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.extend([i-1,i,i+1])
ans = Counter(c).most_common()
print(ans[0][1])

Submission status: Accepted

Solution code:
# 2020/02/01
# AtCoder Beginner Contest 072 - C

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

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

# Count

for i in range(n):
    for j in range(-1, 2):
        wk_val = a[i] + j
        if wk_val < 0:
            wk_val = 10**5 + 1

        cntlist[wk_val] = cntlist[wk_val] + 1

ans = max(cntlist)

# Output
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

dList = sorted(list(map(int,input().split())))
dic = {}

for i in dList:
  
  if str(i) in dic.keys():
    dic[str(i)] += 1
  else:
    dic[str(i)] = 1
  if str(i+1) in dic.keys():
    dic[str(i+1)] += 1
  else:
    dic[str(i+1)] = 1
  
  if i-1 >= 0:
    if str(i-1) in dic.keys():
      dic[str(i-1)] += 1
    else:
      dic[str(i-1)] = 1
 
print(max(dic.values()))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = [0 for i in range(a[n-1]+2)]
for i in a:
    ans[i] += 1
    ans[i+1] += 1
    if i-1 > 0:
        ans[i-1] += 1
ans.sort()
print(ans[len(ans)-1])

Submission status: Accepted

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

def main():
    input()
    A = [int(c) for c in input().split()]

    c = Counter(A)
    c_ = c.copy()

    for i, n in c.items():
        c_[i-1] += n
        c_[i+1] += n

    print(max(c_.values()))

main()

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
ans=0
for i in range(1,10**5+1):
    ans=max(ans,l[i-1]+l[i]+l[i+1])

print(ans)

Submission status: Accepted

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

from collections import defaultdict

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

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

print(max(cnt.values()))

Submission status: Accepted

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

for i in range(n):
  x = a[i]
  if x not in result:
    result[x] = 1;
  else:
    result[x] = result[x] + 1;

  y = x + 1
  if y not in result:
    result[y] = 1;
  else:
    result[y] = result[y] + 1;

  z = x - 1
  if z not in result:
    result[z] = 1;
  else:
    result[z] = result[z] + 1;

print(max(result.values()))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
    d[a - 1] = d.setdefault(a - 1, 0) + 1
    d[a] = d.setdefault(a, 0) + 1
    d[a + 1] = d.setdefault(a + 1, 0) + 1

print(max(d.values()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

ans = Counter(c).most_common()

print(ans[0][1])

Submission status: Accepted

Solution code:
N = int(input())

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

# max_x = max(numbers) + 1
# max_x = int(sum(numbers) / len(numbers))
# res = 0
test = set()
for n in numbers:
    test.add(n)
    test.add(n - 1)
    test.add(n + 1)
length = len(test)
res = {}
# print(test)
# for i in range(max_x + 1):
for n in numbers:
    c = 0
    sub = set([n - 1, n, n + 1]) & test
    # print(sub)
    for s in sub:
        if res.get(s) is None:
            res[s] = 1
        else:
            res[s] += 1
# for i in test:
#     c = 0
#     for n in numbers:
#         if n - 1 == i or n == i or n + 1 == i:
#             c += 1
#     if res < c:
#         res = c

# print(res)
res = max(res.values())
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
pl = [0]*100005

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

for i in range(1,100004):
    pl[i] += pl[i-1]

print(max(pl))