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:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N = INT()
a = LIST()

lim = 10**5+3
cnt = [0]*lim

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

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

Submission status: Accepted

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

for i in range(N):
    a.append(a[i] + 1)
    a.append(a[i] - 1)
c = collections.Counter(a)
print(c.most_common()[0][1])

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

N = INT()
a = np.array(LIST())
a = np.bincount(a)
b = a.copy()
b[1:] += a[:-1]
b[:-1] += a[1:]
print(b.max())

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
import numpy as np

N = INT()
a = np.array(LIST())
#print(a)
a = np.bincount(a)
#print(a)
b = a.copy()
#print(b)
b[1:] += a[:-1]
#print(b)
b[:-1] += a[1:]
#print(b)
print(b.max())

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = LIST()
ans =[]

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

#print(ans)
#print(Counter(ans))
#print(Counter(ans).values())
print(max(Counter(ans).values()))

Submission status: Accepted

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

maxa = max(al)
import collections
c =collections.Counter(al)
res = 0
for i in range(maxa+1):
    res = max(res,c[i-1]+c[i]+c[i+1])

print(res)

Submission status: Accepted

Solution code:
from collections import defaultdict

_ = input()
counts = defaultdict(int)
for a in map(int, input().split()):
    counts[a] += 1
    counts[a - 1] += 1
    counts[a + 1] += 1
print(max(counts.values()))

Submission status: Accepted

Solution code:
from collections import defaultdict

N = input()
counts = defaultdict(int)
values = set()
for a in map(int, input().split()):
    counts[a] += 1
    values.add(a)
ans = 0
for x in values:
    ans = max(ans, counts[x - 1] + counts[x] + counts[x + 1])
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

CA = Counter(A)
ans = 0
for key, val in CA.items():
    temp = 0
    kouho = [key - 1, key, key + 1]
    for num in kouho:
        if num in CA:
            temp += CA[num]
    ans = max(ans, temp)
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
      
    b = [0] * (10**6)
    for aa in a:
        b[aa - 1] += 1 
        b[aa + 0] += 1 
        b[aa + 1] += 1 
        
    print(max(b))
        
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    L.sort()

    ans = -1
    for x in range(10**5):
        ans = max(ans, bisect_right(L, x+1) - bisect_left(L, x -1))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
alis=list(map(int,input().split()))
xlis=dict()
for i in set(alis):
    xlis[i-1]=0
    xlis[i+1]=0
    xlis[i]=0
for i in alis:
    xlis[i-1]+=1
    xlis[i+1]+=1
    xlis[i]+=1
print(max(xlis.values()))

Submission status: Accepted

Solution code:
from collections import Counter
def solve():
    ans = 0
    N = int(input())
    A = list(map(int, input().split()))
    c = Counter(A)
    for i in range(1,10**5-1):
        cnt = 0
        if i-1 in c:
            cnt += c[i-1]
        if i in c:
            cnt += c[i]
        if i+1 in c:
            cnt += c[i+1]
        ans = max(ans,cnt)   
    return ans
print(solve())

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    c = Counter(A)
    uniq = list(k for k in c.keys())
    uniq.sort()
    ans = 0
    for u in uniq:
        ans = max([ans, c[u - 1] + c[u] + c[u + 1]])
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

result_list = []
for a in A:
    result_list.append(a-1)
    result_list.append(a)
    result_list.append(a+1)
C = Counter(result_list).most_common()
print(C[0][1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
aaa = list(map(int, input().split()))
max_a = max(aaa)
cnt = [0] * (max_a + 3)
cnt_sum = [0] * (max_a + 2)
for a in aaa:
    if a == 0:
        cnt[a] += 1
        cnt[a + 2] -= 1
    else:
        cnt[a - 1] += 1
        cnt[a + 2] -= 1
cnt_sum[0] = cnt[0]
for i in range(1, max_a + 2):
    cnt_sum[i] = cnt_sum[i - 1] + cnt[i]
print(max(cnt_sum))

Submission status: Accepted

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

cnt = [0] * (10**6)
# cnt = [0] * (3 + 1)

for _a in a:
    cnt[_a-1] += 1
    cnt[_a] += 1
    cnt[_a+1] += 1

# print(cnt)
print(max(cnt))

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())

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:
N = int(input())
A = list(map(int, input().split()))
count = [0]*(10**6)
for i in range(N):
    count[A[i]] += 1
    count[A[i]+1] += 1
    count[A[i]+2] += 1
print(max(count))

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

from collections import defaultdict
d = defaultdict(int)
for a in A:
    lower = a - 1
    upper = a + 1
    if lower >= 0:
        d[lower] += 1
    d[a] += 1
    d[upper] += 1

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

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()))
dict = {}
ans = 0

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

l = sorted(dict.items())
l += [(-1,0),(-2,0)]

for j in range(len(l)-2):
  if l[j][0]+1 == l[j+1][0] and l[j][0]+2 == l[j+2][0]:
     ans = max(ans,l[j][1]+l[j+1][1]+l[j+2][1])
  elif l[j][0]+1 == l[j+1][0] and l[j][0]+2 != l[j+2][0]:
     ans = max(ans,l[j][1]+l[j+1][1])
  elif l[j][0]+1 != l[j+1][0] and l[j][0]+2 != l[j+2][0]:
     ans = max(ans,l[j][1])
   
  
print(ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
keys = sorted(C.keys())
MAX = 0
for i in keys:
    MAX = max(MAX,C[i-1]+C[i]+C[i+1])
print(MAX)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

print(max(d.values()))

Submission status: Accepted

Solution code:
n = int(input())

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

l = [0]*100005 

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = 1
for c in C.keys():
    for i in range(-1, 2):
        j = c + i
        ans = max(ans, sum([C[j - 1], C[j], C[j + 1]]))
print(ans)

Submission status: Accepted

Solution code:
import collections

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

zen = m
cou = 0

for x in range(n):
    zen.append(m[x]-1)

for x in range(n):
    zen.append(m[x]+1)

a = collections.Counter(zen)

#for k in range(n):
#    if a.most_common()[0][0] == m[k] or a.most_common()[0][0] == m[k] -1 or a.most_common()[0][0] == m[k] +1:
#        cou += 1

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

Submission status: Accepted

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

for i in range(N):
    ans[A[i]-1]+=1
    if A[i]-2>=0:
        ans[A[i]-2]+=1
    if A[i]<=N-1:
        ans[A[i]]+=1

print(max(ans))

Submission status: Accepted

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

plus_list = []
minus_list = []
for a in a_list:
    plus_list.append(a+1)
    minus_list.append(a-1)

a_list.extend(plus_list)
a_list.extend(minus_list)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

c = [0 for _ in range(10**5+3)]

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

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

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

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N = I()
A = IL()

d = DD(int)
for a in A:
  d[a] += 1
keys = [k for k in d]
P(max(d[k-1] + d[k] + d[k+1] for k in keys))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
for i in range(N):
    A.append(A[i]+1)
    A.append(A[i]-1)
import collections 
C = collections.Counter(A)
ans = 0
for k,v in C.items():
    if v>ans:
        ans = v
print(ans)

Submission status: Accepted

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

c=[0 for i in range(100003)]

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

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
a.sort()
#print(a)
l=[0]*(a[-1]+1)#l[i]にはiの数が入る
for i in range(N):
    l[a[i]]+=1
#print(l)
ans=0
if len(l)>3:
    for i in range(len(l)-2):
        if ans<l[i]+l[i+1]+l[i+2]:
            ans=l[i]+l[i+1]+l[i+2]
else:
    ans=sum(l)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

MIN=min(A)
MAX=max(A)

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

Submission status: Accepted

Solution code:
def resolve():
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    A = sorted(A)

    Cnt = [0] * 100002
    for a in A:
        Cnt[a] += 1
        Cnt[a+1] += 1
        Cnt[a+2] += 1

    print(max(Cnt))
resolve()

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)

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

Submission status: Accepted

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

new_list = list()

for x in range(n):
    num = a[x]
    num_plus = num + 1
    num_minus = num - 1
    new_list.append(num_plus)
    new_list.append(num_minus)
    new_list.append(num)

d = dict(Counter(new_list))

print(max(d.values()))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
mina = min(a)
maxa = max(a)
w = maxa - mina + 3
abucket = [0] * w
for i in range(n):
  abucket[a[i] - mina] += 1
  abucket[a[i] - 1 - mina] += 1
  abucket[a[i] + 1 - mina] += 1
print(max(abucket))

Submission status: Accepted

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

lcnt = [0] * (max(la) + 3)

for i in range(N):
    lcnt[la[i]+2] += 1
    lcnt[la[i]+1] += 1
    lcnt[la[i]] += 1

print(max(lcnt))

Submission status: Accepted

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

ans = max(memo.values())
print(ans)

Submission status: Accepted

Solution code:

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

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

print(max(b))

Submission status: Accepted

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

for num in a:
    if num==0:
        cnt+=1
        table[0]+=1
        table[1]+=1
    else:
        table[num-1]+=1
        table[num]+=1
        table[num+1]+=1

tmp=max(table)
ans=max(tmp, cnt)
print(ans)

Submission status: Accepted

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

#print(a[0])

b=np.zeros(n,dtype=int)
c=np.zeros(n,dtype=int)

for i in range(n):
    b[i]=a[i]-1
    c[i]=a[i]+1
#print(b)
#print(c)

mylist=[]
mylist.extend(a)
mylist.extend(b)
mylist.extend(c)

#print(mylist)

d=collections.Counter(mylist)
#print(d.most_common())
print(d.most_common()[0][1])

Submission status: Accepted

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

c = collections.Counter(ans)
d = c.most_common()

# for i in range(N):
#     for j in range(N):
#         item.append(a[i][j])



print(d[0][1])

Submission status: Accepted

Solution code:
from collections import Counter

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

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

ans = Counter(a)

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

Submission status: Accepted

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

import collections
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:
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:
# ABC072
# C
# Together
import itertools

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

a.sort()
gr = itertools.groupby(a)
hoge_list = [0]*100001
ans = 0

for key, group in gr:
    hoge_list[key] = len(list(group))

for i in range(1,100000,1):
    _tmp = hoge_list[i-1] + hoge_list[i] + hoge_list[i+1]
    if ans < _tmp:
        ans = _tmp

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

X = [0]*(10**5+4)

op = [-1,0,1]

for i in range(N):
    for j in range(3):
        X[a[i]+op[j]+1] +=1

print(max(X))

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
ad=dict()
ans=0
for i in range(len(a)):
	if a[i] in ad:
		ad[a[i]]+=1
	else:
		ad[a[i]]=1
for i in range(min(ad),max(ad)+1):
	tmp=0
	if i in ad:
		tmp+=ad[i]
	if i-1 in ad:
		tmp+=ad[i-1]
	if i+1 in ad:
		tmp+=ad[i+1]
	if tmp>ans:
		ans=tmp
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

    li=[0]*(10**5+2)
    for i in range(n):
        li[a[i]]+=1

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

    print(cnt)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))

    d=dict()
    for i in range(n):
        if a[i] not in d:
            d[a[i]]=1
        else:
            d[a[i]]+=1

    cnt=0
    for x in range(1,10**5+1):
        if x-1 in d: s=d[x-1]
        else: s=0

        if x in d: t=d[x]
        else: t=0

        if x+1 in d: u=d[x+1]
        else: u=0

        cnt=max(cnt,s+t+u)

    print(cnt)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
l=LI()
lis=[]
for i in range(n):
    lis.append(l[i]-1)
    lis.append(l[i]+1)
    lis.append(l[i])
c=Counter(lis)
u=c.most_common()[0]
print(u[1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
B = []
for i in A:
    B.append(i-1)
    B.append(i)
    B.append(i+1)

C = Counter(B).values()
print(max(C))

Submission status: Accepted

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