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()))
Acount = [0] * (max(A) + 1)
ans = 0

for i in range(n):
    Acount[A[i]] = Acount[A[i]] + 1

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

if max(A) == 0 or max(A) == 1:
    ans = len(A)

print(ans)

Submission status: Accepted

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
l=[]
for x in a:
    l.append(x-1)
    l.append(x)
    l.append(x+1)
print(collections.Counter(l).most_common()[0][1])

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
ns = list(map(int, input().split()))
dic = defaultdict(int)
max_n = 0
for i in ns:
    dic[i] += 1
    max_n = max(max_n, i)
result = 0

for i in ns:
    result = max(result, dic[i]+dic[i+1]+dic[i-1])
print(result)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()

a=max(arr)

mat=[0]*(a+3)

for i in range(n):
    mat[arr[i]]+=1
    mat[arr[i]+1]+=1
    mat[arr[i]+2]+=1
print(max(mat))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
mat=limii()

a=max(mat)


# 初期化（ABC035Cオセロだと最初はすべて黒と仮定される）
arr = [0] * (a+3)

# いもす法の加算処理
for jj in range(n):
    l, r = mat[jj],mat[jj]+2  # 区間[l, r]の入力を受け取る
    arr[l] += 1
    if r+1 != a+3:
        arr[r+1] -= 1
#print(arr)
# いもす法の累積和（構築処理）
cum = [0] * (a+3)
for i in range( a+3):
    cum[i] += cum[i-1] + arr[i]
#print(cum)
# 答えを出力
ans = max(cum[1:])
print(ans)

Submission status: Accepted

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

print(max(ans))

Submission status: Accepted

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

r = 0
for i in range(10**6):
    r = max(r, d[i] + d[i-1] + d[i+1])
print(r)

Submission status: Accepted

Solution code:
import sys
import math
import fractions
import bisect
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288

'''
1行のint
N, K = map(int, input().split())

1行のstring
S, T = input().split()

1行の整数配列
P = list(map(int,input().split()))

改行あり
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

'''

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

can = [0]*(int(1e5+10))
for n in A:
    can[n] += 1
    can[n-1] += 1
    can[n+1] += 1

ans = 0
big = 0
for i in range(int(1e5+1)):
    if big < can[i]:
        big = can[i]
        ans = i

print(big)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[0]*(10**5+1)
for i in range(0,N):
    B[A[i]]=B[A[i]]+1
m=B[0]
for i in range(0,10**5):
    x=0
    if i==0:
        x=B[0]+B[1]
        if x>m:
            m=x
    else:
        x=B[i-1]+B[i]+B[i+1]
        if x>m:
            m=x
print(m)

Submission status: Accepted

Solution code:
import collections

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

nums = []
roll = [-1,0,1]

for i in range(N):
  for j in range(3):
    d = A[i] + roll[j]
    nums.append(d)

num = collections.Counter(nums).most_common()
print(num[0][1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
from _collections import defaultdict
from functools import lru_cache

class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def map_int():
        return [int(x) for x in Scanner.string().split()]
    def string_list(n):
        return [input() for i in range(n)]
    def int_list_list(n):
        return [Scanner.mapInt() for i in range(n)]
    def int_cols_list(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True

MOD = int(1e09) + 7

def main():
    N = Scanner.int()
    A = Scanner.map_int()
    M = defaultdict(int)
    for i in range(N):
        M[A[i]] +=1
        M[A[i] + 1]+=1
        M[A[i] - 1]+=1
    ans = 0
    for v in M.values():
        ans = max(ans,v)
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))
    C = defaultdict(int)
    for a in A:
        C[a] += 1

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
L = [0 for i in range(max(A)+1)]
for i in range(N):
  L[A[i]] += 1
mL = []
if len(L) >= 3:
  for j in range(len(L)-2):
    mL.append(L[j] + L[j+1] + L[j+2])
else:
  for j in range(3-len(L)):
    L.append(0)
  mL = [L[0]+L[1]+L[2]]
print(max(mL))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
t = [0] * (max(a) + 2)
for x in a:
  if x > 0: t[x - 1] += 1
  t[x] += 1
  t[x + 1] += 1
print(max(t))

Submission status: Accepted

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

lst = [0 for i in range(100009)]
for a in As:
  lst[a-1] += 1
  lst[a] += 1
  lst[a+1] += 1
print(max(lst))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
d={}
mina=min(a)
maxa=max(a)
for i in range(mina-1,maxa+2):
  d[i]=0
for i in a:
  d[i]+=1
ans=0
for i in range(mina,maxa+1):
  ans=max(ans,d[i-1]+d[i]+d[i+1])
print(ans)

Submission status: Accepted

Solution code:
input()
L = list(map(int, input().split()))
m = min(L)
M = max(L)
a = [0]*(M-m+3)
for i in L:
    a[i-m] += 1
    a[i-m+1] += 1
    a[i-m+2] += 1
print(max(a))

Submission status: Accepted

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

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

# print(d[:10])
print(max(d))

Submission status: Accepted

Solution code:
n = int(input())
dic = {}

for i in map(int, input().split()):
    for j in range(i-1, i+1+1):
        if j not in dic:
            dic[j] = 0
        dic[j] += 1

print(max(dic.values()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
A=sorted(list(map(int,input().split())))
L={}
if n==1:
        print(1)
elif n==2:
    if abs(A[0]-A[1])==1:
        print(2)
    else:
        print(1)
else:
    for i in A:
        if i not in L:
            L[i]=1
        else:
            L[i]+=1
    ans=[]
    for j in range(A[0],A[-1]+1):
        if (j in L) and (j-1 in L) and (j+1 in L):
            ans.append(L[j]+L[j+1]+L[j-1])
        elif (j in L) and (j-1 in L):
            ans.append(L[j-1]+L[j])
        elif (j in L) and (j+1 in L):
            ans.append(L[j+1]+L[j])
        elif (j-1 in L) and (j+1 in L):
            ans.append(L[j+1]+L[j-1])
        elif (j in L):
            ans.append(L[j])
    print(max(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ARC082C
import copy
import sys
import math

n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

hoge.sort()
hoge.append(-1)
a=0
b=0
c=1
maxhoge=0
for i in range(0,n):
	if(hoge[i]!=hoge[i+1]):
		if(i!=n-1):
			if(hoge[i+1]-hoge[i]==1):
				a=b
				b=c
				c=1
			elif(hoge[i+1]-hoge[i]==2):
				a=c
				b=0
				c=1
			else:
				a=0
				b=0
				c=1
	else:
		c+=1
#	print("i:{} | {} {} {}".format(i,a,b,c))

	maxhoge=max(maxhoge,a+b+c)



#print(hoge)
print(maxhoge)

Submission status: Accepted

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

counts = {}

for a in A:
    if a in counts:
        counts[a] += 1
    else:
        counts[a] = 1
        
    if a - 1 in counts:
        counts[a - 1] += 1
    else:
        counts[a - 1] = 1
        
    if a + 1 in counts:
        counts[a + 1] += 1
    else:
        counts[a + 1] = 1
        
print(max(counts.values()))

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int, input().split()))
c = {}
for i in b:
    if i not in c:
        c[i] = 1
    else:
        c[i] += 1
    if i+1 not in c:
        c[i+1] = 1
    else:
        c[i+1] += 1
    if i-1 not in c:
        c[i-1] = 1
    else:
        c[i-1] += 1
c = sorted(c.items(), key=lambda x: x[1], reverse=True)
print(c[0][1])

Submission status: Accepted

Solution code:
N = int(input())
dic = {}
for i in range(10 ** 5):
    dic[i] = 0
dic[-1] = 0
dic[10 ** 5] = 0

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

ans = 0
for v in dic.values():
    ans = max(ans, v)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
num = [0 for i in range(200000)]
for i in range(N):
    num[A[i]-1] += 1
    num[A[i]] += 1
    num[A[i]+1] += 1
print(str(max(num)))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
cnt = Counter(map(int, input().split()))
res = max(v + cnt.get(k - 1, 0) + cnt.get(k - 2, 0) for k, v in cnt.items())
print(res)

Submission status: Accepted

Solution code:
# ARC082C - Together (ABC072C)
def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    ans = [0] * 100001
    for i in lst:
        ans[i] += 1
    print(max(map(sum, zip(ans, ans[1:], ans[2:]))))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

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

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Accepted

Solution code:
N = int(input())
li = [ int(it) for it in input().split() ]

dp=[0]*(100000+11)

for it in li:
  dp[it] += 1
  dp[it+1] += 1
  dp[it+2] += 1
  
ma = 0
for it in dp:
  ma = max(it,ma)

print ( ma )

Submission status: Accepted

Solution code:
# ARC082C - Together (ABC072C)
n = int(input())
lst = list(map(int, input().rstrip().split()))
ans = [0] * 100001
for i in lst:
    ans[i] += 1
print(max(map(sum, zip(ans, ans[1:], ans[2:]))))

Submission status: Accepted

Solution code:
input();a=[0]*100000
for i in input().split():a[int(i)]+=1
print(max(map(sum,zip(a,a[1:],a[2:]))))

Submission status: Accepted

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

dic = {}
for a in A:
    for i in [-1,0,1]:
        dic[a+i] = dic.get(a+i,0) + 1

m = 0
ans = 0
for d in dic:
    if dic[d] > m:
        ans = d
        m = dic[d]
print(m)

Submission status: Accepted

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

cnt = [0]*(10**6)

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

ans = max(cnt)
print(ans)

Submission status: Accepted

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

b = [0 for i in range(-1,max(a)+2)]
for x in a:
  b[x-1]+=1
  b[x]+=1
  b[x+1]+=1
print(max(b))

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
As = map(int, input().split())

counts = defaultdict(int)
for a in As:
    counts[a-1] += 1
    counts[a] += 1
    counts[a+1] += 1

print(max(counts.values()))

Submission status: Accepted

Solution code:
import collections
N=int(input())
A=list(map(int,input().split(' ')))
counter=collections.Counter(A)
Y=sorted(list(counter.keys()))
ans=-1
if max(Y)-min(Y)<=2:
  ans=N
else:
  Y_all = [ counter[i] for i in range(min(Y),max(Y)+1) ]
  for i in range(len(Y_all)-2):
    ans = max(sum(Y_all[i:i+3]), ans)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = [int(_) for _ in input().split()]
ans = [0]*(10**5+1)

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

print(max(ans))

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
d = Counter(map(int, input().split()))
cnt = 0
for i in d:
  new = d.get(i,0) + d.get(i-1,0) + d.get(i+1,0)
  if new > cnt:
    cnt = new
print(cnt)

Submission status: Accepted

Solution code:
input();a=[0]*100000
for i in map(int,input().split()):a[i]+=1
print(max(map(sum,zip(a,a[1:],a[2:]))))

Submission status: Accepted

Solution code:
from collections import Counter

if __name__ == '__main__':
    n = int(input())
    a = [int(s) for s in input().split()]
    print(max(Counter(a + [x - 1 for x in a] + [x + 1 for x in a]).values()))

Submission status: Accepted

Solution code:
N = int(input())

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

counter = [0] * 100001

for a in A:
  if a:
    counter[a-1]+=1
    counter[a]+=1
    counter[a+1]+=1
  else:
    counter[a]+=1
    counter[a+1]+=1

print(max(counter))

Submission status: Accepted

Solution code:
N = input()
d = {}
for a in map(int, raw_input().split()):
  d[a - 1] = d.get(a - 1, 0) + 1
  d[a] = d.get(a, 0) + 1
  d[a + 1] = d.get(a + 1, 0) + 1
print max(d.values())

Submission status: Accepted

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

x=[0 for i in range(-1,10**5+10)]

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

x=sorted(x)

for i in reversed(x):
        if(not i<0):
                print(i)
                exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 10 10:05:08 2019

@author: shinjisu
"""


# ARC 076 C
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def dmp(x):
    global debug
    if debug:
        print(x)
    return x


def probC():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    maxA = max(A)
    dmp(maxA)
    b = zeros(maxA+3)
    for i in range(N):
        b[A[i]] += 1
        b[A[i]+1] += 1
        b[A[i]+2] += 1
    dmp(b)
    return dmp(max(b))


debug = False  # True False
print(probC())

def probCTLE2():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    hist = zeros(10**5)
    for i in range(N):
        if A[i] in hist:
            hist[A[i]] += 1
        else:
            hist[A[i]] = 1
    #dmp(hist)
    mxCnt = 1
    #keylist = list(hist.keys())
    #mxKey = max(keylist)
    # dmp(mxKey)
    for k in range(10**5-2):
        cnt = hist[k] + hist[k+1] + hist[k+2]
        mxCnt = max(mxCnt, cnt)
    return mxCnt


def probCTLE():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    hist = {}
    for i in range(N):
        if A[i] in hist:
            hist[A[i]] += 1
        else:
            hist[A[i]] = 1
    dmp(hist)
    mxCnt = 1
    keylist = list(hist.keys())
    mxKey = max(keylist)
    dmp(mxKey)
    for k in hist.keys():
        cnt = 0
        if k-1 in keylist:
            cnt += hist[k-1]
        if k in keylist:
            cnt += hist[k]
        if k+1 in keylist:
            cnt += hist[k+1]
        mxCnt = max(mxCnt, cnt)
        dmp(('max',mxCnt))
    return mxCnt


def probCWA():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    hist = {}
    for i in range(N):
        if A[i] in hist:
            hist[A[i]] += 1
        else:
            hist[A[i]] = 1
    dmp(hist)
    mxCnt = 1
    keylist = list(hist.keys())
    mxKey = max(keylist)
    dmp(mxKey)
    for i in range(mxKey-1):
        cnt = 0
        if i in keylist:
            cnt += hist[i]
        if i+1 in keylist:
            cnt += hist[i+1]
        if i+2 in keylist:
            cnt += hist[i+2]
        mxCnt = max(mxCnt, cnt)
        dmp(('max',mxCnt))
    return mxCnt

Submission status: Accepted

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

Submission status: Accepted

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

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

    a.sort()
    r = 0
    i, j = 0, 0
    while i < N:
        while j < N:
            if a[j] - a[i] <= 2:
                j += 1
            else:
                break
        r = max(r, j - i)
        if j == N:
            break
        i += 1

    print(r)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

ans = 0
for a, b, c in zip(l, l[1:], l[2:]):
    ans = max(ans, a+b+c)

print(ans)

Submission status: Accepted

Solution code:
import collections

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

counter = collections.defaultdict(int)
for b in a:
    counter[b - 1] += 1
    counter[b] += 1
    counter[b + 1] += 1

print(max(counter.values()))

Submission status: Accepted

Solution code:
import collections


N = int(input())
A = list(map(int, input().split(' ')))
A_plus = [A[i]+1 for i in range(len(A))]
A_minus = [A[i]-1 for i in range(len(A))]
ans = collections.Counter(A + A_plus + A_minus).most_common()[0][1]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
def inpl(): return [int(i) for i in input().split()]
ctr = [0 for _ in range(10**5+2)]
a = inpl()
for i in a:
     ctr[i] += 1
subsum = ctr[0] + ctr[1] + ctr[2]
ans = subsum
for i in range(2,10**5+1):
    subsum = subsum - ctr[i-2] + ctr[i+1]
    ans = max(ans, subsum)
print(ans)

Submission status: Accepted

Solution code:
lis=[0]*((10**5)+10)
N=int(input().strip())
a=list(map(int, input().split()))
for i in range(N):
    lis[a[i]-1]+=1
    lis[a[i]]+=1
    lis[a[i]+1]+=1
lis.sort(reverse=True)
print(lis[0])

Submission status: Accepted

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

import collections

cnt = collections.Counter(A)

minval = min(A)
maxval = max(A)

ret = 0
for i in range(minval, maxval+1):
    s = cnt[i - 1] + cnt[i] + cnt[i + 1]
    ret = max([ret, s])

print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

count = [0 for _ in range(10 ** 5 + 1)]
for a in A:
    count[a] += 1

ret = 0

for i in range(1, 10 ** 5):
    ret = max(ret, count[i - 1] + count[i] + count[i + 1])

print(ret)

Submission status: Accepted

Solution code:
N = int(input())
L = [0 for i in range(100003)]

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

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

print(max(L))

Submission status: Accepted

Solution code:
from collections import defaultdict,Counter
N=int(input())
A=[int(i) for i in input().split()]
dd=defaultdict(int)
for a in A:
    dd[a]+=1
    dd[a-1]+=1
    dd[a+1]+=1
print(Counter(dd).most_common(1)[-1][-1])

Submission status: Accepted

Solution code:
import collections

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
f = lambda: map(int,input().split())

n = int(input())
a = list(f())
c = [0]*100005
for i in a:
    c[i]+=1
    c[i-1]+=1
    c[i+1]+=1
print(max(c))

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N = read()
cnt = Counter()
for a in reads():
  cnt[a-1] += 1
  cnt[a] += 1
  cnt[a+1] += 1

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

Submission status: Accepted

Solution code:
# cook your dish here
import bisect
n=int(input())
a = list(map(int,input().split()))	
a.sort()
b = list(set(a))

ass = []
if len(b) == 1:
    print(n)
elif len(b) == 2:
    if b[0] == b[1] or b[0] - 1 == b[1] or b[0] + 1 == b[1]:
        print(n)
    else:
        k1 = bisect.bisect_left(a,b[0])
        k2 = bisect.bisect_right(a,b[0])
        print(max(k2-k1,n-k2+k1))
else:
    for i in range(len(b)-2):
        if b[i+1] == b[i] + 2:
            k1 = bisect.bisect_left(a,b[i])
            k2 = bisect.bisect_right(a,b[i+1])
            ass.append(k2-k1)
        elif b[i+1] == b[i] + 1:
            if b[i+2] == b[i] + 2:
                k1 = bisect.bisect_left(a,b[i])
                k2 = bisect.bisect_right(a,b[i+2])
                ass.append(k2-k1)
            else:
                k1 = bisect.bisect_left(a,b[i])
                k2 = bisect.bisect_right(a,b[i+1])
                ass.append(k2-k1)
        else:
            k1 = bisect.bisect_left(a,b[i])
            k2 = bisect.bisect_right(a,b[i])
            ass.append(k2-k1)
    k1 = bisect.bisect_left(a,b[len(b)-1])
    k2 = bisect.bisect_right(a,b[len(b)-1])
    ass.append(k2-k1)
    k1 = bisect.bisect_left(a,b[len(b)-2])
    k2 = bisect.bisect_right(a,b[len(b)-2])
    ass.append(k2-k1)
    
    print(max(ass))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

if __name__ == "__main__":
    n = int(input())
    a = map(int, input().split())
    cnt = [0 for i in range(0, int(1e5 + 5))]
    for x in a:
        cnt[x] += 1
        cnt[x + 1] += 1
        if x > 0:
            cnt[x - 1] += 1
    print(max(cnt))

Submission status: Accepted

Solution code:
X = [0 for i in range(10**5+40)]

n = int(input())

a = input().split(' ')

for a_ in a:
    a_ = int(a_)
    for i in [-1,0,1]:
        X[a_ + i] +=1
print(max(X))

Submission status: Accepted

Solution code:
input()
d = [0] * 100002
for x in map(int, input().split()):
  d[x + 1] += 1
print(max(d[i] + d[i + 1] + d[i + 2] for i in range(99999)))

Submission status: Accepted

Solution code:
from collections import Counter
from operator import itemgetter

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

c = Counter(a)

def num(n):
	if n in c.keys():
		return c[n]
	else:
		return 0

candidate = num(0) + num(1) + num(2)
ans = candidate

for i in range(1, 99998):
	candidate -= num(i-1)
	candidate += num(i+2)
	if candidate > ans:
		ans = candidate

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
from operator import itemgetter

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

c = Counter(a)

def num(n):
	if n in c.keys():
		return c[n]
	else:
		return 0

ans = 0

for i in range(99998):
	candidate = num(i) + num(i+1) + num(i+2)
	if candidate > ans:
		ans = candidate

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

b ={i:0 for i in range(min(min(a),-1),max(a)+10)}
for i in a:
    b[i] += 1


c = 0
for i in range(len(b)-3):
    c = max(c,b[i]+b[i+1]+b[i+2])
print(c)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())

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

Adec = list(map(lambda x:x-1,A))
Ainc = list(map(lambda x:x+1,A))

Asum = Counter(A+Adec+Ainc)

print(max(Asum.values()))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
cnt = [0]*((10**5)+2) #-1 ~ 10**5+1

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

print(max(cnt))

Submission status: Accepted

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

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(input())
    ai = list(map(int, input().split()))
    assert len(ai) == n
    cnt = [0 for i in range(100002)]
    for a in ai:
        for b in [a, a + 1, a + 2]:
            cnt[b] += 1
    print(max(cnt))

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
puls=[]
minu=[]
for i in range(n):
    puls.append(a[i]+1)
    minu.append(a[i]-1)
a.extend(puls)
a.extend(minu)
import collections
data=collections.Counter(a)
data=sorted(data.items(),key=lambda x:x[1],reverse=True)
print(data[0][1])

Submission status: Accepted

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

ans=1

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

Submission status: Accepted

Solution code:
N = int(input())
a = [0 for i in range(N)]
st = input().split()
for i in range(N):
  a[i] = int(st[i])
m = min(a); M = max(a)
b = [0 for i in range(M - m + 1)]
for i in range(N):
  b[a[i]-m] += 1
c = [0 for i in range(M - m + 1)]
if len(b) >= 2:
	c[0] = b[0] + b[1]
	c[M - m] = b[M - m] + b[M - m - 1]
	for i in range(1, M - m):
	  c[i] = b[i-1] + b[i] + b[i+1]
	print(max(c))
else:
  print(max(b))

Submission status: Accepted

Solution code:
from collections import Counter

N=int(input())
a_lst = [int(_) for _ in input().split()]

c = Counter(a_lst)
mi = min(a_lst)
ma = max(a_lst)

ans = 0
for i in range(mi, ma + 1):
    score = c[i] + c[i+1]+c[i+2]
    ans = max(ans, score)
print(ans)