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()))
for i in range(N):
    a.append(a[i] - 1)
    a.append(a[i] + 1)
a.sort()
ans = 0
cnt = 1
for i in range(1, len(a)):
    if a[i] == a[i - 1]:
        cnt += 1
    else:
        if cnt > ans:
            ans = cnt
        cnt = 1
if cnt > ans:
    ans = cnt
print(ans)

Submission status: Accepted

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

cand_dict = defaultdict(lambda:0)
for a in A:
    cand_dict[a-1] += 1
    cand_dict[a] += 1
    cand_dict[a+1] += 1
print(max(cand_dict.values()))

Submission status: Accepted

Solution code:
#ABC072C
N=int(input())
A=list(map(int,input().split()))
max_A=max(A)
TGS=[0]*(max_A+1)
ans=0
for i in range(N):
    TGS[A[i]]+=1
for i in range(max_A-1):
    if ans<TGS[i]+TGS[i+1]+TGS[i+2]:
        ans=TGS[i]+TGS[i+1]+TGS[i+2]
if max_A<2:
    ans=N
print(ans)

Submission status: Accepted

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

input_map = {i: 0 for i in range(10**5+1)}
for a in a_list:
    input_map[a] += 1


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

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    items = list(sorted(list(Counter(map(int, input().split())).items())))
    ans = 0
    for i in range(len(items)):
        n = items[i][1]
        if i >= 1:
            if abs(items[i][0] - items[i - 1][0]) == 1:
                n += items[i - 1][1]
        if i < len(items) - 1:
            if abs(items[i][0] - items[i + 1][0]) == 1:
                n += items[i + 1][1]
        ans = max(ans, n)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

    #lst = [0 for i in range(n*3)]
    ans_lst = [0 for i in range(max(a)+4)]
    """
    for i in range(n):
        lst[3*i] = a[i]
        lst[3*i+1] = a[i]+1
        lst[3*i+2] = a[i]+2
    """

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

    """
    ans = -1
    for i in set(lst):
        ans = max(lst.count(i),ans)
    """

    print(max(ans_lst))


if __name__ == "__main__":
        main()

Submission status: Accepted

Solution code:
# vim: set fileencoding=utf-8:
from collections import Counter


def main():
    N = input()
    a = [int(ele) for ele in raw_input().split()]
    a_plus = [ele + 1 for ele in a]
    a_minus = [ele - 1 for ele in a]
    ct = Counter(a)
    ct_plus = Counter(a_plus)
    ct_minus = Counter(a_minus)

    for k, v in ct_plus.items():
        ct[k] += v

    for k, v in ct_minus.items():
        ct[k] += v

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
a = [int(ai) for ai in input().split()]
from collections import Counter
c = Counter(a)
best = 0
for x in c.keys():
    count = c[x] + c.get(x-1, 0) + c.get(x+1, 0)
    best = max(count, best)
print(best)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

count = Counter(A)
sort_count = sorted(count.items())
sort_count.append((0, 0))

best_ans = 0

counter_minus2 = (0, 0)
counter_minus1 = (0, 0)

for i, counter in enumerate(sort_count):
    ans = counter_minus1[1]

    if counter_minus1[0] - counter_minus2[0] == 1:
        ans += counter_minus2[1]

    if counter[0] - counter_minus1[0] == 1:
        ans += counter[1]

    best_ans = max(best_ans, ans)

    counter_minus2 = counter_minus1
    counter_minus1 = counter

print(best_ans)

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
a=list(map(int, input().split()))
b=[]
for i in range(N):
    b.append(a[i])
    b.append(a[i]+1)
    b.append(a[i]-1)
Ctb=Counter(b)
print(max(Ctb.values()))

Submission status: Accepted

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

num = {}
for i in range(n):
    if not a[i] in num.keys():
        num[a[i]] = 1
    else:
        num[a[i]] += 1
    if not a[i]-1 in num.keys():
        num[a[i]-1] = 1
    else:
        num[a[i]-1] += 1
    if not a[i]+1 in num.keys():
        num[a[i]+1] = 1
    else:
        num[a[i]+1] += 1

ans = 0
for k in num.keys():
    ans = max(ans, num[k])
print(ans)

Submission status: Accepted

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

Amax = max(max(A),10)
K = [0] * (Amax+1)

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

ans = 1

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
a = [int(v) for v in input().split()]
cnt = Counter(a)

maxv = 0
for k in cnt:
    maxv = max(maxv, cnt[k-1] + cnt[k] + cnt[k+1])
print(maxv)

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    N = int(input())
    A = li_input()

    ans = 1
    Bkt = [0] * 100001

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

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

    print(ans)


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import groupby
n = int(input())
a = sorted(list(map(int,input().split())))
g = groupby(a)
# 1-indexed
r = [0]*100010
for k,v in g:
    r[k] = len(list(v))
s = []
for i in range(len(r)-2):
    t = r[i] + r[i+1] + r[i+2]
    s.append(t)
print(max(s))

Submission status: Accepted

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

r = defaultdict(int)

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

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

Submission status: Accepted

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

def add_dict(dict, n):
    if n in dict.keys():
        dict[n] += 1
    else:
        dict[n] = 1
    return dict

dict = {}
for ai in a:
    dict = add_dict(dict, ai)
    dict = add_dict(dict, ai+1)
    dict = add_dict(dict, ai-1)

print(max(dict.values()))

Submission status: Accepted

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

count_dct = {}
for i in int_list:
    if i-1 not in count_dct.keys():
        count_dct[i-1] = 1
    if i not in count_dct.keys():
        count_dct[i] = 1
    if i+1 not in count_dct.keys():
        count_dct[i+1] = 1
        
    if i + 1 in count_dct.keys():
        count_dct[i+1] += 1
    if i  in count_dct.keys():
        count_dct[i] += 1
    if i -1 in count_dct.keys():
        count_dct[i-1] += 1
        
print(max(count_dct.values())-1)

Submission status: Accepted

Solution code:
'''input
10
0 1 2 3 4 5 6 7 8 9
'''
n = input()
arr = map(int,raw_input().split())
cou = [0]*(10**5+10)
for i in range(n):
	cou[arr[i]]+=1
	cou[arr[i]+1] += 1
	cou[arr[i]-1] += 1
print max(cou)

Submission status: Accepted

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

a_list = [a_i-i for a_i in a for i in range(-1, 2)]

d = dict()
for a_i in a_list:
	if a_i not in d:
		d[a_i] = 0
	d[a_i] += 1

print(max(d.values()))

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
from collections import Counter

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    counter = Counter(a_list)

    max_cnt = 0
    for i in set(a_list):
        cnt = 0
        cnt += counter[i]
        cnt += counter[i - 1]
        cnt += counter[i + 1]
        if cnt > max_cnt:
            max_cnt = cnt
    print(max_cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

A_p1 = [a+1 for a in A]
A_m1 = [a-1 for a in A]

cnt = Counter(A_p1)
cnt += Counter(A)
cnt += Counter(A_m1)

print(max(list(cnt.values())))

Submission status: Accepted

Solution code:
n=int(input())
l=sorted(list(map(int,input().split())))
p=0
o=len(l)

t=[]
for i in range(o-2):
  while p<o and l[p]-l[i]<=2:
    p+=1
  t.extend([p-i])

if len(l)==1:
  print(1)
elif len(l)==2:
  if abs(l[0]-l[1])<=2:
    print(2)
  else:
    print(1)
else:
  print(max(t))

Submission status: Accepted

Solution code:
def inpl():
    return input().split()

n = int(input())
a = list(map(int, inpl()))
d = {}
for i in range(n):
    d[a[i]] = d.get(a[i], 0) + 1

ans = 0
for k in d.keys():
    b = 0
    b += d.get(k - 1, 0)
    b += d.get(k, 0)
    b += d.get(k + 1, 0)
    ans = max(ans, b)
print(ans)

Submission status: Accepted

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

for i in a :
    if i in d.keys() :
        d[i] += 1
    else :
        d[i] = 1
        
    if i - 1 in d.keys() :
        d[i - 1] += 1
    else :
        d[i - 1] = 1
        
    if i + 1 in d.keys() :
        d[i + 1] += 1
    else :
        d[i + 1] = 1
        
print(max(d.values()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
a = list(map(int,input().split()))
counter = Counter(a)
ans=[]
for k,v in counter.items():
    if k-1 in counter:
        v+=counter[k-1]
    if k+1 in counter:
        v+=counter[k+1]
    ans.append(v)
print(max(ans))

Submission status: Accepted

Solution code:
n = int(input())
a = map(int,input().split())
field = [0 for _ in range(100001)]

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

ans = 0

for i in range(100001-3):
    ans = max(ans,field[i]+field[i+1]+field[i+2])

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
MAX_N = int(1e5) + 1
cnts = [0 for i in range(MAX_N)]
for a in A:
  cnts[a] += 1
res = 0
for idx in range(1, len(cnts) + 1):
  tmp = sum(cnts[idx-1:idx+2])
  if tmp > res:
    res = tmp
print(res)

Submission status: Accepted

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

from collections import Counter 

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

# 各数値ごとに数を集計
AN_dict = Counter(AN)

ans = 0
for key, value in AN_dict.items():
    tmp = 0
    # その数、+1、-1した数の合計を調べて、最大になるものを選ぶ
    tmp += value
    if key-1 in AN_dict:
        tmp += AN_dict[key-1]
    if key+1 in AN_dict:
        tmp += AN_dict[key+1]
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
def line_input(f, type):
    return f(map(type, input().split(" ")))

n = input()
a = line_input(list, int)

c = Counter(a)
so = sorted(c)

cnt = [0] * (max(so) + 1)
for idx in range(0, max(so)+1):
    cnt[idx] = cnt[idx-1] + c[idx]

m = 0
for j in range(1, 4):
    for idx in range(len(cnt)-j):
        m = max(m, cnt[idx + j] - cnt[idx])

for i in c.values():
    m = max(m, i)

print(m)

Submission status: Accepted

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

sum = [0]*100005

for a in A:
	sum[a] += 1
	sum[a+1] += 1
	sum[a+2] += 1

print(max(sum))

Submission status: Accepted

Solution code:
from collections import defaultdict as dd
N = input()
a_raw = list(map(int, input().split()))
num_count = dd(int)
for item in a_raw:
    num_count[item] += 1
    num_count[item-1] += 1
    num_count[item+1] += 1
print(max(num_count.values()))

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
ans=0
d={}
for i in a:
    if i-1 in d:
        d[i-1]+=1
    else:
        d[i-1]=1
    if d[i-1]>ans: ans=d[i-1]
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    if d[i]>ans: ans=d[i]
    if i+1 in d:
        d[i+1]+=1
    else:
        d[i+1]=1
    if d[i+1]>ans: ans=d[i+1]
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
distribution={}
for element in a:
    for num in [element-1,element,element+1]:
        if num not in distribution:
            distribution[num]=1
        else:
            distribution[num]+=1
ans=0
for key in distribution:
    ans = max(ans,distribution[key])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
dic = {}
for nums in A:
  if nums in dic:
    dic[nums] += 1
  else:
    dic[nums] = 1
  if nums-1 in dic:
    dic[nums-1] += 1
  else:
    dic[nums-1] = 1
  if nums+1 in dic:
    dic[nums+1] += 1
  else:
    dic[nums+1] = 1
b = list(dic.values())
print(max(b))

Submission status: Accepted

Solution code:
N=int(input())

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

a_max=100001
ans=[0]*(a_max)

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

ll = [ans[0], ans[0]+ans[1], ans[a_max-2]+ans[a_max-1], ans[a_max-1]]

ans_a=max(ll)

for i in range(a_max-2):
    aa = ans[i]+ans[i+1]+ans[i+2]
    if aa>ans_a:
        ans_a=aa
    
print(ans_a)

Submission status: Accepted

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

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

A_RANGE = range(0, 10 ** 5)

num_of = [0] * 10 ** 5
for ai in a:
    num_of[ai] += 1

max_X = 0
max_count = max(num_of)
max_count_indexes = [i for i, x in enumerate(num_of) if x == max_count]
for i in A_RANGE:
    if (i + 1 in A_RANGE) and (i + 2 in A_RANGE):
            max_X = max(num_of[i] + num_of[i + 1] + num_of[i + 2], max_X)
    if (i - 1 in A_RANGE) and (i + 1 in A_RANGE):
            max_X = max(num_of[i - 1] + num_of[i] + num_of[i + 1], max_X)
    if (i - 2 in A_RANGE) and (i - 1 in A_RANGE):
            max_X = max(num_of[i - 2] + num_of[i - 1] + num_of[i], max_X)
print(max_X)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
limit=100000
count=[]
for i in range(limit):
  count.append(0)
for i in range(n):
  count[a[i]]+=1
x=count[0]+count[1]+count[2]
maxx=x
for i in range(limit-3):
  x+=count[i+3]-count[i]
  maxx=max(maxx,x)
print(maxx)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
bucket=[0]*(max(A)+1)
answer=0
for number in A:
    bucket[number]+=1
if len(bucket)<3:
    answer=sum(bucket)
for i in range(1,max(A)):
    candidate=bucket[i-1]+bucket[i]+bucket[i+1]
    if candidate>answer:
        answer=candidate
print(answer)

Submission status: Accepted

Solution code:
from collections import Counter
import numpy as np

N = int(input())
a = list(map(int, input().split()))
l = [0] * ((10 ** 5) + 5)
c = Counter(a)

for k, v in c.items():
    l[k] = v

c_l = np.cumsum(l)

max_n = c_l[2]
for i in range(3, len(l)):
    max_n = max(max_n, c_l[i] - c_l[i - 3])
print(max_n)

Submission status: Accepted

Solution code:
import collections
N = int(input())
numbers = [int(i) for i in input().split()]
count = collections.Counter(numbers)
biggest = 1
for i in count:
    counting = count[i-1] + count[i] + count[i+1]
    if  counting > biggest:
        biggest = counting

print(biggest)

Submission status: Accepted

Solution code:
n = int(input())

arr = map(int,raw_input().split())

dic = [0 for i in range(10**5)]

for i in arr:
	dic[i] += 1

ans = 0
for i in range(10**5-2):
	ans = max(ans,dic[i]+dic[i+1]+dic[i+2])

print ans

Submission status: Accepted

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

A = sorted(A)
l, r, ans = 0, 0, 0

while r < N:
    if A[r] <= A[l] + 2:
        if r - l + 1 > ans:
            ans = r - l + 1
        r += 1
    else:
        l += 1

print(ans)

Submission status: Accepted

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

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

for a in A:
    xs[a] += 1
    xs[a+1] += 1
    xs[a+2] += 1

print(max(xs))

Submission status: Accepted

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

n = int(input())
A = list(map(int, input().split()))
A_plus = []
for a in A:
    A_plus.append(a+1)
A_minus = []
for a in A:
    A_minus.append(a-1)

B = {}
for a in A:
    if a not in B:
        B[a] = 1
    else:
        B[a] += 1
for a_plus in A_plus:
    if a_plus not in B:
        B[a_plus] = 1
    else:
        B[a_plus] += 1
for a_minus in A_minus:
    if a_minus not in B:
        B[a_minus] = 1
    else:
        B[a_minus] += 1

count = 0
for b in B.keys():
    count = max(count, B[b])

print(count)

Submission status: Accepted

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

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

print(max(c.values()))

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
input_list = sorted([int(i) for i in input().split()])
inupt_dict = (Counter(input_list))
result = 0
input_dict_keys = inupt_dict.keys()

if N == 1:
    result = 1
elif N == 2 and input_list[0] == input_list[1]:
    result = 2
elif N == 2 and input_list[0] != input_list[1]:
    if input_list[1] == input_list[0] + 1:
        result = 2
    else:
        result = 1
else:
    for i in range(N-2):
        if i in input_dict_keys:
            if i+1 in input_dict_keys:
                if i+2 in input_dict_keys:
                    result = max(result, (inupt_dict[i] + inupt_dict[i+1] + inupt_dict[i+2]))
    for i in range(N-1):
        if i in input_dict_keys:
            if i+1 in input_dict_keys:
                result = max(result, (inupt_dict[i] + inupt_dict[i+1]))
    for i in range(N):
        if i in input_dict_keys:
            result = max(result, inupt_dict[i])

print(result)

Submission status: Accepted

Solution code:
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:
cnt = [0]*10**5; input()
a = list(map(int,input().split()))
for x in a:cnt[x]+=1
print(max(map(sum,zip(cnt,cnt[1:],cnt[2:]))))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Whairetsu={}
Xhairetsu={}
Yhairetsu={}


for i in range(len(AN)):
    if AN[i] not in Xhairetsu.keys():
        Xhairetsu[AN[i]]=1
    elif AN[i] in Xhairetsu.keys():
        Xhairetsu[AN[i]]+=1
    
    if AN[i] -1 not in Whairetsu.keys():
        Whairetsu[AN[i]-1]=1
    elif AN[i]-1 in Whairetsu.keys():
        Whairetsu[AN[i]-1]+=1
    
    if AN[i] +1 not in Yhairetsu.keys():
        Yhairetsu[AN[i]+1]=1
    elif AN[i]+1 in Yhairetsu.keys():
        Yhairetsu[AN[i]+1]+=1
    


anshairetsu={}
for i in range(10**5+1):
    if i in Whairetsu.keys():
        if i in anshairetsu.keys():
            anshairetsu[i]+=Whairetsu[i]
        else:
            anshairetsu[i]=Whairetsu[i]
            
    if i in Xhairetsu.keys():
        if i in anshairetsu.keys():
            anshairetsu[i]+=Xhairetsu[i]
        else:
            anshairetsu[i]=Xhairetsu[i]
            
    if i in Yhairetsu.keys():
        if i in anshairetsu.keys():
            anshairetsu[i]+=Yhairetsu[i]
        else:
            anshairetsu[i]=Yhairetsu[i]
print(max(anshairetsu.values()))

Submission status: Accepted

Solution code:
from collections import Counter
import math
import sys
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0]) 

arr01 = [int(x) for x in arr_data[1]]
arr02 = [int(x) + 1 for x in arr_data[1]]
arr03 = [int(x)-1 for x in arr_data[1]]

#print(arr01, arr02, arr03)

arr = Counter(arr01 + arr02 + arr03)

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

Submission status: Accepted

Solution code:
N=int(input())
a=list(input().split())
mydict={}
for i in range (len(a)):
    num=int(a[i])
    if str(str(num-1) in mydict)==str(False):
        mydict[str(num-1)]=1
    else:
        mydict[str(num-1)]+=1
    if str(str(num) in mydict)==str(False):
        mydict[str(num)]=1
    else:
        mydict[str(num)]+=1
    if str(str(num+1) in mydict)==str(False):
        mydict[str(num+1)]=1
    else:
        mydict[str(num+1)]+=1
  
print(max(mydict.values()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

res = []
for item in array:
    res.append(item-1)
    res.append(item)
    res.append(item+1)

res_dict = sorted(dict(collections.Counter(res)).items(), key=lambda x:x[1])
print(res_dict[-1][1])

Submission status: Accepted

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

for a in A:
    c[a] += 1
    c[a+3] -= 1

for i in range(1, n):
    c[i] += c[i-1]

print(max(c))

Submission status: Accepted

Solution code:
MAX = 100000
def m():
    N = int(input())
    a = list(map(int, input().split()))
    t = [0] * (MAX + 1)

    for i in range(N): t[a[i]] += 1
    ans = 0
    tmp = 0
    for n in range(1, MAX):
        ans = max(t[n - 1] + t[n] + t[n + 1], ans)
    return ans

print(m())

Submission status: Accepted

Solution code:
N = int(raw_input())
a = map(int, raw_input().split())
lst = []
max = 0
for i in range(0, 100002):
	lst.append(0)

for i in range(0, N):
	lst[a[i]] = lst[a[i]] + 1

for i in range(1, 100001):
	if lst[i-1] + lst[i] + lst[i+1] > max:
		max = lst[i-1] + lst[i] + lst[i+1]

print max

Submission status: Accepted

Solution code:
from collections import Counter

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

for i in range(0,n):
    canA.append(a[i]-1)
    canA.append(a[i])
    canA.append(a[i]+1)

ans = Counter(canA).most_common(1)
print(ans[0][1])

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d=defaultdict(int)

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

ans=sorted(d.items(),key = lambda x:-x[1])

v,c=ans[0]
print(c)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
ans = {}
for i in A:
    for j in [i-1,i,i+1]:
        if j in ans:
            ans[j] += 1
        else:
            ans[j] = 1
print(max(ans.values()))

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    from bisect import bisect_left
    from bisect import bisect_right

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

    for i in range(max(a) + 1):
        left = bisect_left(a, i - 1)
        right = bisect_right(a, i + 1)
        count = max(count, max(0, right - left))

    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
plus=[0]*n
minus=[0]*n
for i in range(n):
    plus[i]=a[i]+1
    minus[i]=a[i]-1
plus=plus+minus+a
data=Counter(plus)
ans=[]
for i in data.values():
    ans.append(i)
print(max(ans))

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)
    B.append(a-1)
    B.append(a+1)

C = Counter(B).most_common(1)
print(C[0][1])

Submission status: Accepted

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

Submission status: Accepted

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

mx = max(src)
ans = 0
for i in range(mx+1):
    ans = max(ans, ctr[i] + ctr[i+1] + ctr[i+2])
print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
m = max(1, min(a))
M = max(a)
ans=[]
for x in range(m,M):
    ans.append(c[x-1]+c[x]+c[x+1])
if m >= M:
    ans.append(n)
print(max(ans))

Submission status: Accepted

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

times = {}
for i in a:
    for j in range(i-1, i+2):
        times[j] = times.get(j, 0) + 1

m = 0
for k in times:
    if times[k] > m:
        m = times[k]

print(m)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
a_list = [int(elem) for elem in input().split(' ')]

a_count = Counter(a_list)

max_num_x = 0
for key, value in a_count.items():
    num_x = a_count[key-1] + a_count[key] + a_count[key+1]
    if num_x > max_num_x:
        max_num_x = num_x

print(max_num_x)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
aa = []
amax = max(a) + 100


for i in range(amax + 1):
    aa.append(0)

for i in range(len(a)):
    aa[a[i]] = aa[a[i]] + 1
    
kouho = 1    
for j in range(len(aa) - 2):
    if kouho < aa[j] + aa[j + 1] + aa[j + 2]:
        kouho = aa[j] + aa[j + 1] + aa[j + 2]

print(kouho)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0 for k in range(100002)]

for k in A:
    B[k] += 1

ans = 0
for k in range(1,100001):
    ans = max(ans,B[k-1]+B[k]+B[k+1])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding utf-8

from collections import Counter

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

aaa = list()

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

c = Counter(aaa)
mode = c.most_common(1)

print(mode[0][1])

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
for x in range(n):
    a.append(a[x]-1)
    a.append(a[x]+1)
counter = Counter(a)
for name, cnt in counter.most_common():
    print(cnt)
    break

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
counta = [0 for _ in range(100000)]
ans = 0

for elem in a:
    counta[elem] += 1

for x in range(1, 100000 - 1):
    ans = max(ans, counta[x-1] + counta[x] + counta[x+1])

print(ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
a_minus1 = [i-1 for i in a]
a_plus1 = [i+1 for i in a]
a_join = a + a_minus1 + a_plus1
c = collections.Counter(a_join)
print(max(list(c.values())))

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
ans = 0
count = {}
for i in range(0, 10**5+1):
  count[i] = 0

for i in l:
  count[i] = count[i] + 1

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

  if temp > ans:
    ans = temp

print(ans)