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

a.sort()
ans = 0
num = [0] * int(3e5)
for i in a:
    num[i] += 1

for i in range(int(2e5)):
    check = sum(num[i:i+3])
    ans = max(ans, check)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in a:
    c[i] += 1
    if i != 0 and i != 10 ** 5:
        c[i-1] += 1
        c[i+1] += 1
    elif i == 0:
        c[i+1] += 1
    else:
        c[i-1] += 1

print(max(c))

Submission status: Accepted

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

lst = [0 for _ in range(max(a)+3)]
for x in a:
    lst[x] += 1
    lst[x+1] += 1
    lst[x+2] += 1
print(max(lst))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
Min = min(a)-1
Max = max(a)+1
ans = [0 for i in range(Min, Max+1)]

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

Submission status: Accepted

Solution code:
n=int(input())
d=dict()
for i in map(int,input().split()):
  if i not in d:
    d[i]=1
  else:
    d[i]+=1
  if i-1 not in d:
    d[i-1]=1
  else:
    d[i-1]+=1
  if i+1 not in d:
    d[i+1]=1
  else:
    d[i+1]+=1
print(max(d.values()))

Submission status: Accepted

Solution code:
import sys
fastinput=sys.stdin.readline
N=int(input())
bucket=[0]*(10**5+2)
A=[int(_) for _ in fastinput().split()]
for a in A:
    bucket[a-1]+=1
    bucket[a]+=1
    bucket[a+1]+=1
print(max(bucket))

Submission status: Accepted

Solution code:
import collections

N = int(input())
A = list(map(int, input().split()))
A.sort()
A = A+[i + 1 for i in A]+[i - 1 for i in A]
c = collections.Counter(A)
ans = max(c.values())
print(ans)

Submission status: Accepted

Solution code:
import itertools

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

aggregated_a = {x: sum(1 for _ in iter) for (x, iter) in itertools.groupby(sorted(a))}
counts = [aggregated_a[a_i] if a_i in aggregated_a else 0 for a_i in range(100000)]
print(max(sum(counts[a_i - 1 : a_i + 2]) for a_i in range(100000)))

Submission status: Accepted

Solution code:
n = int(input())

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

d = {}

for i in a:
  for j in range(i - 1, i + 2): #aの値の両隣まで
    d[j] = d.get(j, 0) + 1#getは第一引数で指定したキーがなかったら第二引数で指定した値を戻す
    
    
print(max(d.values()))

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math

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

a.sort()

counts = {}
for i in range(N):
    if a[i] in counts.keys():
        counts[a[i]] += 1
    else:
        counts[a[i]] = 1

counts_list = []
tmp = 0
for num in range(max(a)+1):
    try:
        tmp += counts[num]
        # counts_list.append(tmp)
    except:
        pass

    counts_list.append(tmp)

ans = 0
for i in range(len(counts_list)-3):
    ans = max(ans,counts_list[i+3]-counts_list[i])
    # print(ans)

if len(counts_list) <= 3:
    ans = max(ans,max(counts_list))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

n = int(input())
a = [int(num) for num in input().split()]

list_num = collections.Counter(a)

count_max = 0
for x in range(min(a), max(a)+1):
    count = list_num[x-1] + list_num[x] + list_num[x+1]
    count_max = max(count_max, count)

print(count_max)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
bit = [0]*10**6
for a in A:
    bit[a] += 1
    bit[a+1] += 1
    bit[a+2] += 1
ans = max(bit)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

c = defaultdict(int)
for ai in a:
    c[ai] += 1

m = 0
for n in c.keys():
    sum_c = c[n]
    if n - 1 in c: sum_c += c[n - 1]
    if n + 1 in c: sum_c += c[n + 1]
    m = max(m, sum_c)
print(m)

Submission status: Accepted

Solution code:
from itertools import accumulate
n = int(input())
a = [int(item) for item in input().split()]

cum = [0]* (10**5 + 2)
for item in a:
    if item - 1 < 0:
        cum[0] += 1
    else:
        cum[item-1] += 1
    cum[item+2] -= 1
print(max(list(accumulate(cum))))

Submission status: Accepted

Solution code:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())


n = ni()

a = nl()

minn = min(a)
maxx = max(a)

lis = [0 for i in range(maxx - minn + 3)]
for aa in a:
    i = aa - minn
    lis[i - 1] += 1
    lis[i] += 1
    lis[i + 1] += 1
print(max(lis))

Submission status: Accepted

Solution code:
n = int(input())

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

d = dict()

for x in data:
    if d.__contains__(x):
        d[x]+=1
    else:
        d[x]=1
         
    if d.__contains__(x-1):
        d[x-1]+=1
    else:
        d[x-1]=1
    if d.__contains__(x+1):
        d[x+1]+=1
    else:
        d[x+1]=1
res = 0
for v in d.values():
    res = max(res,v)
print(res)

Submission status: Accepted

Solution code:
N = int(input())
A = [0]*100000
AA = list(map(int, input().split()))
minA = 100000
maxA = 0
for a in AA:
  A[a] += 1
  minA = min(minA, a)
  maxA = max(maxA, a)
ans = 1
for i in range(max(minA-1,0), min(maxA+1, N-2)):
  ans = max(ans, A[i]+A[i+1]+A[i+2])
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
#先に数えておく
N=int(input())
A=list(map(int,input().split()))
low=min(A)
high=max(A)

c_l=Counter(A)
ans=-1
for x in range(low,high+1):
    #範囲
    a=x-1
    b=x
    c=x+1
    num=c_l[a]+c_l[b]+c_l[c]
    ans=max(num,ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
from sys import stdin
n = int(stdin.readline().rstrip())
al = [int(_) for _ in stdin.readline().rstrip().split()]
counter = Counter(al)
for a in al:
    counter[a-1]+=1
    counter[a+1]+=1
print(max(counter.values()))

Submission status: Accepted

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

import itertools
import collections
import bisect

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

    c = collections.Counter()
    for a in A:
        c[a-1] += 1
        c[a] += 1
        c[a+1] += 1
    print(c.most_common()[0][1])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

max = 0
for i in set(a):
  if max < d[i]+d[i-1]+d[i+1]:
    max = d[i]+d[i-1]+d[i+1]
print(max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

print(max(counter.values()))

Submission status: Accepted

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
from collections import Counter
lst=[]
for i in l:
  lst.append(i-1)
  lst.append(i)
  lst.append(i+1)
print(Counter(lst).most_common(1)[0][1])

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
n = ip()                                     #入力整数1つ
#n,q= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#b = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
a.sort()
pos = [0]
p = a[0]
for i in range(n):
    if a[i] != p:
        p = a[i]
        pos.append(i)
s = [1]
if n == 2:
    if a[1]-a[0]==1:s.append(2)
for i in range(len(pos)):
    p = a[pos[i]]
    position = pos[i]
    score = 0
    while p +  2 >= a[position]:
        position+=1
        score+=1
        if position == n: break
  #      print(position,end='')
    s.append(score)
 #   print()
print(max(s))

Submission status: Accepted

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

from collections import Counter
c =  Counter()
for a in an:
    c[a-1] += 1
    c[a] += 1
    c[a+1] += 1
print(c.most_common()[0][1])

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
dic = defaultdict(int)
for i in range(N):
    dic[a[i] - 1] += 1
    dic[a[i]] += 1
    dic[a[i] + 1] += 1
print(max(dic.values()))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
from collections import defaultdict

n=int(input())
a=[int(x) for x in input().split()]
d=defaultdict(int)
for i in a:
    d[i]+=1
#print(d)
b=[[-2,0],[-1,0]]
for i in d:
    b.append([i,d[i]])
b.sort()

ans=1
m=len(b)
for i in range(m):
    ans=max(ans,b[i][1])
    if i+1<m and b[i][0]+1==b[i+1][0]:
        ans=max(ans,b[i][1]+b[i+1][1])
    if i+2<m and b[i][0]+1==b[i+1][0] and b[i+1][0]+1==b[i+2][0]:
        ans=max(ans,b[i][1]+b[i+1][1]+b[i+2][1])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
    for j in range(-1, 2):
        if a[i] + j in d.keys():
            d[a[i] + j] += 1
        else:
            d[a[i] + j] = 1
print(max(d.values()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
alist = np.array(list(map(int, input().split())))
alist
alistp = alist + 1
alistm = alist - 1
d = {}
for a in alist:
    if a not in d.keys():
        d[a] = 1
    else:
        d[a] += 1
for a in alistp:
    if a not in d.keys():
        d[a] = 1
    else:
        d[a] += 1
for a in alistm:
    if a not in d.keys():
        d[a] = 1
    else:
        d[a] += 1
print(max(d.values()))

Submission status: Accepted

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

#カウンター(二次元リストver)
counter = []
count = 0
for i in range(N):
  if(i == 0):
    counter.append([A[i],1])
  else:
    if(A[i] == A[i-1]):
      counter[count][1] += 1
    else:
      count += 1
      counter.append([A[i],1])

count += 1
ans = 0
for i in range(count):
  tmp = counter[i][1]
  if((i != 0)and(i != count-1)):
    if((counter[i][0]-counter[i-1][0])==1):
      tmp += counter[i-1][1]
    if((counter[i+1][0]-counter[i][0])==1):
      tmp += counter[i+1][1]
  elif((i == count-1)and(count >= 2)):
    if((counter[i][0]-counter[i-1][0])==1):
      tmp += counter[i-1][1] 
  ans = max(ans,tmp)

print(ans)

Submission status: Accepted

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

memo=[0]*(10**5)
answer=0

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
def binarysearch(x):
  ok=-1
  ng=n
  while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if a[mid]>=x:
      ng=mid
    else:
      ok=mid
  return ok
ans=0
for i in range(-1,10**5+2):
  ans=max(ans,binarysearch(i+2)-binarysearch(i-1))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    d = defaultdict(lambda: 0)
    for a in A:
        d[a-1] += 1
        d[a] += 1
        d[a+1] += 1

    ans = 0
    for key in d:
        ans = max(ans, d[key])

    return ans


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
c = []
for i in a:
    c.append(bisect.bisect_right(a, i+1) - bisect.bisect_right(a, i-2))
print(max(c))

Submission status: Accepted

Solution code:
from collections import Counter

N=int(input())
l=list(map(int, input().split()))  #リスト入力

c=Counter(l+[x-1 for x in l]+[x+1 for x in l])
print(c.most_common()[0][1])

Submission status: Accepted

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

count = [0] * 10**5

for e in a :
    if e != 0 :
        count[e - 1] += 1
    count[e] += 1
    if e != 10**5 - 1 :
        count[e + 1] += 1

print(max(count))

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
a = [int(i) for i in input().split()]
d = defaultdict(int)
for x in a:
    d[x] += 1
#print(d)
ans = []
for x in d.keys():
    sum = d[x]
    if x-1 in d:
        sum += d[x-1]
    if x+1 in d:
        sum += d[x+1]
    ans.append(sum)
print(max(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
an = Counter(map(int, input().split()))


def main():
    print(max([an[k - 1] + an[k] + an[k + 1] for k in an.keys()]))
    return


main()

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
an = Counter(map(int, input().split()))


def main():
    print(max([an[k - 1] + v + an[k + 1] for k, v in an.items()]))
    return


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict
n = input()
nums = list(map(int, input().split()))
dic = defaultdict(int)
for num in nums:
    dic[num] += 1
keys = sorted(list(dic.keys()))
cnt = 1
for key in keys:
    cnt = max(dic[key] + dic[key + 1] + dic[key - 1], cnt)
print(cnt)

Submission status: Accepted

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

        d.setdefault(a+1, 0)
        d[a+1] += 1

        d.setdefault(a-1, 0)
        d[a-1] += 1

    return max(d.values())


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = together(N, A)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())))
count = dict()
for a in A:
    for i in range(a-1, a+2):
        if i not in count:
            count[i] = 1
        else:
            count[i] += 1
print(max(count.values()))

Submission status: Accepted

Solution code:
n=int(input())

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

X=list(set(A))

RES=[0]*100002

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

print(max(RES))

Submission status: Accepted

Solution code:
import collections
n=int(input())

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

a=collections.Counter(A)

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

K=[]
V=[]

RES=[]
for i in range(len(X)):
    K.append(X[i][0])
    V.append(X[i][1])

if len(X)>=3:
    for j in range(1,len(X)-1):
        res=V[j]
        if K[j]-1==K[j-1]:
            res+=V[j-1]
        if K[j]+1==K[j+1]:
            res+=V[j+1]
        RES.append(res)
elif len(X)==2:
    if K[0]+1==K[1]:
        RES.append(V[0]+V[1])
    else:
        RES.append(max(V))
else:
    RES.append(V[0])        

print(max(RES))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect

n = int(input())
A = sorted(list(map(int,input().split())))

res = []
for i in range(1,10**5+1):
    res.append(bisect.bisect_right(A,i+1)-bisect.bisect_left(A,i-1))
print(max(res))

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=[int(i) for i in input().split()]
plus=[i+1 for i in a]
minus=[i-1 for i in a]
print(sorted(list(Counter(a+plus+minus).values()))[-1])

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(10 ** 5 + 1)]
d = {}

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

ans = 0
for i in range(10 ** 5 + 1):
    if i in d:
        b[i] = d[i]

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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
a = list(map(int, input().split()))
m = max(a)
d = Counter(a)

ans = 0
for i in range(-1, m+2):
  count = 0
  if i in d.keys():
    count += d[i]
  if i+1 in d.keys():
    count += d[i+1]
  if i-1 in d.keys():
    count += d[i-1]
  ans = max(ans, count)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

Submission status: Accepted

Solution code:
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

NUM = 100000

N = int(input())

table = [0] * (NUM+1)

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

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


maximum = 1

#連続する3つの数
for i in range(0,100001,1):
    tmp = 0
    if i-1 >= 0:
        tmp += table[i-1]
    tmp += table[i]
    if i+1 <= 100000:
        tmp += table[i+1]
    maximum = max(maximum,tmp)

print("%d"%(maximum))

Submission status: Accepted

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

Submission status: Accepted

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

afters = []
for ai in range(N):
	for sign in [-1,0,1]:
		afters.append(A[ai]+sign)
		
uniq = set(afters)

countDic = {}
sas = sorted(afters)
for a in sas:
	if a in countDic.keys():
		countDic[a] += 1
	else:
		countDic[a] = 1
	
print(max(countDic.values()))

Submission status: Accepted

Solution code:
import collections
n=int(input())
a=list(map(int, input().split()))
s=[0]*3*n
for i in range(n):
    s[3*i]+=a[i]+1
    s[3*i+1]+=a[i]-1
    s[3*i+2]+=a[i]
c=collections.Counter(s)
print(c.most_common()[0][1])

Submission status: Accepted

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

c = collections.Counter(a)
res = 0
for i in range(10**5):
    num = c[i-1] + c[i] + c[i+1]
    if res < num:
        res = num
print(res)

Submission status: Accepted

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

T = [0]*100000
for x in a:
  T[x] += 1
ans = 0
for i in range(99998):
  ans = max(ans, sum(T[i:i+3]))
print ans

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    X = {}
    for a in map(int, input().split()):
        for i in range(-1, 2):
            if (a+i) not in X:
                X[a+i] = 0
            X[a+i] += 1
    print(max(X.values()))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
n = I()
d = defaultdict(int)
a = LI()
for i in a:
    d[i] += 1
    d[i+1] += 1
    d[i-1] += 1
d = list(d.values())
print(max(d))
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

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

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):
    if a[i] == 0:
        b[a[i]] += 1
        b[a[i]+1] += 1
    else:
        b[a[i]-1] += 1
        b[a[i]] += 1
        b[a[i]+1] += 1
print(max(b))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
if N == 1:
  print(1)
elif N == 2:
  if abs(A[1]-A[0]) <= 2:
    print(2)
  else:
    print(1)
else:
  L = [0]*(10**5+1)
  for i in range(N):
    L[A[i]+1] += 1
  for j in range(1,len(L)):
    L[j] = L[j-1]+L[j]
  ans = 0
  for k in range(3,len(L)):
    S = L[k]-L[k-3]
    if ans <= S:
      ans = S
  print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
ls = []
for i in a:
    ls.append(i)
    ls.append(i+1)
    ls.append(i-1)
import collections as col
dic = col.defaultdict(int)
for i in ls:
    dic[i] += 1
print(max(dic.values()))

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    a = [int(s) for s in input().split()]
    print(solve(a))

def solve(a):
    c = dict()

    for i in a:
        for j in range(i - 1, i + 2):
            c[j] = c.get(j, 0) + 1
    
    return max(c.values())

main()

Submission status: Accepted

Solution code:
#ABC072C
N=int(input())
A=list(map(int,input().split()))
A.sort()
B=[0]*(max(A)+1)
back=A[0]
count=0
for a in A:
	if back==a:
		count+=1
	else:
		B[back]=count
		back=a
		count=1
B[back]=count
num=sum(B[0:min(3,len(B))])
for n in range(max(A)-1):
	if num<sum(B[n:n+3]):
		num=sum(B[n:n+3])
print(num)

Submission status: Accepted

Solution code:
from sys import stdin, stderr, setrecursionlimit, exit
from collections import Counter
setrecursionlimit(2147483647)
def getint():
    return int(stdin.readline().rstrip('\r\n'))
def getints():
    return [int(i) for i in stdin.readline().rstrip('\r\n').split()]
def getintlines(n=1):
    res = []
    for _ in range(n):
        res.append(getint())
    return res
def getintslines(n=1):
    res = []
    for _ in range(n):
        res.append(getints())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getint()
a = getints()
c = Counter()

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

print(c.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] += 1
    x[i] += 1
    x[i+2] += 1
print(max(x))

Submission status: Accepted

Solution code:
import bisect

n=int(input())
a=list(map(int,input().split()))
a.sort()
max=0
for i in range(10**5+1):
    x=bisect.bisect_left(a,i-1)
    y=bisect.bisect_right(a,i+1)
    if y-x>max:
        max=y-x
print(max)

Submission status: Accepted

Solution code:
from collections import Counter 
N = int(input())
A = Counter(list(map(int, input().split())))
cnt = 0
for i in A:
    sums = A[i] + A[i+1] + A[i+2]
    if sums > cnt:
        cnt = sums
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

d = {}
for a in A:
    for i in [-1,0,1]:
        if a+i in d.keys():
            d[a+i] += 1
        else:
            d[a+i] = 1

print(max(d.values()))

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
b=[0 for _ in range(100002)]
for i in range(N):
    b[a[i]-1],b[a[i]],b[a[i]+1]=b[a[i]-1]+1,b[a[i]]+1,b[a[i]+1]+1
b.sort(reverse=True)
print(b[0])

Submission status: Accepted

Solution code:
import collections

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

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int,input().split()))
table = [0 for i in range(10**5+3)]


for x in L:
    table[x] += 1
    table[x-1] += 1
    table[x+1] += 1

print(max(table))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a_max = max(a)
count = {}
for i in range(a_max+2):
    count[i] = 0
for i in a:
    if i != 0:
        count[i-1] += 1
        count[i] += 1
        count[i+1] += 1
    if i == 0:
        count[i] += 1
        count[i+1] += 1
        
print(max(count.values()))

Submission status: Accepted

Solution code:
from collections import defaultdict

int_n = int(input())
ar_int_a = list(map(int, input().split()))

d_cnt = defaultdict(int)
for w in ar_int_a:
    d_cnt[w] += 1


st_int_group = set(ar_int_a)
max_count = 0

for i in st_int_group:
    max_count = max(d_cnt[i] + d_cnt[i - 1] + d_cnt[i + 1], max_count)

print(max_count)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
d = {}
ans = 0
for i in a:
    try:
        d[i] += 1
    except:
        d[i] = 1
for i in d:
    cnt = d.get(i-1, 0) + d.get(i, 0) + d.get(i+1, 0)
    if cnt > ans:
        ans = cnt
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
aset = set(a)
d = {i:0 for i in aset}
for i in range(n):
    d[a[i]] += 1
aset = sorted(aset)
if len(aset) == 1:
    print(d[aset[0]])
    exit()
if len(aset) == 2:
    if abs(aset[0]-aset[1]) <= 1:
        print(d[aset[0]] + d[aset[1]])
    else:
        print(max(d[aset[0]], d[aset[1]]))
    exit()
ans = 0
for i in range(len(aset)-2):
    ans = max(d[aset[i]], ans)
    if aset[i+1] - aset[i] == 1:
        ans = max(d[aset[i+1]]+d[aset[i]], ans)
    if aset[i+2] - aset[i] == 2:
        ans = max(d[aset[i+2]]+d[aset[i+1]]+d[aset[i]], ans)
print(ans)