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()))
ans = 0
A.sort()
a=0
b=0
c=1

for i in range(N-1):
  if A[i] == A[i+1]:
    a += 1
    b += 1
    c += 1
  elif A[i]+1 == A[i+1]:
    if ans < a:
      ans = a
    a = b
    a += 1
    b = c
    b += 1
    c = 1
  elif A[i]+2 == A[i+1]:
    if ans < a:
      ans = a
    if ans < b:
      ans = b
    a = c
    a += 1
    b = 1
    c = 1
  else:
    if ans < a:
      ans = a
    if ans < b:
      ans = b
    if ans < c:
      ans = c
    a = 1
    b = 1
    c = 1

if ans < a:
      ans = a
if ans < b:
      ans = b
if ans < c:
      ans = c
print(ans)

Submission status: Accepted

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

for i in range(N):
    CN = N_List[i]
    for k in range(-1,2,1):
        d[CN + k] += 1
        
print(max(d.values()))

Submission status: Accepted

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

dp=[0 for n in range(max(a)+1)]
for n in range(N):
    dp[a[n]]+=1

ans=0
if len(dp)==1:
    ans=dp[0]
else:
    for n in range(1,len(dp)-1):
        ans=max(ans,dp[n-1]+dp[n]+dp[n+1])

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
al = list(map(int, input().split()))
al.sort()
al.append(-1)
cnt = 1
bl = []
for i in range(n):
    if al[i] == al[i+1]:
        cnt += 1
    else:
        bl.append([al[i], cnt])
        cnt = 1
tmp = 0
ans = 0
for j in range(len(bl)):
    tmp = bl[j][1]
    if bl[j-1][0] + 1 == bl[j][0]:
        tmp += bl[j-1][1]
    if j!=len(bl)-1 and bl[j][0] == bl[j+1][0] - 1:
        tmp += bl[j+1][1]

    if tmp > ans:
        ans = tmp

print(ans)

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    a = i_list()

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







if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 21 23:37:30 2020

@author: liang
"""

N = int(input())

A = [int(x) for x in input().split()]

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

for a in A:
    if a - 1 >= 0:
        d[a-1] += 1
    d[a] += 1
    d[a+1] += 1

ans = max(d)

print(ans)

Submission status: Accepted

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

ans = 0

cnt = [0]*100001

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

n = int(input())

a_list = list(map(int, input().split()))
sort_a_list = sorted(a_list)

l = 0
r = 0
ans = 0
max_ans = 0
sabun = 0
#print(sort_a_list)

while (r < n):
    #print(l,r)
    #print(ans)
    #print(sabun)
    if (sabun <= 2):
        if sort_a_list[r] - sort_a_list[l] > 2:
            l += 1
            sabun = sort_a_list[r] - sort_a_list[l]
            ans -= 1
            continue
        ans += 1
        max_ans = max(max_ans,ans)
        r += 1
        if r >= n:
            break
        sabun = sort_a_list[r] - sort_a_list[l]
        
    else:
        l += 1
        sabun = sort_a_list[r] - sort_a_list[l]
        ans -= 1
print(max_ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

t = [0] * (max(a) + 1)
for v in a:
    t[v] += 1

if max(a) <= 1:
    print(sum(t))
    sys.exit(0)

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

print(ans)

Submission status: Accepted

Solution code:
#（i+1 and i and i-1）の合計数が一番多いところを見つける
from collections import Counter
ans = []
N = int(input())
a = list(map(int,input().split()))
num = Counter(a)
for i in set(a):
    ans.append(num[i] + num[i+1] + num[i-1])
    
print(max(ans))

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:
import collections

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

for i in range(len(a)):
    if a[i] > 0:
        a.append(a[i]-1)
    a.append(a[i]+1)

res = collections.Counter(a)

print(max(res.values()))

Submission status: Accepted

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

if N == 1:
    print(1)
    sys.exit(0)
    
cnt = [0 for _ in range(10**5+1)]
for a in A:
    if a == 0:
        cnt[a] += 1
        cnt[a+1] += 1
    else:
        cnt[a-1] += 1
        cnt[a] += 1
        cnt[a+1] += 1
    
print(max(cnt))

Submission status: Accepted

Solution code:

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

cnt=[0]*(a[-1]+2)
for i in range(N):
    cnt[a[i]]+=1

out=0
dam = cnt[0] + cnt[1]
out=max(out,dam)
for i in range(1,a[-1]+1):
    dam = cnt[i-1] + cnt[i] + cnt[i+1]
    out=max(out,dam)
print(out)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, math
from functools import lru_cache
from itertools import accumulate
sys.setrecursionlimit(10**9)
MOD = 10**9+7

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

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

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

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

N = ii()
a = list(mi())

l = [0]*(max(a)+5)

for i in range(N):
    l[a[i]] += 1
    l[a[i]+3] -= 1

acc = list(accumulate(l))

print(max(acc))

Submission status: Accepted

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

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

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

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

max_value = max(count)
#max_index = count.index(max_value)
print(max_value)

Submission status: Accepted

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

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

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

x_cnt = [0] * (10**5 +1)
for x in range(1, 10**5):
    tmp = cnt[x-1] + cnt[x] + cnt[x+1]
    x_cnt[x] = tmp

print(max(x_cnt))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
cnt=[0]*100002
input()
for x in map(int,input().split()):
    cnt[x]+=1
    cnt[x+1]+=1
    cnt[x+2]+=1
print(max(cnt))

Submission status: Accepted

Solution code:
N = int(input())
a_s = list(map(int,input().split()))
cnt = [0] * (max(a_s)+1)
for a in a_s:
    cnt[a] += 1
answer = 1
for i,c in enumerate(cnt):
    if i < 1:
        answer = max(answer, cnt[i])
        continue
    if i < 2:
        answer = max(answer, sum(cnt[i-1:i+1]))
        continue
    answer = max(answer, sum(cnt[i-2:i+1]))
print(answer)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from collections import Counter
with open(0) as f:
    N, *a = map(int, f.read().split())
data = [x-1 for x in a] + [x for x in a] + [x+1 for x in a]
ans = Counter(data).most_common(1)[0][1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
count=[0 for _ in range(100001)]
for x in a:
    count[x]+=1
    count[x+1]+=1
    if x>0:
        count[x-1]+=1
print(max(count))

Submission status: Accepted

Solution code:
N = int(input())
a = sorted([int(c) for c in input().split()])
#2回の変わり目を記憶
c1,c2,c3 = [0,0,0]
ma = 1
for i in range(N):
    if i > 0:
        if a[i]==a[i-1]+1:
            c1 = c2 
            c2 = c3
            c3 = i
        elif a[i]!=a[i-1]:
            c1,c2,c3=[i,i,i]
    if ma < i - c1+1:
        ma = i - c1+1

print(ma)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

lower_a = list(map(lambda x: x - 1, a))
upper_a = list(map(lambda x: x + 1, a))
extended_a = collections.Counter(a + lower_a + upper_a)

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
  for i in range(a - 1, a + 2):
    d[i] = d.get(i, 0) + 1
x = sorted(d.values())
print(max(x))

Submission status: Accepted

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

ans=0

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

for i in range(0,100000):
    sum=cnt[i]+cnt[i+1]+cnt[i+2]
    ans=max(ans,sum)

print(ans)

Submission status: Accepted

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
a1=[x-1 for x in a]
a2=[x+1 for x in a]
b=a+a1+a2
c=collections.Counter(b)

print(max(c.values()))

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int, input().split(" "))))
counter = [0 for i in range(10 ** 5 + 2)]
ans = 0

for i in range(n):
  counter[a[i]] += 1
#print(counter)
for i in range(1, 10 ** 5 + 1):
  temp = sum(counter[i-1:i+2])
  ans = max(ans, temp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
a1 = [x - 1 for x in a]
a2 = [x + 1 for x in a]
b = a + a1 + a2
c = collections.Counter(b)

print(max(c.values()))

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

Solution code:
import sys
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20

def mint():
    return map(int,input().split())
def lint():
    return map(int,input().split())
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])

N,A = int(input()),lint()
S = [0]*(10**5+10)
for a in A:
    S[a-1] += 1
    S[a] += 1
    S[a+1] += 1
print(max(S))

Submission status: Accepted

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

lis = collections.Counter(a)
ans = 0
memo = 0
#print(lis)

for i in range(10**5):
    memo = lis[i-1] + lis[i] + lis[i+1]
    #print(lis[i-1], lis[i], lis[i+1])
    if memo > ans:
        ans = memo


print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

a=[i-1 for i in l]
b=[i+1 for i in l]

l=Counter(l+a+b)

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
i=0
ans=0
while i < n:
    k=i
    index=i
    while a[k]-a[i]<= 2:
        k += 1
        if k == n:
            break
    while a[index] == a[i]:
        index += 1
        if index == n:
            break
    ans=max(k-i,ans)
    if index == n:
        break
    i=index
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int,input().split()))
c = 0
nums = [0]*(10**5+2)
for a in As:
    nums[a]+=1

for i in range(1,len(nums)-1):
    t = nums[i-1]+nums[i]+nums[i+1]
    c = max(c,t)
print(c)

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int,input().split()))
c = 0
nums = [0]*(10**5+1)
for a in As:
    nums[a]+=1

for i in range(1,len(nums)):
    if i == len(nums)-1:
        t = nums[i - 1] + nums[i]
    else:
        t = nums[i-1]+nums[i]+nums[i+1]
    c = max(c,t)
print(c)

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
a = tuple(map(int, input().split()))
cnt = defaultdict(int)

for i in range(N):
	cnt[a[i]-1] += 1
	cnt[a[i]] += 1
	cnt[a[i]+1] += 1
print(max(cnt.values()))

Submission status: Accepted

Solution code:
# vim: fileencoding=utf-8


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import collections

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = [0] * (max(a)+3)
    
    for i in a:
        cnt[i-1] += 1
        cnt[i] += 1
        cnt[i+1] += 1
        
    print(max(cnt))
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
al = [int(a) for a in input().split()]
a_dic = {}
for a in al:
    num = a_dic.get(a, 0)
    a_dic[a] = num + 1

min_X = min(al)
max_X = max(al)
ans = 0
for X in range(min_X, max_X + 1):
    num = a_dic.get(X-1, 0) + a_dic.get(X, 0) + a_dic.get(X+1, 0)
    if num > ans:
        ans = num

print(ans)

Submission status: Accepted

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

a_max = max(A)
a_min = min(A)

cnt_dict = {}
for i in range(a_min-1, a_max+2):
    cnt_dict[i] = 0
for i in range(len(A)):
    cnt_dict[A[i]-1] += 1
    cnt_dict[A[i]] += 1
    cnt_dict[A[i]+1] += 1

print(max(cnt_dict.items(), key = lambda x: x[1])[1])

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(max(l))

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(a_list)

for i in range(max(c.keys()) + 1) :
    cnt = c[i] + c[i + 1] + c[i + 2]
    
    if max_cnt < cnt :
        max_cnt = cnt

print(max_cnt)

Submission status: Accepted

Solution code:
import collections

n = int(input())
a = list(map(int, input().split()))
b = list(map(lambda x: x-1, a))
c = list(map(lambda y: y+1, a))
d = a+b+c

e = collections.Counter(d)
print(max(e.values()))

Submission status: Accepted

Solution code:
n = int(input())
a_lst = list(map(int, input().split()))
for i in range(n):
    a_lst[i] += 1

max_a = max(a_lst)
count_lst = [0] * (max_a + 2)


for i in range(n):
    a = a_lst[i]
    index1 = a - 1
    index2 = a
    index3 = a + 1

    count_lst[index1] += 1
    count_lst[index2] += 1
    count_lst[index3] += 1

maximum = max(count_lst)
print(maximum)

Submission status: Accepted

Solution code:
import collections
N = int(input())
lsA = list(map(int,input().split()))
counterA = collections.Counter(lsA)
ans = 0
for X in range(1,10**5+1):
    b1 = counterA[X-1]
    b2 = counterA[X]
    b3 = counterA[X+1]
    ans = max(ans,sum([b1,b2,b3]))
print(ans)

Submission status: Accepted

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

ans = [0] * (max(A) + 2)

for a in A:
    if a == 0:
        ans[a] += 1
        ans[a + 1] += 1
    if a != 0:
        ans[a - 1] += 1
        ans[a] += 1
        ans[a + 1] += 1

print(max(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#10 C - Together
N = int(input())
a = list(map(int,input().split()))
a = sorted(a, reverse = True)
a_set = set(a)

#aの各要素の個数をカウント
a_cnt = [0]*(max(a)+2)#0からmax(a)+1まで
for i in a:
    a_cnt[i] += 1

mcnt = 0
for j in a:
    cnt = a_cnt[j]
    if j-1 in a_set:
        cnt += a_cnt[j-1]
    if j+1 in a_set:
        cnt += a_cnt[j+1]
    mcnt = max(mcnt,cnt)    
print(mcnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input();B=[0]*10**5
for a in input().split():B[int(a)]+=1
print(max(sum(B[i:i+3])for i in range(10**5)))

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())

C = {}
for a in A:
    if a in C.keys():
        C[a] += 1
    else:
        C[a] = 1
B = list(C.items())
B.sort(key=lambda x: x[0])

ans = 0
for i in range(len(B)):
    count = B[i][1]
    try:
        for j in [-1,1]:
            if B[i+j][0] == B[i][0]+j:
                count += B[i+j][1]
    except IndexError:
        pass
    ans = max(ans, count)
print(ans)

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())

C = {}
for a in A:
    if a in C.keys():
        C[a] += 1
    else:
        C[a] = 1
B = list(C.items())
B.sort(key=lambda x: x[0])

M = len(B)
ans = 0
for i in range(M):
    count = B[i][1]
    if i-1 >= 0 and B[i-1][0] == B[i][0]-1:
        count += B[i-1][1]
    if i+1 < M and B[i+1][0] == B[i][0]+1:
        count += B[i+1][1]
    ans = max(ans, count)
print(ans)

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())

C = {}
for a in A:
    if a in C.keys():
        C[a] += 1
    else:
        C[a] = 1
B = list(C.items())
B.sort(key=lambda x: x[0])

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

Submission status: Accepted

Solution code:
import sys
import collections

N, *A = map(int, open(0).read().split())

B = collections.Counter(A).most_common()
B.sort(key=lambda x: x[0])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

B = []
for a in A:
    B.append(a-1)
    B.append(a)
    B.append(a+1)
C = Counter(B)

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

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
a = LI()

ANS = [0]*(10**5+1)
for i in range(N):
    b = a[i]
    if b == 0:
        ANS[b] += 1
        ANS[b+1] += 1
    else:
        ANS[b-1] += 1
        ANS[b] += 1
        ANS[b+1] += 1
        
print(max(ANS))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

from collections import defaultdict
dic = defaultdict(int)
for a in As:
    dic[a] += 1
    dic[a-1] += 1
    dic[a+1] += 1

print(max(dic.values()))

Submission status: Accepted

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline

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

counter = Counter(A)
ans = 0
for value, count in counter.items():
    if value - 1 in counter:
        count += counter[value - 1]
    if value + 1 in counter:
        count += counter[value + 1]
    ans = max(ans, count)

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
a=lnii()

c=Counter(a)
a_max=max(a)

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import copy


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


N = int(input())
A = LI()
B = Counter(A)
A = copy.copy(B)

for k, v in B.items():

    if k-1 in A:
        A[k-1] += v
    else:
        A[k-1] = v
    if k+1 in A:
        A[k+1] += v
    else:
        A[k+1] += v

print(max(A.values()))

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d = defaultdict(int)
for x in arr:
    d[x] += 1

a = d[0] + d[1] + d[2]
ans = [a]

for i in range(max(arr) - 2):
    a -= d[i]
    a += d[i + 3]
    ans.append(a)

print(max(ans))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
K = max(A)
ls = [0 for i in range(K+2)]
for i in range(N):
    if A[i] == 0:
        ls[A[i]] += 1
        ls[A[i]+1] += 1
    else:
        ls[A[i]-1] += 1
        ls[A[i]] += 1
        ls[A[i]+1] += 1
print(max(ls))

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d = defaultdict(int)

for x in arr:
    d[x] += 1
    d[x - 1] += 1
    d[x + 1] += 1

result = [y for x, y in d.items()]

print(max(result))

Submission status: Accepted

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

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

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

print(max(bucket))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
mode = [0]*(10**5+2)
for i in range(len(a)):
    k = a[i]
    if(a == 0):
        mode[k] += 1
        mode[k+1] += 1
    else:
        mode[k-1] += 1
        mode[k]   += 1
        mode[k+1] += 1

print(max(mode))

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
a=lnii()

c=Counter(a)
a_max=max(a)

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
arr = [int(x) for x in input().split()]
cnt = [0] * (10 ** 5 + 1)
for a in arr:
    cnt[a] += 1
    cnt[a+1] += 1
    if a > 0:
        cnt[a-1] += 1

print(max(cnt))

Submission status: Accepted

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

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

from collections import Counter

c=Counter(p).most_common()

m = list(c)[0][0]

ans=0

for i in range(n):
    if abs(a[i]-m)<=1:
        ans+=1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

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

for i in range(N):
    tmp = a[i]
    memo[tmp-1] += 1
    memo[tmp] += 1
    memo[tmp+1] += 1

ans = max(memo)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
C = {i:0 for i in range(0,10**5)}
for i in range(N):
    C[A[i]] += 1
cmax = 0
for x in range(1,10**5-1):
    cnt = C[x]+C[x-1]+C[x+1]
    cmax = max(cmax,cnt)
print(cmax)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
a = LI()

ANS = [0]*(10**5+1)
for i in range(N):
    b = a[i]
    if b == 0:
        ANS[b] += 1
        ANS[b+1] += 1
    else:
        ANS[b-1] += 1
        ANS[b] += 1
        ANS[b+1] += 1
print(max(ANS))

Submission status: Accepted

Solution code:
n = int(input())
al = list(map(int, input().split()))    
# al.sort()
al_cnts = [0]*(10**5+1)
for a in al:
    al_cnts[a] += 1

ans = 0
for a1,a2,a3 in zip(al_cnts[0:-2],al_cnts[1:-1],al_cnts[2:]):
    v = a1+a2+a3
    ans = max(ans,v)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
d=[0]*(10**5+1)
for i in l:
   d[i]+=1
s=list(set(l))
m=len(s)
k=0
for i in range(m):
    k=max(d[s[i]-1]+d[s[i]]+d[s[i]+1],k)
print(k)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


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


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = z()
A = zz()
c = collections.Counter(A)
ans = 0
for x in range(max(A)+1):
    tmp = c[x]
    try:
        tmp += c[x-1]
    except:
        pass
    try:
        tmp += c[x+1]
    except:
        pass
    ans = max(tmp, ans)
print(ans)

Submission status: Accepted

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

data = {}
for a in A:
    for i in range(3): #a-1,a,a+1をカウント
        if a-1+i in data:
            data[a-1+i] += 1
        else:
            data[a-1+i] = 1
            
#カウントしたものの最大値が答え
ans = 0
for d in data.values():
    ans = max(ans, d)
print(ans)

Submission status: Accepted

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

M = max(a)

C = [0] * (M + 1)

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

ans = 0

for i in range(1,M):
    wa = C[i - 1] + C[i] + C[i + 1]
    ans = max(ans, wa)

if M <= 1:
    ans = N

print(ans)

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    a = LI()
    dic = collections.defaultdict(int)
    for i in a:
        for x in range(i-1,i+2):
            dic[x] += 1
    diclst = sorted(dic.items(), key=lambda x: x[1], reverse=True)
    ans = diclst[0][1]
    print(ans)
main()