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):
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))

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

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

Solution (Python):

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))

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

Solution (Python):



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))

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

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

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

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

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

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

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

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

print(max(cnt))

Solution (Python):


import sys, math, copy




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()

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

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

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

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

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

Solution (Python):

from collections import Counter

n=int(raw_input())
a=map(int,raw_input().split())
a.insert(0,-float('inf'))
for i in xrange(1,n+1):
 a.append(a[i]-1)
 a.append(a[i]+1)
print Counter(a).most_common(1)[0][1]

Solution (Python):
def solve():
    n = int(input())
    a = list(map(int, input().split(" ")))
    ans_dict = {}
    for i in range(n):
        for j in [a[i]-1, a[i], a[i]+1]:
            if j in ans_dict.keys():
                ans_dict[j] += 1
            else:
                ans_dict[j] = 1
    
    print(max(ans_dict.values()))

solve()

Solution (Python):

from collections import Counter

N = int(input())

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

V = []
for a in As:
    V.append(a)
    V.append(a+1)
    V.append(a-1)

cnter = Counter(V)


key, ans = cnter.most_common(1)[0]

print(ans)

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

"""
b = [i + 1 for i in a]
c = [i - 1 for i in a]
use_set = set(a) | set(b) | set(c)
ans = 0
for i in use_set:
    ans = max(ans, a.count(i) + b.count(i) + c.count(i))
print(ans)
"""



ans = {}
for i in a:
    for j in range(3):
        if i + j - 1 not in ans:
            ans[i + j - 1] = 1
        else:
            ans[i + j - 1] += 1

print(max(ans.values()))

Solution (Python):

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

 
minval = min(a)
maxval = max(a)
l = (maxval - minval +1)
 
num = [0]*(l+2)

for i in a:
	num[i-minval] += 1

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

print(ans)

Solution (Python):

from collections import Counter

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

ans = 0
for i in range(max(a)+1):
    temp = col[i-1] + col[i] + col[i+1]
    if temp > ans:
        ans = temp
print(ans)

Solution (Python):
from collections import defaultdict

def C_Together():

    try:
        LOCAL_FLAG
        N = 3
        a = [6, 2, 6]
        
        
        N = 6
        a = [12, 22, 16, 22, 13, 12]

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

    counter = defaultdict(lambda: 0)
    for i in range(N):
        counter[a[i]] += 1

    results = 0
    key = -1

    for k, v in counter.items():
        temp = v + counter.get(k-1, 0) + counter.get(k+1, 0)
        if(temp > results):
            results = temp
            key = k

    print(results)
    

C_Together()

Solution (Python):
cnt = []
for _ in range(10**5+2):
	cnt.append(0)

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

for x in a:
	cnt[x] += 1
	if x > 0 : cnt[x-1] += 1
	cnt[x+1] += 1
	
answer = 0
for n in cnt:
	answer = max(answer, n)

print(answer)

Solution (Python):
from collections import defaultdict
N = int(input())
a = [int(i) for i in input().split(" ")]
dic_num=defaultdict(int)

for i in a:
    dic_num[i] += 1
ans = -1
for X in range(min(a),max(a)+1):
    tmp = (dic_num[X-1] + dic_num[X] + dic_num[X+1])
    if ans < tmp:
        ans = tmp
print(ans)

Solution (Python):
n = int(raw_input())
nums = map(int, raw_input().split())

pos = {}
for i in nums:
    if not i-1 in pos:
        pos[i-1] = 0
    if not i in pos:
        pos[i] = 0
    if not i+1 in pos:
        pos[i+1] = 0

    pos[i-1] += 1
    pos[i] += 1
    pos[i+1] += 1

print max(pos.values())

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

c_list = {}
for i in a:
	if i in c_list:
		c_list[i] += 1
	else:
		c_list[i] = 1

ans = 0
for k, v in c_list.items():
	_sum = c_list[k]
	if (k-1) in c_list:
		_sum += c_list[k-1]
	if (k+1) in c_list:
		_sum += c_list[k+1]
	if _sum > ans:
		ans = _sum
print(ans)

Solution (Python):
import sys
N = int(sys.stdin.readline())
data = [0] * 100000
for i in map(int,sys.stdin.readline().split()):
	data[i] += 1
print(max(map(sum,zip(data,data[1:],data[2:]))))

Solution (Python):
def main():
    N =  int(input())
    a = [int(i) for i in input().split()]
    
    
    
    count_ = [0] * ( max(a)+2 )
    
    
    
    
    
    for num in a:
        if(num > 0):
            count_[num-1] += 1
            count_[num] += 1
            count_[num+1] += 1
        else:
            count_[num] += 1
            count_[num+1] += 1
    
    
    print(max(count_))
    
if __name__=="__main__":
    main()

Solution (Python):
from collections import Counter

n = int(input())
a = map(int, input().split(' '))
c = Counter(a)

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

print(rs)

Solution (Python):
import sys
import copy
import numpy as np

from math import *
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func()
    input_str = input_raw.strip().split()
    value_dic = {}
    for i in range(N):
        val = int(input_str[i])
        if val in value_dic:
            value_dic[val] += 1
        else:
            value_dic[val] = 1

        if val - 1 in value_dic:
            value_dic[val - 1] += 1
        else:
            value_dic[val - 1] = 1

        if val + 1 in value_dic:
            value_dic[val + 1] += 1
        else:
            value_dic[val + 1] = 1

    print max(value_dic.values())

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

N=input()
nums=map(int,raw_input().split(' '))
num = np.zeros(100000,dtype='int')
for i in nums:
    num[i] = num[i] + 1
max=0
for i in range(100000-2):
    if max < num[i] + num[i+1] + num[i+2]:
        max = num[i] + num[i+1] + num[i+2]
print max

Solution (Python):

from collections import Counter
N = int(input())
A = tuple(map(int, input().split()))

c0 = Counter()
c1 = Counter()
c2 = Counter()
for a in A:
    c0[(a+0)//3] += 1
    c1[(a+1)//3] += 1
    c2[(a+2)//3] += 1
    
print(max(max(c0.values()),
          max(c1.values()),
          max(c2.values())))

Solution (Python):
import collections
n = input()
a = list(map(int, input().split()))
s = collections.Counter(a);
res = 0
for i in range(10 ** 5 + 1):
    b = 0
    if i in s:
        b += s[i]
    if i - 1 in s:
        b += s[i - 1]
    if i + 1 in s:
        b += s[i + 1]
    res = max(res, b)
print(res)

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

Solution (Python):
n=input()
s=raw_input().split()
a=[0 for i in range(n)]
b=[0 for i in range(100005)]
mini=1000005
maxi=-1
for i in range(n):
    a[i]=int(s[i])
    b[a[i]]+=1
maxi=-1
for i in range(100001):
    maxi=max(maxi,b[i]+b[i+1]+b[i+2])
print maxi

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

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    a = input()
    a = a.split(' ')
    a = list(map(int, a))

    min_a = min(a)
    max_a = max(a)

    num = []

    for i in range(max_a+1):
        num.append(0)

    for i in a:
        if i-2 >= 0:
            num[i-2] += 1
        if i-1 >= 0:
            num[i-1] += 1
        num[i] += 1

    c = max(num)
    print(c)

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

M = 10**5

L = [0]*M


for i in map(int,input().split()):
  L[i] += 1

c = sum(L[:3])
b = c

for i,j in zip(range(3,M),range(M-3)):
  c += L[i]
  c -= L[j]
  b = max(b,c)

print(b)

Solution (Python):
import sys 

N = int(sys.stdin.readline())
alist = map(int, sys.stdin.readline().strip().split())
summary = {}
for a in alist:
    summary[a] = summary.get(a, 0) + 1                                                                                                                                                                                                
    summary[a - 1] = summary.get(a -1, 0) + 1 
    summary[a + 1] = summary.get(a +1, 0) + 1 
print max(summary.values())

Solution (Python):
n=int(input())
l=[int(x) for x in input().split()]

l1=[0]*(100002)

for i in range(n):
	l1[l[i]]+=1
	l1[l[i]+1]+=1
	l1[l[i]-1]+=1

print(max(l1))

Solution (Python):
N = int(raw_input())
A = map(int, raw_input().split())

count = {}
ans = 1
def INC(x):
    global count
    if x in count:
        count[x] += 1
    else:
        count[x] = 1

for x in A:
    INC(x-1)
    INC(x)
    INC(x+1)

for a, b in count.items():
    ans = max(ans, b)
print ans

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

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

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

res = 0
for i in range(1,100002):
  res = max(res, freqs[i-1] + freqs[i] + freqs[i+1])

print(res)

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))

    result_counter = [0 for i in range(100001)]
    for number in a:
        if number == 0:
            result_counter[0] += 1
            result_counter[1] += 1
        else:
            result_counter[number - 1] += 1
            result_counter[number] += 1
            result_counter[number + 1] += 1

    print(max(result_counter))

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

B = []
for i in A:
    B.append(i - 1)
    B.append(i)
    B.append(i + 1)
B.sort()

C = []
count = 0
for i in range(len(B)):
    if B[i] == B[i - 1]:
        count += 1
    else:
        C.append(count + 1)
        count = 0

print(max(C))

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
ap = [e + 1 for e in a]
am = [e - 1 for e in a]

table = [0 for _ in range(10**5 + 2)]
for e in a:
    table[e + 1] += 1
    table[(e+1) + 1] += 1
    table[(e-1) + 1] += 1
print(max(table))

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

Solution (Python):
from collections import Counter

N = int(input())
a_list = list(map(int, input().split()))
am_list = list(map(lambda x: x - 1, a_list))
ap_list = list(map(lambda x: x + 1, a_list))
data = a_list + am_list + ap_list
c = Counter(data)
print(c.most_common(1)[0][1])

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

Solution (Python):
n=int(raw_input())
a=[int(i) for i in raw_input().split(' ')]
res={}
for i in a:
    for p in (i,i-1,i+1):
            res[p]=res.get(p,0)+1
if len(res)>0:
    print  max(res.values())

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

counts = [0] * (10**5 + 2)
for a_i in a:
    counts[a_i + 1] += 1

counts_all = [0] * (10**5)
for i in range(10**5):
    counts_all[i] += (counts[i] + counts[i + 1] + counts[i + 2])

print(max(counts_all))

Solution (Python):
n = int(raw_input())
nums = map(int, raw_input().split())
from collections import Counter
c = Counter(nums)
ans = 0
for k in c:
    ans = max(ans, c[k] + c[k-1] + c[k+1])
print ans

Solution (Python):
n = int(input())
ar = [int(x) for x in input().split()]

cnt = {}
for x in ar:
        def add(x):
                if x in cnt:
                        cnt[x] += 1
                else:
                        cnt[x] = 1
        add(x-1)
        add(x)
        add(x+1)

counts = map(lambda x: x[1], cnt.items())
ans = max(counts)

print(ans)

Solution (Python):

from collections import Counter
N = int(input())
A = tuple(map(int, input().split()))

c0 = Counter()
c1 = Counter()
c2 = Counter()
for a in A:
    c0[(a+0)//3] += 1
    c1[(a+1)//3] += 1
    c2[(a+2)//3] += 1
    
print(max(sorted(c0.values(), reverse = True)[0],
          sorted(c1.values(), reverse = True)[0],
          sorted(c2.values(), reverse = True)[0]))

Solution (Python):
import collections


M = 10 ** 5 + 10


def solve(n, xs):
    ctr = collections.Counter(xs)
    freqs = [ctr[i] for i in range(0, M)]
    res = max(sum(freqs[i: i + 3]) for i in range(M - 3))
    return res


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    print(solve(n, xs))


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
xs = [int(x) for x in input().split()]
xmap = {}
for x in xs:
    if x in xmap:
        xmap[x] += 1
    else:
        xmap[x] = 1
    if x+1 in xmap:
        xmap[x+1] += 1
    else:
        xmap[x+1] = 1
    if x-1 in xmap:
        xmap[x-1] += 1
    else:
        xmap[x-1] = 1
ret = 0
for x in xmap.keys():
    if xmap[x] > ret:
        ret = xmap[x]
print(ret)

Solution (Python):
import sys
from collections import Counter
sys.setrecursionlimit(10**6)
n=int(input())
a=[int(i) for i in input().split()]
b=[]
for i in range(n):
 b.append(a[i])
 b.append(a[i]+1)
 b.append(a[i]-1)
c = Counter(b).most_common(1)
print(c[0][1])

Solution (Python):


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

b = []

for ai in a:
    b.append(ai-1)
    b.append(ai)
    b.append(ai+1)


import collections
cnt = collections.Counter(b)

print(max(cnt.values()))

Solution (Python):
n = int(input())
a = [int(num) for num in input().split()]

a.sort()
count = []
for i in range(100001 + 1):
    count.append(0)

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

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

print(max)

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

Solution (Python):
from collections import defaultdict

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    c = defaultdict(int)
    for i in A:
        c[i] += 1
        c[i - 1] += 1
        c[i + 1] += 1
    print(sorted(c.items(), key=lambda x: x[1], reverse=True)[0][1])

if __name__ == '__main__':
    main()

Solution (Python):
def spaceinput():
    return list(map(int,input().split(" ")))


N=int(input())
a=spaceinput()



H=[0]*(10**5+1)
for sa in a:
    H[sa]+=1

maxsum=0
for i in range(1,len(H)-1):
    sum=H[i-1]+H[i]+H[i+1]
    if maxsum<sum:
        maxsum=sum

print(maxsum)

Solution (Python):


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

b = []

for ai in a:
    b.append(ai-1)
    b.append(ai)
    b.append(ai+1)


import collections
cnt = collections.Counter(b)

print(max(cnt.values()))

Solution (Python):
N = int(raw_input())
arr = map(int, raw_input().split(" "))

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

answer = 0
for v in d.itervalues():
  if v > answer: answer = v

print answer

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

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

    for a in A:
        D[a] += 1
        D[a+1] += 1
        if a-1 >= 0:
            D[a-1] += 1

    print(max(D))

        
if __name__ == "__main__":
    main()

Solution (Python):

def main():
	n = int(input())
	nums = list(map(int, input().split()))
	counter = [0 for _ in range(max(nums) + 3)]

	for x in nums:
		counter[x] += 1
		counter[x + 1] += 1
		counter[x + 2] += 1

	print(max(counter))

if __name__ == '__main__':
	main()

Solution (Python):
def solve():
    n = int(input())
    al = [int(i) + 1 for i in input().split()]
    amax = max(al) + 3
    ans = [0] * amax
    for i in al:
        ans[i] += 1
        ans[i-1] += 1
        ans[i+1] += 1
    print(max(ans))



if __name__=="__main__":
    solve()

Solution (Python):
N=int(raw_input())
A=map(int, raw_input().split())
B = [0 for i in range (100000+3)]
for a in A:
    B[a+2]+=1
    B[a+1]+=1
    B[a]+=1
print max(B)

Solution (Python):

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

for a in a_list:
    if a not in cnt_dict.keys():
        cnt_dict[a] = 0
    cnt_dict[a] += 1
    if a+1 not in cnt_dict.keys():
        cnt_dict[a+1] = 0
    cnt_dict[a+1] += 1
    if a-1 not in cnt_dict.keys():
        cnt_dict[a-1] = 0
    cnt_dict[a-1] += 1

print(max(list(cnt_dict.values())))

Solution (Python):
from collections import Counter

values_nr = int(input())
idx___value = [int(x) for x in input().split()]

value_counter = Counter()
for value in idx___value:
    value_counter[value] += 1
    value_counter[value + 1] += 1
    value_counter[value - 1] += 1

print(max(value_counter.values()))

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

cnt = {}
for ai in a:
    if ai in cnt:
        cnt[ai] += 1
    else:
        cnt[ai] = 1

ans = 0
for ai in cnt.keys():
    tmp = cnt[ai]
    tmp += cnt[ai - 1] if (ai - 1) in cnt else 0
    tmp += cnt[ai + 1] if (ai + 1) in cnt else 0
    ans = max(ans, tmp)

print(ans)

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N = int(input())
As = list(map(int, input().split()))
c = Counter(As)

ans = 0
for i in range(100000):
    ans = max(ans, c[i-1] + c[i] + c[i+1])
print(ans)

Solution (Python):

from collections import defaultdict

def II(): return int(input())
def ILI(): return list(map(int, input().split()))


def read():
    N = II()
    a = ILI()
    return N, a


def solve(N, a):
    count = defaultdict(int)
    for _a in a:
        count[_a - 1] += 1
        count[_a] += 1
        count[_a + 1] += 1
    l_count = list(count.items())
    l_count.sort(key = lambda x: -x[1])
    ans = l_count[0][1]
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

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

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

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

Solution (Python):


import collections

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

    c = collections.Counter()
    for i in a:
        c[i] += 1
        c[i-1] += 1
        c[i+1] += 1
    return c.most_common(1)[0][1]


print(main())

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
f = [0 for i in range(100005)]
for x in a:
    f[x + 1] += 1
maks = 0
for i in range(1, 100002):
    maks = max(maks, f[i - 1] + f[i] + f[i + 1])
print(maks)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    a = LI()
    d = collections.defaultdict(int)
    for c in a:
        d[c-1] += 1
        d[c] += 1
        d[c+1] += 1

    return max(d.values())


print(main())

Solution (Python):
from collections import Counter
n = int(input())
C = Counter(map(int, input().split()))
opt = -1
for x in C:
    opt = max(opt, C[x-1]+C[x]+C[x+1])
print(opt)