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:
# encoding: "utf-8"

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

Submission status: Accepted

Solution code:
# encoding: "utf-8"

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

Submission status: Accepted

Solution code:
# encoding: "utf-8"

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)
    # print(xs)
    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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
input()
get_data = input().split(' ')  # String
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]))

Submission status: Accepted

Solution code:
#coding=UTF-8

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

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

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

#count up
for suu in a:
    hindo[suu]+=1

#search the best
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""

"""



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)

Submission status: Accepted

Solution code:
# encoding: "utf-8"

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

Submission status: Accepted

Solution code:
# encoding: "utf-8"

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

Submission status: Accepted

Solution code:
# encoding: "utf-8"

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

Submission status: Accepted

Solution code:
# encoding: "utf-8"

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

Submission status: Accepted

Solution code:
def solve(): # 072C- Together
    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()

Submission status: Accepted

Solution code:
# encoding: "utf-8"

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]
    # cnt = xs.count(fst)
    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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# encoding: "utf-8"

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 first_count_and_pop(xs):
    cnt = 0
    fst = xs[0]
    # cnt = xs.count(fst)
    for x in xs:
        if x != fst:
            break
        cnt += 1
    return (cnt, xs[cnt:])    
    

def main():
    _ = input()
    # xs = Stdin.read_line(converter=int)
    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
    for x in xs:
        key = x
        ys[key] += 1
        ys[key-1] += 1
        ys[key+1] += 1

    print(max(ys.values()))

# def main_():
#     input()
#     xs = Stdin.read_line(converter=int)
#     xs.sort()
#     counts = list()
#     for i in range(100000):
#         if not xs:
#             counts.extend([0] * (100000 - len(counts)))
#             break     
#         elif i == xs[0]:
#             cnt, xs = first_count_and_pop(xs)
#             counts.append(cnt)
#         else:
#             counts.append(0)
#     m = 0
#     for i in range(0, 100000):
#         if i == 0:
#             temp = counts[i] + counts[i+1]
#         elif i == 100000 - 1:
#             temp = counts[i-1] + counts[i]
#         else:
#             temp = counts[i-1] + counts[i] + counts[i+1]
#         if m < temp:
#             m = temp
#     print(m)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# encoding: "utf-8"

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 first_count_and_pop(xs):
    cnt = 0
    fst = xs[0]
    cnt = xs.count(fst)
    # for x in xs:
    #     if x != fst:
    #         break
    #     cnt += 1
    return (cnt, xs[cnt:])    
    

def main():
    _ = input()
    # xs = Stdin.read_line(converter=int)
    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()))

# def main_():
#     input()
#     xs = Stdin.read_line(converter=int)
#     xs.sort()
#     counts = list()
#     for i in range(100000):
#         if not xs:
#             counts.extend([0] * (100000 - len(counts)))
#             break     
#         elif i == xs[0]:
#             cnt, xs = first_count_and_pop(xs)
#             counts.append(cnt)
#         else:
#             counts.append(0)
#     m = 0
#     for i in range(0, 100000):
#         if i == 0:
#             temp = counts[i] + counts[i+1]
#         elif i == 100000 - 1:
#             temp = counts[i-1] + counts[i]
#         else:
#             temp = counts[i-1] + counts[i] + counts[i+1]
#         if m < temp:
#             m = temp
#     print(m)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter

# sys.stdin = open('c1.in')


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
from collections import Counter
#from statistics import mode
num=raw_input()
tmp=map(int, raw_input().split(" "))
#tmp_count=[]
#for i in set(tmp):
#    tmp_count.append(tmp.count(i))

#print set(tmp),tmp_count
#out=tmp[:]
#for i,j in zip(set(tmp),tmp_count):

#out=tmp[:]
#for i in tmp:
#    out.append(i-1)
#    out.append(i+1)

arr1=np.array(tmp)
arr2=np.array(tmp)+1
arr3=np.array(tmp)-1
arr=np.r_[arr1, arr2,arr3]
#print arr
data = Counter(list(arr))
print data.most_common(1)[0][1]
#print mode(list(arr))
#print np.median(arr)
"""
sub=[]
for i in set(arr):
    sub.append(list(arr).count(i))
#print sub
print max(sub)
"""

Submission status: Accepted

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

Submission status: Accepted

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

N = 10**5
cnt = [0 for i in range(N+2)]
# index 0 == -1
for i in a:
    cnt[i] += 1
    cnt[i+1] += 1
    cnt[i+2] += 1

print(max(cnt))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def C_Together(N, a):
    lst = [0] * (max(a) + 1 + 2)  # 配列0スタートを考慮+1、リスト長が3以上になるように+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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import 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])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bim/python
#! -*- coding: utf-8 -*-

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())						# 5
a = [int(i) for i in input().split()]	# 1 2 3 4 5 ...


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

# print(a_max)
# print(a_min)


l = [0] * (a_max+3) # *を用いた初期化 ← こっちの方が高速

for i in range(N):
	x = a[i]
#	print(x, l[x])

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

#print(l)
l[0] = 0
#l[len(l)-1] = 0
print(max(l))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# problem C
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())) # counts the elements' frequency

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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