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 = input()
s = list(map(int,input().split()))

MAX = max(s)
nums = [0]*(MAX+1)

if MAX == 0:
    print(n)
    exit()

for i in s:
    if i == 0:
        nums[0] += 1
        nums[1] += 1
    elif i == MAX:
        nums[-1] += 1
        nums[-2] += 1
    else:
        nums[i-1] += 1
        nums[i] += 1
        nums[i+1] += 1

print(max(nums))

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
MaxA = max(As) + 1
numbers = [0] * (MaxA+1)
for i in range(N):
    A = As[i]
    if A != 0:
        numbers[A-1] += 1
    numbers[A] += 1
    numbers[A+1] += 1
print(max(numbers))

Submission status: Accepted

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

Submission status: Accepted

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

for aa in a:
    t=0
    t+=c[aa]
    t+=c[aa-1]
    t+=c[aa+1]
    ans=max(ans,t)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt = {}
for x in a:
    if x not in cnt:cnt[x] = 1
    else:cnt[x] +=1
ans = 0
for key in cnt:
    res = 0
    if key in cnt:res += cnt[key]
    if key-1 in cnt:res += cnt[key-1]
    if key+1 in cnt:res += cnt[key+1]
    ans = max(ans,res)
print(ans)

Submission status: Accepted

Solution code:
# Problem C - Together

import collections

# input
N = int(input())
a_list = list(map(int, input().split()))

# initialization
num_counter = collections.Counter(a_list)
max_count = 0

# count
for k in num_counter.keys():
    nc = num_counter[k]
    tmp_mae = num_counter[k-1]
    tmp_ushiro = num_counter[k+1]
    max_count = max(max_count, nc + tmp_mae + tmp_ushiro)

# output
print(max_count)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array(input().split(), dtype = np.int32)

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

ans = B.max()
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import collections
n = int(input())
a = [int(i) for i in input().split()]

ans = 0
c = collections.Counter(a)
b = list(set(a))
for i in range(len(b)):
    tmp = c[b[i] - 1] + c[b[i]] + c[b[i] + 1]
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

ans = 0
for a in range(max(A) + 1):
    ans = max(ans, cnt[a - 1] + cnt[a] + cnt[a + 1])
print(ans)

Submission status: Accepted

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

    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
 
set_a = set(a)
cnt = [0] * (max(a)+1)
ans = 0
 
for i in a:
    cnt[i] += 1
 
if len(cnt) == 1:
    print(cnt[0])
elif len(cnt) == 2:
    print(sum(cnt))
else:
    for i in range(1, max(a)):
        ans = max(ans, cnt[i-1]+cnt[i]+cnt[i+1])

    print(ans)

Submission status: Accepted

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

for i in range(1, 100000):
    right_idx = bisect.bisect_left(A, i - 1)
    left_idx = bisect.bisect_right(A, i + 1)
    tmp_ans = left_idx - right_idx
    if tmp_ans > ans:
        ans = tmp_ans
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    ans = 0
    for k in c.keys():
        cur = c[k-1] + c[k] + c[k+1]
        ans = max(cur, ans)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    a = tuple(map(int,input().split()))
    cnt = [0]*1000000
    for i in a:
        if i!=0:
            cnt[i-1]+=1
        cnt[i]+=1
        cnt[i+1]+=1
    mx = (0,0)
    for i in range(100100):
        if cnt[i]>mx[0]:
            mx = (cnt[i],i)
    print(mx[0])
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

ans = 0
for c in counter[:-2]:
    ans = max(ans, c)
print(ans)

Submission status: Accepted

Solution code:
import collections

N = int(input())
A = map(int, input().split())
CA = collections.Counter(A)

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

Submission status: Accepted

Solution code:
from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

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

    AA=Counter(A)

    ans=0
    if N==1:
        print(1)
    elif N==2:
        if abs(A[0]-A[1])<=1:
            print(2)
        else:
            print(1)
    else:
        for i in range(N-2):
            ans=max(AA[i]+AA[i+1]+AA[i+2],ans)
        print(ans)

resolve()

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=int)

U = 10 ** 5 + 1
b = np.bincount(A, minlength=U)
c = np.zeros(U, dtype=int)
c[:-1] += b[1:]
c[1:] += b[:-1]
c += b

print(c.max())

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

from collections import defaultdict

cnt = defaultdict(int)

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

print(max(cnt.values()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
b = Counter(a)
c = list(set(a))
c.sort()
ans = 0
for i in range(len(c)):
    tmp = b[c[i]]
    if i > 0 and c[i - 1] == c[i] - 1:
        tmp += b[c[i - 1]]
    if i < len(c) - 1 and c[i + 1] == c[i] + 1:
        tmp += b[c[i + 1]]
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = max(a)
s = collections.Counter(a)
answer = s[0]+s[1]
for i in range(1,b+1):
    result=s[i-1] + s[i] + s[i+1]
    if (answer < result):
        answer = result
print(answer)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import collections
n = int(input())
a = [int(i) for i in input().split()]

ans = 0
c = collections.Counter(a)
#print(c)
#print(set(a))
b = list(set(a))
for i in range(len(b)):
    tmp = c[b[i] - 1] + c[b[i]] + c[b[i] + 1]
    #print(tmp)
    if ans < tmp:
        ans = tmp
print(ans)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
b = Counter(a)
c = list(set(a))
l = len(c)
if l == 1:
    print(n)
    exit()
ans = 0
for i in range(l):
    tmp = b[c[i]]
    if i > 0 and c[i - 1] + 1 == c[i]:
        tmp += b[c[i - 1]]
    if i < l - 1 and c[i] + 1 == c[i + 1]:
        tmp += b[c[i + 1]]
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import Counter


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

    count = Counter(A)

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

    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

cnt = [0]*(10**5+2)
for a in A:
    cnt[a] += 1
ans = []
for a in A:
    if a == 0:
        ans.append(cnt[a] +cnt[a+1])
    else:
        ans.append(cnt[a-1] + cnt[a] +cnt[a+1])
print(max(ans))

Submission status: Accepted

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

sub = [0]*(max(a)+3)
for i in range(n):
  sub[a[i]] += 1
  sub[a[i]+1] += 1
  sub[a[i]+2] += 1
print(max(sub))

Submission status: Accepted

Solution code:
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
# 0が混ざってる場合に対応して、１ずつ足しておく
a = [i+1 for i in a]

# 10**5だと99999がコーナーケースになる
l = [0] * 10 ** 6
# いもす法
for i in a:
    l[i-1] += 1
    l[i+2] -= 1

b = accumulate(l)
print(max(list(b)))

Submission status: Accepted

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

c = Counter(A)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
n = int(input())
line = list(map(int,input().split()))
box = []
for i in line:
  box.append(i)
  box.append(i-1)
  box.append(i+1)
newbox = collections.Counter(box)
answer = max(newbox.values())
print(answer)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
ap = [i + 1 for i in a]
am = [i - 1 for i in a]

a3 = []
a3.extend(a)
a3.extend(ap)
a3.extend(am)
a3 = [str(i) for i in a3]

from collections import Counter
c = Counter(a3)
c = dict(c)

print(max(c.values()))

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
A = sorted(A)
from bisect import bisect_left
ans = 0
for i in range(0, A[-1]+1):
  cnt = bisect_left(A, i+2) - bisect_left(A, i-1)
  ans = max(ans, cnt)
  #print(i, cnt)
print(ans)

Submission status: Accepted

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

if max(a)<=1:
    print(N)
else:
    cnt=[0]*(max(a)+1)
    for val in a:
        cnt[val]+=1
    #print(cnt)

    tri=[cnt[i]+cnt[i+1]+cnt[i+2] for i in range(len(cnt)-2)]
    #print(tri)
    print(max(tri))

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()
set_a = list(set(a))

import collections
count = collections.Counter(a)

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N=int(input())
    A=list(map(int,input().split()))
    AA=Counter(A)
    maxval=0
    for i in AA.keys():
        maxval=max(AA[i-1]+AA[i]+AA[i+1],maxval)

    print(maxval)



resolve()

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = [int(x) for x in input().split()]
seq = Counter(s)

ans = 1
for val in s:
    ans = max(ans, seq[val-1] + seq[val] + seq[val+1])
print(ans)

Submission status: Accepted

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

    mx = -1
    for i in range(1,10**5):
        sm = counter[i-1]+counter[i]+counter[i+1]
        mx = max(sm,mx)
        
    print(mx)




if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import collections
import sys
n=int(input())
a=list(map(int,input().split()))
b=list(collections.Counter(a).items())
b.sort(key=lambda x:int(x[0]))
if len(b)==1:
  print(n)
  sys.exit()
lst=[]
num=b[0][1]
if int(b[1][0])-int(b[0][0])==1:
  num+=b[1][1]
lst.append(num)
for i in range(1,len(b)-1):
  num=b[i][1]
  if int(b[i+1][0])-int(b[i][0])==1:
    num+=b[i+1][1]
  if int(b[i][0])-int(b[i-1][0])==1:
    num+=b[i-1][1]
  lst.append(num)
num=b[len(b)-1][1]
if int(b[len(b)-1][0])-int(b[len(b)-2][0])==1:
  num+=b[len(b)-2][1]
lst.append(num)
print(max(lst))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

bucket = [0 for i in range(max(a) + 1)]

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


sum_three_num = []

if len(bucket) == 1:
    sum_three_num.append(bucket[0])
elif len(bucket) == 2:
    sum_three_num.append(bucket[0] + bucket[1])
else:
    for i in range(1, len(bucket) - 1):
        sum_three_num.append(bucket[i-1] + bucket[i] + bucket[i+1])

print(max(sum_three_num))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
A = 0
renzoku = 0
a_ta = [0]
for i in range(N):
    if A == a[i]:
        renzoku += 1
        pass
    elif A + 1 == a[i]:
        a_ta.append(renzoku)
        renzoku = 1
        A = a[i]
    else:
        a_ta.append(renzoku)
        tobi = a[i] - A - 1
        A = a[i]
        renzoku = 1
        for j in range(tobi):
            a_ta.append(0)
a_ta.append(renzoku)
a_ta.append(0)

ans = []
#print(a_ta)
for i in range(len(a_ta)-2):
    b = sum(a_ta[i:i+3])
    ans.append(b)

print(max(ans))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S1 = [int(i) for i in input().split(" ")]
S2 = [i+1 for i in S1]
S3 = [i-1 for i in S1]
S = S1+S2+S3
c = Counter(S)
print(max(c.values()))

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

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
c = Counter(map(int, input().split()))
c = sorted(c.items())

if len(c) == 1:
    print(c[0][1])
    exit()

if len(c) == 2:
    if c[1][0] - c[0][0] == 1:
        print(c[0][1]+c[1][1])
    else:
        print(max(c[0][1], c[1][1]))
    exit()

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

print(ans)

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
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
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 = 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 collections
n, *a = map(int, open(0).read().split())
a_plus = [i+1 for i in a]
a_minus = [i-1 for i in a]
c = collections.Counter(a+a_plus+a_minus)
print(c.most_common()[0][1])

Submission status: Accepted

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

ans = [0] * (int(1e5)+2)
for i in range(n):
    ans[a[i]-1] += 1
    ans[a[i]] += 1
    ans[a[i]+1] += 1

print(max(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Author: cr4zjh0bp
# Created: Tue Mar 24 00:01:43 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import defaultdict

n = ni()
a = na()

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

print(max(d.values()))

Submission status: Accepted

Solution code:
#072_C
n = int(input())
a = list(map(int, input().split()))
sa = [0 for _ in range(0, 100001)]
for ai in a:
    sa[ai] += 1
    
ans = 0
for i in range(1, 100000):
    ans = max(ans, sa[i-1] + sa[i] + sa[i+1])
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

na = {}
for i in a:
    x = i - 1
    y = i
    z = i + 1
    na.setdefault(x, 0)
    na.setdefault(y, 0)
    na.setdefault(z, 0)
    na[x] += 1
    na[y] += 1
    na[z] += 1

print(max(na.values()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input()
l=sorted(map(int,input().split()))
from bisect import *
a=0
for i in range(l[0],l[-1]+1):
  a=max(a,bisect(l,i+1)-bisect_left(l,i-1))
print(a)

Submission status: Accepted

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

Submission status: Accepted

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

res = 0
for i in range(0, len(cnt)-2):
    val = sum(cnt[i:i+3])
    if res < val:
        res = val

print(res)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter
from itertools import chain
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, a: "List[int]"):
    ctr = Counter(chain.from_iterable(
        (ai - 1, ai, ai + 1)
        for ai in a
    ))
    print(ctr.most_common(1)[0][1])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

l_plus = list(i+1 for i in l)
l_minus = list(i-1 for i in l)
total =l + l_plus + l_minus

from collections import Counter
c = Counter(total)
print(sorted(c.values())[-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict


def solve():
    _ = int(input())
    a = list(map(int, input().split()))
    
    counter = defaultdict(int)
    for ai in a:
        counter[ai] += 1
        counter[ai + 1] += 1
        counter[ai - 1] += 1
    
    ans = 0
    for val in counter.values():
        ans = max(ans, val)
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

for i in range(n):
    mini, mid, maxi = a[i], a[i]+1, a[i]+2
    ans[mini] += 1;  ans[mid] += 1;  ans[maxi] += 1

print(max(ans))

Submission status: Accepted

Solution code:
n=int(input())

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

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

for a in t:
    memo[a-1] += 1
    memo[a] += 1
    memo[a+1] += 1
print(max(memo))

Submission status: Accepted

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

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

for ai in a:
    X[ai-1] += 1
    X[ai] += 1
    X[ai+1] += 1

print(max(X))

Submission status: Accepted

Solution code:
import numpy as np
import collections
n = int(input())
a = list(map(int,input().split()))
t = [0 for i in range (100001)]
max = 0
ac = collections.Counter(a)
for i in range(1,100000):
    max = np.maximum(max,ac[i-1]+ac[i]+ac[i+1])
print(max)

Submission status: Accepted

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

L = []
for i in a_L:
    L.append(i+1)
    L.append(i-1)
    L.append(i)

import collections

L = collections.Counter(L)

L = sorted(L.items(),key=lambda x: x[1],reverse=True)
print(L[0][1])

Submission status: Accepted

Solution code:
n = int(input().strip())
a = list(map(int, input().split()))
a.sort()
counts = []
now = a[0]
count = 0
for e in a:
    if e == now:
        count += 1
    else:
        counts.append([now, count])
        now = e
        count = 1
counts.append([now, count])

if len(counts) == 1:
    print(counts[0][1])
elif len(counts) == 2:
    if (counts[0][0] + 1) == counts[1][0]:
        print(counts[0][1] + counts[1][1])
    else:
        print(counts[0][1])
else:
    ans = counts[0][1]
    for i in range(len(counts) - 2):
        rep = counts[i + 1][1]
        if (counts[i][0] + 1) == counts[i + 1][0]:
            rep += counts[i][1]
        if (counts[i + 1][0] + 1) == counts[i + 2][0]:
            rep += counts[i + 2][1]
        ans = max(rep, ans)
    print(ans)

Submission status: Accepted

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

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

ans = sorted(d.values(),reverse = True)
print(ans[0])

Submission status: Accepted

Solution code:
from collections import Counter

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

for i in a:
  if i-1 in ans:
    ans[i-1]+=1
  else:
    ans.setdefault(i-1,1)  

  if i in ans:
    ans[i]+=1
  else:
    ans.setdefault(i,1)
    
  if i+1 in ans:
    ans[i+1]+=1
  else:
    ans.setdefault(i+1,1)

answer= sorted(ans.values())
print(answer[-1])

Submission status: Accepted

Solution code:
def main():
  import sys
  input = sys.stdin.readline
  n=input()
  a=tuple(map(int,input().split()))
  cnt=[0]*(max(a)+3)
  for i in a:
    cnt[i]+= 1
  x,y,z=cnt,cnt[1:],cnt[2:]
  print(max(map(sum,zip(x,y,z))))  
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
def main():
  import sys
  input = sys.stdin.readline
  n=input()
  a=tuple(map(int,input().split()))
  cnt=[0]*(pow(10,5)+2)
  for i in a:
    cnt[i-1]+=1
    cnt[i]+=1
    cnt[i+1]+=1
  print(max(set(cnt)))   
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
def main():
  n=input()
  a=tuple(map(int,input().split()))
  cnt=[0]*(pow(10,5)+2)
  for i in a:
    cnt[i-1]+=1
    cnt[i]+=1
    cnt[i+1]+=1
  print(max(set(cnt)))   
if __name__=='__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

ac = Counter(a)

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

Submission status: Accepted

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

A = Counter(a)

ans = 0

for x in A.keys():
    ans = max(ans, A[x]+A[x-1]+A[x+1])
    
print(ans)

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

M = 10**5

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

cnt = [0]*(M+2)
for a in A:
    cnt[a] += 1

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

count_dict = {}

for i in nums:
    num_minus = i - 1
    num = i
    num_plus = i + 1
    count_dict.setdefault(num_minus, 0)
    count_dict.setdefault(num, 0)
    count_dict.setdefault(num_plus, 0)
    count_dict[num_minus] += 1
    count_dict[num] += 1
    count_dict[num_plus] += 1
    
print(max(count_dict.values()))

Submission status: Accepted

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

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

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
ans = 0
for x in range(min(a), max(a)+1):
  ans = max(ans, d[x-1] + d[x] + d[x+1])
print(ans)