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

Solution (Python):

import sys, math, fractions, itertools, collections


def solve(N: int, a: "List[int]"):
    a.sort()
    c = collections.Counter(a)
    cc = dict(c.items())
    mx = 0
    for i in range(a[0], a[-1]+1):
        counter = 0
        for j in range(i-1, i+2):
            if j in c.keys():
                counter += c[j]
        mx = max(counter, mx)
    print(mx)
    return



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

if __name__ == '__main__':
    main()

Solution (Python):

import sys
input = sys.stdin.readline
a = int(input())
b = list(map(int,input().split()))
from collections import defaultdict
d = defaultdict(int)
for i in b:
    d[i]+=1
    d[i-1]+=1
    d[i+1]+=1

ret_v = 0
for v in d.values():
    if v > ret_v:
        ret_v = v
print(ret_v)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
c =[0]*(10**5+2)


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

print(max(c))

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


d = {}
for a in A:
    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()))

Solution (Python):

import sys
from bisect import bisect_left
INF = float("inf")


def solve(N: int, a: "List[int]"):
    a.sort()
    lower, upper = 0, 2
    m = 1
    while lower < 10**5:
        m = max(m, bisect_left(a, upper+1)-bisect_left(a, lower))
        lower += 1
        upper += 1
    print(m)

    return


def main():

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


if __name__ == '__main__':
    main()

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

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

b = [0]*(10**5+1)
for i in a:
    if i == 10**5:
        b[i-1] += 1
        b[i] += 1
    elif i == 0:
        b[i] += 1
        b[i+1] += 1
    else:
        b[i-1] += 1
        b[i] += 1
        b[i+1] += 1

print(max(b))

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

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
 




 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    a = inputList()
    ans = {}
    
    for i, val in enumerate(a):
        if val in ans:
            ans[val] += 1
        else:
            ans[val] = 1
            
        if val+1 in ans:
            ans[val+1] += 1
        else:
            ans[val+1] = 1
            
        if val-1 in ans:
            ans[val-1] += 1
        else:
            ans[val-1] = 1
            
    tmp = 0
    for i in ans.values():
        if tmp < i:
            tmp = i
            
    print(tmp)
    
    
if __name__ == "__main__":
	main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
nums = [0] * (10**5+1)

for num in A:
  if num == 0:
    nums[0] += 1
    nums[1] += 1
  else:
    nums[num-1] += 1
    nums[num] += 1
    nums[num+1] += 1
print(max(nums))

Solution (Python):
import collections


def main():
    N = int(input())
    a = [0] * (N * 3)
    i = 0
    for ele in input().split():
        ele = int(ele)
        a[i] = ele-1
        i += 1
        a[i] = ele
        i += 1
        a[i] = ele+1
        i += 1

    ctr = collections.Counter(a)
    print(max(list(ctr.values())))


if __name__ == "__main__":
    main()

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

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

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
l=[0]*(max(a)+1)
for i in range(n):l[a[i]]+=1
if len(l)<3:print(sum(l))
else:print(max(sum(l[i:i+3]) for i in range(len(l)-2)))

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

    cnt = [0] * 100002

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

main()

Solution (Python):
N  = int(input())
count = [0] * 100001
a = list(map(int, input().split()))

for i in range(N):
    if a[i] == 0:
        count[a[i]] += 1
        count[a[i]+1] += 1
    else:
        count[a[i]-1] += 1
        count[a[i]] += 1
        count[a[i]+1] += 1

ans = max(count)
print(ans)

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
B=[0]*100002
for a in A:
  B[a]+=1
ans=0
for i in range(1,100001):
  ans=max(ans,B[i-1]+B[i]+B[i+1])
print(ans)

Solution (Python):
import bisect

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

num = []
for i in range(min(a), max(a) - 1):
    num.append(bisect.bisect_right(a, i + 2) - bisect.bisect_left(a, i))
if len(num) == 0:
    print(n)
else:
    print(max(num))

Solution (Python):
from bisect import bisect_left, bisect_right

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

A.sort()

ans = 0
for a in range(100000):
    k = bisect_right(A, a+2) - bisect_left(A, a)
    ans = max(ans, k)

print(ans)

Solution (Python):
from collections import Counter

N = int(input())
a = [int(i) for i in input().split()]
number_counter = [list(i) for i in sorted(list(Counter(a).most_common()), key=lambda x: x[0])]
if len(number_counter) == 1:
  number_counter = [[10 ** 6, 0]] + number_counter + [[10 ** 6, 0]]
elif len(number_counter) == 2:
  number_counter += [[10 ** 6, 0]]

count = 0 
for i in range(1, len(number_counter) - 1):
  next_count = number_counter[i][1]
  number = number_counter[i][0]
  if number_counter[i - 1][0] + 1 == number:
    next_count += number_counter[i - 1][1]
  if number_counter[i + 1][0] - 1 == number:
    next_count += number_counter[i + 1][1]
  if next_count > count:
    count = next_count

print(count)

Solution (Python):
t=eval(input())
l=list(map(int,input().split()))
L=[0 for i in range(1000000+3)]
for i in range(t):
    L[l[i]]+=1
    L[l[i] + 1] += 1
    L[l[i] - 1] += 1
print(max(L))

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007


def A():
    x, t = LI()
    print(max(0, x-t))
    return


def B():
    s = S()
    print("".join(s[::2]))
    return


def C():
    II()
    a = LI()
    lis = [0] * (max(a) + 3)
    for ai in a:
        lis[ai - 1] += 1
        lis[ai] += 1
        lis[ai + 1] += 1
    print(max(lis))
    return


def D():
    return


if __name__ == '__main__':
    C()

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007


def A():
    x, t = LI()
    print(max(0, x-t))
    return


def B():
    s = S()
    print("".join(s[::2]))
    return


def C():
    II()
    a = LI()
    lis = [0] * (10**5+2)
    for ai in a:
        lis[ai - 1] += 1
        lis[ai] += 1
        lis[ai + 1] += 1
    print(max(lis))
    return


def D():
    return


if __name__ == '__main__':
    C()

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

a=sorted(a)
a.append(a[-1]+1)
arr=[]
tmp=a[0]
cnt=0
for i in range(N+1):
    if a[i]==tmp:
        cnt+=1
    elif a[i]==tmp+1:
        arr.append(cnt)
        tmp=a[i]
        cnt=1
    else:
        arr.append(cnt)
        step=a[i]-tmp
        for _ in range(step-1):
            arr.append(0)
        tmp=a[i]
        cnt=1
num=0
if len(arr)>=3:
    for i in range(len(arr)-2):
        num=max(num,sum(arr[i:i+3]))
else:
    num=sum(arr)
print(num)

Solution (Python):
N = int(input())
A = [0]*(10**5+2)
a = [int(i) for i in input().split()]

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

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

Solution (Python):
from collections import defaultdict
d = defaultdict(int)
n = int(input())
a = tuple(map(int,input().split()))
for i in a:
  d[i] += 1
m = 0
for i in a:
  m = max(d[i-1] + d[i] + d[i+1],m)
print(m)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
A = []
for b in a:
    A.append(b-1)
    A.append(b)
    A.append(b+1)

A.sort()
count = 1
maxcount =1
for i in range(1,len(A)):
    if A[i] == A[i-1]:
        count = count+1
    else:
        maxcount = max(maxcount,count)
        count = 1

print(maxcount)

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

a_c = Counter(sorted(a))
a_v = list(a_c.values())
a_k = list(a_c.keys())
count_max = a_v[0]
for i in range(1, len(a_v)):
    count = 0
    if a_k[i] - a_k[i - 1] == 1: 
        count += a_v[i - 1]
    if i < (len(a_v) - 1) and a_k[i + 1] - a_k[i] == 1:
        count += a_v[i + 1]
    count += a_v[i]
    if count > count_max:
        count_max = count
print(count_max)

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

a_sorted = sorted(a)
a_v = list(Counter(a_sorted).values())
a_k = list(Counter(a_sorted).keys())
count_max = a_v[0]
for i in range(1, len(a_v)):
    count = 0
    if a_k[i] - a_k[i - 1] == 1: 
        count += a_v[i - 1]
    if i < (len(a_v) - 1) and a_k[i + 1] - a_k[i] == 1:
        count += a_v[i + 1]
    count += a_v[i]
    if count > count_max:
        count_max = count
print(count_max)

Solution (Python):
N = int(input())
l = list(map(int,input().split()))

data = [0]*(100010)
for i in l:
  data[i-1] += 1
  data[i] += 1
  data[i+1] += 1

print(max(data))

Solution (Python):

from collections import Counter

n = int(input())
A = [int(el) for el in input().split(' ')]
C = Counter(A)
max_count = 0
for x in range(min(A), max(A)+1):

    count = C[x-1] + C[x] + C[x+1]

    if count > max_count:
        max_count = count
print(max_count)

Solution (Python):



from itertools import accumulate

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

x = [0]*(10**5+3)

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

x = list(accumulate(x))
print(max(x))

Solution (Python):



from itertools import accumulate

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

x = [0]*(10**5+3)

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

x = list(accumulate(x))
print(max(x))

Solution (Python):
from collections import Counter

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

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

a_counter = Counter(A)
print(a_counter.most_common()[0][1])

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

Solution (Python):
from collections import defaultdict

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

D = defaultdict(lambda: 0)
for a in A:
    D[a] += 1

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

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

b = [0]*100003
for i in a: b[i]+=1
ans = 0
for i in range(100000): ans=max(ans, sum(b[i:i+3]))
print(ans)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
cnt=[0]*100002
for v in a:
  cnt[v]+=1
  cnt[v-1]+=1
  cnt[v+1]+=1
print(max(cnt))

Solution (Python):


import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, = read_h()
    arr = read_h()

    cnts = [0] * 100000
    for a in arr:
        cnts[a] += 1

    ans = 0
    for i in range(len(cnts) - 2):
        c = cnts[i] + cnts[i + 1] + cnts[i + 2]
        if c > ans:
            ans = c

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):


import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, = read_h()
    arr = read_h()

    from collections import Counter
    c = Counter(arr)

    cnt = 0
    for X in c.keys():
        cnt = max(cnt, c.get(X - 1, 0) + c.get(X, 0) + c.get(X + 1, 0))

    print(cnt)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
a.sort()
max_count = 0
count = 0
i = 0
x_before = -1
while i < N:
    x = a[i]
    j = i
    if x_before != x:
        while j < len(a):
            if x == a[j] or x+1 == a[j] or x+2 == a[j]:
                count += 1
                j += 1
            else:
                break
        if max_count < count:
            max_count = count
    x_before = x
    count = 0
    i += 1
print(max_count)

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

Solution (Python):
input()
a = list(map(int,input().split()))
l = [0] * 100000
for c in a:
    if c-1<0:pass
    else:l[c-1]+=1
    l[c] += 1
    if c+1>99999:pass
    else:l[c+1]+=1
print(max(l))

Solution (Python):
import sys
input = sys.stdin.readline

N = int(input())
L = [int(v) for v in input().split()]
ans = {}

for v in L:
    a, b, c = v - 1, v, v + 1
    for p in [a, b, c]:
        if ans.get(p) == None:
            ans[p] = 0
        ans[p] += 1

print(max(ans.values()))

Solution (Python):
import collections

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

a_counter = collections.Counter(a)
ret = 0
for i in range(1,10**5+1):

    tmp = a_counter[i-1] + a_counter[i] + a_counter[i+1]
    ret = max(tmp,ret)

print(ret)

Solution (Python):
N=int(input())
list1=[0 for k in range(-1,10**5+2)]
listA=list(map(int,input().split()))
for i in listA:
  list1[i]+=1
  list1[i+1]+=1
  list1[i+2]+=1
MAX=max(list1)
print(MAX)

Solution (Python):
n = int(raw_input())
arr = map(int, raw_input().split())
freq = [0]*(10**5)
for a in arr:
    freq[a] += 1
count = 0
for i in range(10**5):
    if i == 0:
        count = freq[i] + freq[i+1]
    elif i == 10**5-1:
        count = max(count, freq[i] + freq[i-1])
    else:
        count = max(count, freq[i-1]+freq[i]+freq[i+1])
print count

Solution (Python):

N = int(input())

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


a.sort()

L2 = -2
L1 = -2
now = -2 

N2 = 0
N1 = 0
N0 = 0 

ans = 0


for i in a:

    if i != now:

        if now+1 == i:

            L2 = L1
            N2 = N1
            L1 = now
            N1 = N0

            now = i
            N0 = 1

        else:

            L2 = -2
            L1 = -2
            N2 = 0
            N1 = 0

            now = i
            N0 = 1

    else:

        N0 += 1

    ans = max(ans , N0 + N1 + N2)

print (ans)

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

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

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

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

ruiseki=[0]*(10**5+2)
for i in range(1, 10**5+1):
    ruiseki[i]=num[i-1]+num[i]+num[i+1]

print(max(ruiseki))

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
l.sort()
a=[0]*(l[-1]-l[0]+3)
b=l[0]
for i in range(n):
  l[i]-=b
for i in range(n):
  a[l[i]]+=1
  a[l[i]+1]+=1
  a[l[i]+2]+=1
print(max(a))

Solution (Python):
N = int(input())

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

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

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


ans = 0

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

ans = max(ans, buff[N-2])
ans = max(ans, buff[N-1])
print(ans)

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

count = [0] * 200000

for x in a:
    count[x] += 1

y = 0
for i in range(1, 100000):
    x = count[i - 1] + count[i] + count[i + 1]
    if x > y:
        y = x

print(y)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
L = [0]*(10**5+1)
for i in a:
    L[i] += 1
hoge = sum(L[:3])
ans = hoge
for i in range(10**5-2):
    hoge += L[i+3]-L[i]
    ans = max(ans,hoge)
print(ans)

Solution (Python):
n = int(input())
cnt= [0]*100002
a = list(map(int, input().split()))
for v in a:
    cnt[v-1] += 1
    cnt[v] += 1
    cnt[v+1] += 1

print(max(cnt))

Solution (Python):
n=int(input())
hoge=list(map(int,input().split()))
huga=[0]*(10**5+1)
for i in hoge:
  if(i==10**5):
    huga[i-1]+=1
    huga[i]+=1
  elif(i==0):
    huga[i]+=1
    huga[i+1]+=1
  else:
    huga[i-1]+=1
    huga[i]+=1
    huga[i+1]+=1
print(max(huga))

Solution (Python):
from collections import Counter

N = int(input())
A = [int(zz) for zz in input().split()]
b = Counter(A)
p = list(set(A))
ans = 0
for i in range(len(p)-2):
    q = b[p[i]]+b[p[i+1]]+b[p[i+2]]
    if ans < q:
        ans = q

if N == 2:
    if A[0]-1 <= A[1] <= A[0]+1:
        ans = 2
    else:
        ans = 1
elif N == 1:
        ans = 1

if len(p) == 2:
    if p[0]-1 <= p[1] <= p[0]+1:
        ans = N
    else:
        ans = max(b[p[0]],b[p[1]])
elif len(p) == 1:
    ans = N
    
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
D={}
for a in A:
    if a in D:D[a]=D[a]+1
    else:D[a]=1
    if a-1 in D:D[a-1]=D[a-1]+1
    else:D[a-1]=1
    if a+1 in D:D[a+1]=D[a+1]+1
    else:D[a+1]=1
L=list(D.values())
L.sort(reverse=True)
print(L[0])

Solution (Python):
N=int(input())

from collections import defaultdict
d = defaultdict(int)

for i in input().split():
    d[int(i)] += 1

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

Solution (Python):
n = int(input())
d = {}
a = list(map(int,input().split()))
for i in range(len(a)):
    d[a[i]+1] = 0
    d[a[i]-1] = 0
    d[a[i]] = 0
for i in range(len(a)):
    d[a[i]+1]+=1
    d[a[i]-1]+=1
    d[a[i]]+=1
l = 0
for key in d:
    if(d[key]>l):
        l=d[key]
print(l)

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

Solution (Python):

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

Solution (Python):



n = int(input())
arr = list(map(int, input().split()))
lis = [0 for _ in range(10**5+1)]
hash = dict()
for a in arr:
    lis[a] += 1

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

print(ans)

Solution (Python):
N = int(input())
l = list(map(int, input().split()))
import collections
c = collections.Counter(l + list(map(lambda x: x+1, l)) + list(map(lambda x: x-1, l)))
print(c.most_common()[0][1])

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
b = []
for i in range(n):
    b.extend([a[i], a[i]+1, a[i]-1])

b.sort()
cnt = 1
max_cnt = 0
for i in range(len(b)-1):
    if b[i] == b[i+1]:
        cnt += 1
    else:
        max_cnt = max(max_cnt, cnt)
        cnt = 1

print(max_cnt)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = [0] * (10 ** 5)
    for a in A:
        C[a] += 1
    ans = 0
    for i in range(1, len(C) - 1):
        ans = max(ans, C[i - 1] + C[i] + C[i + 1])
    print(ans)


main()

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = [0] * (10 ** 5)
    for a in A:
        C[a] += 1
    ans = 0
    for i in range(len(C) - 2):
        ans = max(ans, C[i] + C[i + 1] + C[i + 2])
    print(ans)


main()

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
B=[0]*(4+10**5)
for a in A:
    B[a+1]+=1
    B[a]+=1
    B[a+2]+=1
print(max(B))

Solution (Python):
import collections
N=int(input())
L=list(map(int,input().split()))
L.sort()
c = collections.Counter(L)
LL=[c[l-1]+c[l]+c[l+1] for l in set(L)]
print(max(LL))

Solution (Python):
import bisect
n=int(input())
al=list(map(int,input().split()))
al.sort()
sa=set(al)
ans=0
for a in sa:
    ans=max(ans,bisect.bisect_right(al,a+1)-bisect.bisect_left(al,a-1))
print(ans)

Solution (Python):
import collections

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

res = []

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

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

Solution (Python):
n = int(input())

from collections import defaultdict

d1 = defaultdict(int)

for i in input().split():
    d1[int(i)] += 1

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

for i in d1.keys():
    ans[i-1] += d1[i]
    ans[i]   += d1[i]
    ans[i+1] += d1[i]
print(max(ans))

Solution (Python):
import sys
input = sys.stdin.readline

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

Solution (Python):
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:] 

answer = B.max()
print(answer)

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

counter = np.bincount(A)
if len(counter) <= 2:
  answer = counter.sum()
else:
  answer = (counter[2:] + counter[1:-1] + counter[:-2]).max()
print(answer)

Solution (Python):
import numpy as np

N = int(input())


A = np.bincount(np.array(input().split(), dtype=np.int32))

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

answer = B.max()
print(answer)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = [0]*(100000+2)

for i in A:
  ans[i-1] += 1
  ans[i] += 1
  ans[i+1] += 1

  
print(max(ans))

Solution (Python):
N = int(input())
aList = [int(x) for x in input().split()]
x = [0] * 10**5

for a in aList:
    x[a] += 1
    if a > 0:
        x[a-1] += 1
    if N-1 > a:
        x[a+1] += 1
print(max(x))

Solution (Python):
from collections import defaultdict, Counter
import itertools

def main():
    num = int(input())
    data = Counter(list(map(int, input().split())))
    min_num, max_num = min(data.keys()), max(data.keys())

    ans = 0
    for i in range(min_num - 1, max_num + 1):
        kari = data[i - 1] + data[i + 1] + data[i]
        ans = max(kari, ans)
    print(ans)



if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())

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

a.sort()



a = [-2] + a + [-8]

lst = []
count = 1
for i in range(1,N+2):
    if a[i] == a[i-1]:
        count += 1
    else:
        lst += [[a[i-1], count]]
        count = 1



ans = 0
lst += [[-10,0], [-20,0]]

for i in range(0, len(lst)-2):
    count = lst[i][1]
    if lst[i][0] + 1 == lst[i+1][0]:
        count += lst[i+1][1]
        if lst[i][0] +2 == lst[i+2][0]:
            count += lst[i+2][1]
    ans = max(ans, count)

print (ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = {}
for aa in a:
    if aa not in s.keys():
        s[aa] = 1
    else:
        s[aa] += 1
    
    if aa + 1 not in s.keys():
        s[aa+1] = 1
    else:
        s[aa+1] += 1
    
    if aa - 1 not in s.keys():
        s[aa-1] = 1
    else:
        s[aa-1] += 1

print(max(s.values()))

Solution (Python):
n=int(input())
dic=dict()
l=list(map(int,input().split()))
for a in l:
	for i in range(a-1,a+2):
		if i not in dic.keys():
			dic[i]=1
		else:
			dic[i]+=1
print(max(dic.values()))

Solution (Python):

import sys


def solve(N: int, a: "List[int]"):
    counts = [0] * 100000
    a.sort()
    for v in a:
        counts[v] += 1
    ret = 0
    for i in range(len(counts) - 2):
        ret = max(ret, counts[i] + counts[i + 1] + counts[i + 2])
    print(ret)
    return


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

if __name__ == '__main__':
    main()

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

dic = {}

for a in A:
    for i in range(-1,2):
        if a + i in dic:
            dic[a+i] += 1
        else:
            dic[a+i] = 1
print(max(list(dic.values())))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = {}
for aa in a:
    if aa not in s.keys():
        s[aa] = 1
    else:
        s[aa] += 1
    
    if aa + 1 not in s.keys():
        s[aa+1] = 1
    else:
        s[aa+1] += 1
    
    if aa - 1 not in s.keys():
        s[aa-1] = 1
    else:
        s[aa-1] += 1

print(max(s.values()))

Solution (Python):
from collections import Counter
n=int(input())
a=sorted(map(int,input().split()))
ans={}
for i in range(n):
    ans[a[i]]=ans.get(a[i],0)+1
    ans[a[i]+1]=ans.get(a[i]+1,0)+1
    ans[a[i]-1]=ans.get(a[i]-1,0)+1
print(max(ans.values()))

Solution (Python):
N = int(input())

tmp = input().split(" ")

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

for n in tmp:
    nowNum = int(n)
    als[nowNum - 1] += 1
    als[nowNum] += 1
    als[nowNum + 1] += 1


    
print(max(als))

Solution (Python):
import collections

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

plus = []
minus = []

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

all_l = a + minus + plus
ans = collections.Counter(all_l)
print(ans.most_common(1)[0][1])

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
countlist = []
for i in range(0, 100001):
	countlist.append(0)
for i in range(0, N):
	countlist[A[i]] += 1
max = 0
for i in range(0, 100001):
	sum = countlist[i]
	if i != 0: sum += countlist[i-1]
	if i != 100000: sum += countlist[i+1]
	if max < sum: max = sum
print(max)

Solution (Python):
from collections import defaultdict

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

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

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

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

Solution (Python):











import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    from collections import Counter
    N = I()
    a = LI()
    c = Counter(a)
    ans=0
    for i in range(0, max(a) + 1):
        candidate = 0
        for j in range(-1, 2):
            if i + j in c:
                candidate += c[i + j]
        ans = max(ans, candidate)
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

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

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

Solution (Python):
from collections import defaultdict

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

arr_count = defaultdict(int)

for a in arr:
    arr_count[a] += 1

max_x_count = 0
for x in range(1, 10 ** 5):
    x_count = arr_count[x-1] + arr_count[x] + arr_count[x+1]
    max_x_count = max(max_x_count, x_count)

print(max_x_count)

Solution (Python):
import collections as cl

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

plus = [x+1 for x in a]
minus = [x-1 for x in a]
mix = plus  + minus + a 
res = cl.Counter(mix) 
ans = max(res.values())

print(ans)

Solution (Python):
import collections

n=int(input())
a=list(map(int,input().split()))
m=max(a)
cnt=collections.Counter(a)
if m==0:
  print(len(a))
else:
  ans=[0]*(m-1)
  for j in range(m-1):
    ans[j]=cnt[j]+cnt[j+1]+cnt[j+2]
  print(max(ans))

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