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


from numpy import array

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    ys = array(list(map(lambda x: [x-1, x, x+1], xs))).flatten()
    ys.sort()
    cnt = 0
    m = 0
    prev = ys[0]
    for y in ys:
        if y == prev:
            cnt += 1
        else:
            if m < cnt:
                m = cnt
            prev = y
            cnt = 1
    print(m)

if __name__ == "__main__":
    main()

Solution (Python):


import numpy as np

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    ys = np.array(list(map(lambda x: [x-1, x, x+1], xs))).flatten()
    ys.sort()
    cnt = 0
    m = 0
    prev = ys[0]
    for y in ys:
        if y == prev:
            cnt += 1
        else:
            if m < cnt:
                m = cnt
            prev = y
            cnt = 1
    print(m)

if __name__ == "__main__":
    main()

Solution (Python):


import numpy as np

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    ys = np.array(list(map(lambda x: [x-1, x, x+1], xs))).flatten()
    ys.sort()
    cnt = 0
    m = 0
    prev = ys[0]
    for y in ys:
        if y == prev:
            cnt += 1
        else:
            if m < cnt:
                m = cnt
            prev = y
            cnt = 1
    print(m)

if __name__ == "__main__":
    main()

Solution (Python):


from collections import defaultdict
from functools import reduce
from itertools import groupby, chain

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]

def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    ys = chain.from_iterable([[x-1, x, x+1] for x in xs])
    ys = sorted(list(ys))
    m = max(map(len, group(ys)))
    print(m)

def group(xs):
    result = list()
    prev = xs[0]
    temp = list()
    for x in xs:
        if x == prev:
            temp.append(x)
        else:
            result.append(temp)
            prev = x
            temp = [x]
    return result

if __name__ == "__main__":
    main()

Solution (Python):


from collections import defaultdict
from functools import reduce
from itertools import groupby, chain

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]

def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    ys = chain.from_iterable([[x-1, x, x+1] for x in xs])
    ys = sorted(list(ys))
    cnt = 0
    m = 0
    prev = ys[0]
    for y in ys:
        if y == prev:
            cnt += 1
        else:
            if m < cnt:
                m = cnt
            prev = y
            cnt = 1
    print(m)

if __name__ == "__main__":
    main()

Solution (Python):


from collections import defaultdict
from functools import reduce
from itertools import groupby, chain

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]

def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    ys = chain.from_iterable([[x-1, x, x+1] for x in xs])
    ys = sorted(list(ys))
    m = max([len([1 for _ in x]) for (i, x) in groupby(ys)])
    print(m)

if __name__ == "__main__":
    main()

Solution (Python):


from collections import defaultdict
from functools import reduce
from itertools import groupby

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    
    ys = concat_map(xs, lambda x: [x, x+1, x-1])
    ys.sort()
    print(max(map(lambda x: count(x[1]), groupby(ys))))

def concat_map(xs, f):
    return reduce(lambda accum, x: extended(accum, x), map(f, xs))

def extended(xss, xs):
    xss.extend(xs)
    return xss

def count(iterator):
    cnt = 0
    for _ in iterator:
        cnt += 1
    return cnt

if __name__ == "__main__":
    main()

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())
cnt = [0] * 100010
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()))
from collections import defaultdict
dd=defaultdict(int)
for a in arr:
    dd[a-1]+=1
    dd[a]+=1
    dd[a+1]+=1
ans=0
for k in dd.keys():
    ans=max(ans,dd[k])
print(ans)

Solution (Python):
n = int(raw_input())
l = map(int, raw_input().split())
c = [0 for _ in xrange(10**5+1)]
for i in l:
    c[i] += 1
ans = 0
for i in xrange(1,10**5):
    ans = max(ans, c[i-1]+c[i]+c[i+1])
print ans

Solution (Python):
input()
get_data = input().split(' ')  
count = dict()
for v in get_data:
  if v not in count.keys():
    count[v] = 1
  else:
    count[v] += 1

count_result = count.items()
dup = dict()
for v in count_result:
  key = v[0]
  dup[key] = v[1]
  key_to_int = int(key)
  if str(key_to_int+1) in count.keys():
    dup[key] += count[str(key_to_int+1)]
  if str(key_to_int-1) in count.keys():
    dup[key] += count[str(key_to_int-1)]
  
  
print(int(sorted(dup.items(), key=lambda v: v[1], reverse=True)[0][1]))

Solution (Python):


N=int(input())
mozir=input()

hyo=mozir.split(' ')
a=[int(mono) for mono in hyo]

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


for suu in a:
    hindo[suu]+=1


ansidx=None
tokuten=0
for idx in range(1,10**5,1):
    tmp=hindo[idx-1]+hindo[idx]+hindo[idx+1]
    if tmp > tokuten:
        tokuten=tmp
        ansidx=idx

print(tokuten)

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):
def solve():
    N = int(input())
    a = list(map(int, input().split()))
    count = [0]*100000

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

    print(max(map(sum,zip(count,count[1:],count[2:]))))


if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
a = [int(i) for i in input().split(" ")]
b = [0 for _ in range(100002)]

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

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

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

b = []
c = []

for i in range(N):
    if a[i] > 0:
        b.append(a[i] - 1)
        c.append(a[i] + 1)
    else:
        c.append(a[i] + 1)

abc = a + b + c
count = [0] * (max(abc) + 1)

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

print(max(count))

Solution (Python):

"""

"""



if __name__ == '__main__':
    n = int(input())
    data = [0 for _ in range(100000+2)]
    nums = [int(x) for x in input().split(' ')]
    for num in nums:
        data[num] += 1

    max_ans = 0
    for x in range(100000):
        temp = sum(data[x:x+3])
        if temp > max_ans:
            max_ans = temp
    print(max_ans)

Solution (Python):


class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def count_and_drop(xs):
    cnt = 0
    key = xs[0]
    for x in xs:
        if x != key:
            break
        cnt += 1
    del xs[:cnt]
    return (key, cnt)


def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    xs.sort()
    ys = dict()
    while xs:
        key, cnt = count_and_drop(xs)
        ys[key] = cnt
    m = 0
    for x in ys.keys():
        temp = ys.get(x-1, 0) + ys.get(x, 0) + ys.get(x+1, 0)
        if m < temp:
            m = temp
    print(m)

if __name__ == "__main__":
    main()

Solution (Python):


class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def count_and_drop(xs):
    cnt = 0
    fst = xs[-1]
    for x in reversed(xs):
        if x != fst:
            break
        cnt += 1
    del xs[-cnt:]
    return cnt


def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    xs.sort()
    ys = dict()
    while xs:
        key = xs[-1]
        cnt = count_and_drop(xs)
        ys[key] = cnt
    m = 0
    for x in ys.keys():
        temp = ys.get(x-1, 0) + ys.get(x, 0) + ys.get(x+1, 0)
        if m < temp:
            m = temp
    print(m)

if __name__ == "__main__":
    main()

Solution (Python):


from collections import defaultdict

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def count_and_del(xs):
    cnt = 0
    fst = xs[-1]
    for x in reversed(xs):
        if x != fst:
            break
        cnt += 1
    del xs[-cnt:]
    return cnt   


def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    xs.sort(reverse=True)
    ys = defaultdict(int)
    while xs:
        key = xs[-1]
        cnt = count_and_del(xs)
        ys[key] += cnt
        ys[key-1] += cnt
        ys[key+1] += cnt

    print(max(ys.values()))


if __name__ == "__main__":
    main()

Solution (Python):


from collections import defaultdict

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def count_and_del(xs):
    cnt = 0
    fst = xs[-1]
    for x in reversed(xs):
        if x != fst:
            break
        cnt += 1
    del xs[-cnt:]
    return cnt   


def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    xs.sort(reverse=True)
    ys = defaultdict(int)
    while xs:
        key = xs[-1]
        cnt = count_and_del(xs)
        ys[key] += cnt
        ys[key-1] += cnt
        ys[key+1] += cnt

    print(max(ys.values()))


if __name__ == "__main__":
    main()

Solution (Python):
def solve(): 
    N = int(input())
    a = list(map(int, input().split(" ")))
    mode = [0] * 1000000

    for element in a:
        mode[element-1] += 1
        mode[element] += 1
        mode[element+1] += 1

    print(max(mode))
    
   
solve()

Solution (Python):


from collections import defaultdict

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def count_and_del(xs):
    cnt = 0
    fst = xs[0]
    
    for x in xs:
        if x != fst:
            break
        cnt += 1
    del xs[:cnt]
    return cnt   

def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    xs.sort()
    ys = defaultdict(int)
    while xs:
        key = xs[0]
        cnt = count_and_del(xs)
        ys[key] += cnt
        ys[key-1] += cnt
        ys[key+1] += cnt

    print(max(ys.values()))


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
N = int(input())
temp = input()
a = np.array([int(i) for i in temp.split()])

list_X = [0]*1000000

for ele in a:
    list_X[ele] += 1
    list_X[ele-1] += 1
    list_X[ele+1] += 1

print(max(list_X))

Solution (Python):


from collections import defaultdict





    






    










def first_count_and_pop(xs):
    cnt = 0
    fst = xs[0]
    
    for x in xs:
        if x != fst:
            break
        cnt += 1
    return (cnt, xs[cnt:])    
    

def main():
    _ = input()
    
    xs = [int(x) for x in input().split()]
    xs.sort()
    ys = defaultdict(int)
    
    
    
    
    for x in xs:
        key = x
        ys[key] += 1
        ys[key-1] += 1
        ys[key+1] += 1

    print(max(ys.values()))



























if __name__ == "__main__":
    main()

Solution (Python):


from collections import defaultdict





    






    










def first_count_and_pop(xs):
    cnt = 0
    fst = xs[0]
    cnt = xs.count(fst)
    
    
    
    
    return (cnt, xs[cnt:])    
    

def main():
    _ = input()
    
    xs = [int(x) for x in input().split()]
    xs.sort()
    ys = defaultdict(int)
    for key in xs:
        ys[key] += 1
        ys[key-1] += 1
        ys[key+1] += 1

    print(max(ys.values()))



























if __name__ == "__main__":
    main()

Solution (Python):
input()
a_list = [int(s) for s in input().split()]

count = [0]*100002

for a in a_list:
    count[a] += 1
    count[a+1] += 1
    count[a+2] += 1
    
print(max(count))

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

count = [0]*100002

for a in a_list:
    count[a] += 1
    count[a+1] += 1
    count[a+2] += 1
    
print(max(count))

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

Solution (Python):
from collections import Counter

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

b=[x+1for x in a]
c=[x-1for x in a]

d=a+b+c

print(max(Counter(d).values()))

Solution (Python):
import sys
from collections import Counter




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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    M = 10 ** 5
    n = read_int()
    a = read_int_list()
    c = Counter(a)
    res = 0
    for X in range(0, M + 1):
        r = c[X - 1] + c[X] + c[X + 1]
        if r > res:
            res = r
    print(res)


main()

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

print(max(a))

Solution (Python):
N = int(input())
ls = list(map(int, input().split(' ')))
d = {}
for l in ls:
    if l in d:
        d[l] += 1
    else:
        d[l] = 1

m = 0
keys = sorted(d.keys())
for k in keys:
    c = d[k]
    if (k-1) in d:
        c += d[k-1]
    if (k+1) in d:
        c += d[k+1]
    m = max(m,c)
print(m)

Solution (Python):
a=input()
b=map(int,raw_input().split())
c=[]
for i in range(100002):
    c.append(0)

for i in b:
    c[i]+=1
    c[i+1]+=1
    c[i+2]+=1

c.sort()
c.reverse()

print c[0]

Solution (Python):
N = input()
ls = list(map(int, input().split()))
dic = {}
for item in ls:
    if item in dic:
        dic[item] += 1
    else:
        dic[item] = 1 
    item_u = item+1
    if item_u in dic:
        dic[item_u] += 1
    else:
        dic[item_u] = 1
    item_l = item-1
    if item_l in dic:
        dic[item_l] += 1
    else:
        dic[item_l] = 1
print(max(dic.values()))

Solution (Python):
n = input()

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

ans = {}

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

print max(ans.values())

Solution (Python):
import sys

def main():
    N = int(sys.stdin.readline())
    a = list(map(int, input().split()))
    n = [0 for i in range(0, max(a)+1)]
    for i in a:
        n[i] += 1
    if len(n) < 3:
        print(sum(n))
    else:
        print(max([i+j+k for i, j, k in zip(n[:-2], n[1:-1], n[2:])]))

if __name__ == '__main__':
    main()

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

Solution (Python):
import numpy as np
from collections import Counter

num=raw_input()
tmp=map(int, raw_input().split(" "))













arr1=np.array(tmp)
arr2=np.array(tmp)+1
arr3=np.array(tmp)-1
arr=np.r_[arr1, arr2,arr3]

data = Counter(list(arr))
print data.most_common(1)[0][1]


"""
sub=[]
for i in set(arr):
    sub.append(list(arr).count(i))

print max(sub)
"""

Solution (Python):
from collections import Counter

N = int(input())
X = input().split()

counter = Counter(X)

Keys = [int(key) for key in counter]
max = max(Keys)
min = min(Keys)

S_max = 1
for i in range(min, max+1):
  S = counter[str(i-1)] + counter[str(i)] + counter[str(i+1)]
  if S > S_max:
    S_max = S

    
print(S_max)

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

N = 10**5
cnt = [0 for i in range(N+2)]

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

print(max(cnt))

Solution (Python):
n = int(input())
l = input().split()

for i in range(0,n):
	l[i] = int(l[i])

dict_i = {}
for i in range(-1,100001):
	dict_i[i] = 0
	
for j in range(n):
	dict_i[l[j]] += 1
	dict_i[l[j] + 1] += 1
	dict_i[l[j] - 1] += 1
print(max(dict_i.values()))

Solution (Python):
import numpy as np
from collections import Counter

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

ans = 0
counter = Counter(A)
for a, cnt in counter.most_common():
    tmp = counter[a-1] + cnt + counter[a+1]
    if ans < tmp:
        ans = tmp
        

print(ans)

Solution (Python):
def C_Together(N, a):
    lst = [0] * (max(a) + 1 + 2)  
    for i in a:
        lst[i] += 1

    ans = 0
    for i in range(1, len(lst) - 1):
        tmp = lst[i - 1] + lst[i] + lst[i + 1]
        ans = max(ans, tmp)
    return ans

N = int(input())
a = [int(i) for i in input().split()]
print(C_Together(N, a))

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

Solution (Python):
import collections

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

v_list = []

for i in a_list:
    v_list.append(i - 1)
    v_list.append(i)
    v_list.append(i + 1)

count_dict = collections.Counter(v_list)
print(count_dict.most_common(1)[0][1])

Solution (Python):
def c():
    n = int(input())
    a = [int(ai) for ai in input().split()]
    maxN = 10**5
    A = [0]*maxN
    for i in a:
        A[i] += 1
        if i != 0:
            A[i-1] += 1
        if i != maxN-1:
            A[i+1] += 1
    print(max(A))

c()

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

b = []
c = []
for i in range(N):
    if a[i] > 0:
        b.append(a[i] - 1)
        c.append(a[i] + 1)
    else:
        c.append(a[i] + 1)

abc = a + b + c
count = [0] * (max(abc) + 1)

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

print(max(count))

Solution (Python):



import copy

n = raw_input()
n = int(n)

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

al.sort()

x = 0
y = 0
z = 0

mae = 0
saidai = 0

for i in range(n):
    a = al[i]
    if a == mae:
        x += 1
        y += 1
        z += 1
    elif a == mae + 1:
        if z > saidai:
            saidai = copy.copy(z)
        z = copy.copy(y) + 1
        y = copy.copy(x) + 1
        x = 1
    elif a == mae + 2:
        if z > saidai:
            saidai = copy.copy(z)
        z = copy.copy(x) + 1
        y = 1
        x = 1
    else:
        if z > saidai:
            saidai = copy.copy(z)
        z = 1
        y = 1
        x = 1
    mae = a

if z > saidai:
    saidai = z

print saidai

Solution (Python):
N = int(input())
d = dict()
for a in map(int,input().split()):
   if a-1 in d:
      d[a-1] += 1
   else:
      d[a-1] = 1
   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
print(max(d.values()))

Solution (Python):


from collections import defaultdict

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

dic = defaultdict(int)
for n in a_list:
    dic[n] += 1

max_count = 0
res = 0
for n in set(a_list):
    val = dic[n-1] + dic[n] + dic[n+1]

    if val > max_count:
        max_count = val

print (max_count)

Solution (Python):
import collections

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

m = list(map(lambda x: x + 1, l))
n = list(map(lambda x: x - 1, l))

ans = collections.Counter(l + m + n).most_common(1)

print(ans[0][1])

Solution (Python):
myinput=input()
myinput=input()
myarray=list(map(int,myinput.split()))
from collections import Counter
c=Counter(myarray)
d={k:c[k-1]+c[k]+c[k+1] for k in c.keys()}
print(max(d.values()))

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


a_max = max(a)
a_min = min(a)





l = [0] * (a_max+3) 

for i in range(N):
	x = a[i]


	l[x]   = l[x]   + 1

	l[x+1] = l[x+1] + 1
	l[x+2] = l[x+2] + 1


l[0] = 0

print(max(l))

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

a.sort()

hist = [0 for x in range(-1,max(a)+3)]
As = []
ans = -1
Aspd = As.append

if len(a) ==1:
    print(1)
else:
    for i in a:
        hist[i] += 1
    
    for i in range(len(hist)-1):
        Aspd(hist[i-1]+hist[i]+hist[i+1])
        

    print(max(As))

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
m = max(a)
ans = 0

l = [0 for y in range(m+3)]
for j in range(n):
    l[a[j]] += 1
    l[a[j]+1] += 1
    l[a[j]+2] += 1
print(max(l))

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

num = [0 for i in range(100000)]
for aa in a:
    num[aa] += 1

ans = 0
for X in range(1, 99999):
    ans = max(ans, sum(num[X-1:X+2]))

print(ans)

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

Solution (Python):
from collections import Counter

n = input()
s = input()

histogram = Counter()

for a in (int(a) for a in s.split()):
    histogram[a] += 1
    histogram[a + 1] += 1
    histogram[a - 1] += 1

_, X = histogram.most_common(1)[0]
print(X)

Solution (Python):
from collections import Counter
N = int(input())

a = list(map(int, input().split()))
que = []

for i in range(N):
    num = a[i]
    que.append(num+1)
    que.append(num)
    que.append(num-1)


counter = Counter(que)
for word, cnt in counter.most_common(1):
    print(cnt)

Solution (Python):
import sys
n = int (sys.stdin.readline())
a = map (int, sys.stdin.readline().split())
cnt = [0] * 111111
for i in a:
  cnt[i] += 1
  cnt[i-1] += 1
  cnt[i+1] += 1

print (max (cnt))

Solution (Python):

from collections import Counter

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

ls2 = []
for i in range(N):
    ls2.append(ls[i])
    ls2.append(ls[i]-1)
    ls2.append(ls[i]+1)

print(max(Counter(ls2).values()))

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

L = [0 for i in range(max(A) + 10)]

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

print(max(L))

Solution (Python):
from collections import Counter

n = input()
data = list(map(int, input().split(" ")))

counter = Counter(data)
result = 0
s = 0

for x, y in counter.most_common():
    s = counter[x-1] + counter[x] + counter[x+1]
    if result < s:
        result = s

print(result)

Solution (Python):


import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N = int(line)
        a = map(lambda x: int(x), sys.stdin.readline().split(" "))

        histogram = [0 for i in xrange(100000 + 2)]
        for i in a:
            histogram[i - 1] += 1
            histogram[i] += 1
            histogram[i + 1] += 1
        print(max(histogram[1:]))
        
        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

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

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

for n in a:
    if n==0:
        t[n]+=1
        t[n+1]+=1
    elif n==10**5:
        t[n-1]+=1
        t[n]+=1
    else:
        t[n-1]+=1
        t[n]+=1
        t[n+1]+=1

print max(t)

Solution (Python):
N = int(input())
a = map(int, input().split())
d = {}
for an in a:
    if an not in d:
        d[an] = 0
    if an + 1 not in d:
        d[an + 1] = 0
    if an - 1 not in d:
        d[an - 1] = 0
    d[an] = d[an] + 1
    d[an + 1] = d[an + 1] + 1
    d[an - 1] = d[an - 1] + 1
print(max(d[x] for x in d))

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

    a = [0] * 100001
    for i in A:
        if i > 0:
            a[i-1] += 1
        a[i] += 1
        a[i+1] += 1

    print(max(a))

main()

Solution (Python):
from collections import Counter

N = int(input())
listA = [int(_) for _ in input().split()]
listA_plus = [-1 for i in range(N)]
listA_minus = [-1 for i in range(N)]
for i in range(N):
    listA_plus[i] = listA[i] + 1
    listA_minus[i] = listA[i] - 1  
list_all = listA + listA_plus + listA_minus
count = Counter(list_all)
top = count.most_common(1)
print(top[0][1])

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

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
b = [0] * 100002
m = 0
for i in range(N):
    for j in range(3):
        b[a[i] + j] += 1
        if b[a[i] + j] > m:
            m = b[a[i] + j]
print(m)