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: Time Limit Exceeded

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 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.sort()
    ys = dict()
    while xs:
        key = xs[0]
        cnt, xs = first_count_and_pop(xs)
        ys[key] = cnt
    # zs = sorted(list(ys.items()), key=(lambda x: x[1]), reverse=True)
    m = 0
    for i in range(0, 100002):
        temp = ys.get(i-1, 0) + ys.get(i, 0) + ys.get(i+1, 0)
        if m < temp:
            m = temp
    print(m)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
_ = input()
l = map(int, raw_input().split())
la = []
bans = 0
for x in l:
	if x not in la:
		la.append(x)
	if x-1 not in la:
		la.append(x-1)
	if x+1 not in la:
		la.append(x+1)
for x in la:
	ans = 0
	for y in l:
		if x-y in [0,1,-1]:
			ans += 1
	if ans > bans:
		bans = ans
print(bans)

Submission status: Time Limit Exceeded

Solution code:
_ = input()
l = map(int, raw_input().split())
mi, ma = min(l), max(l)
bans = 0
for x in xrange(mi-1, ma+1):
	ans = 0
	for y in l:
		if x-y in [0,1,-1]:
			ans += 1
	if ans > bans:
		bans = ans
print(bans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
ans = 1
 
A_ = []
for i in A:
    if i not in A_:
        i_ = int(i)
        est = A.count(str(i_)) + A.count(str(i_+1)) + A.count(str(i_+2))
        ans = max(est, ans)
        A_.append(i)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
A2 = list(set(A))
ans = 0
m = {}
for a in A2:
    if a-2 not in m:
        m[a-2] = A.count(a-2)
    if a-1 not in m:
        m[a-1] = A.count(a-1)
    if a not in m:
        m[a] = A.count(a)
    if a+1 not in m:
        m[a+1] = A.count(a+1)
    if a+2 not in m:
        m[a+2] = A.count(a+2)
    tmp1 = m[a-2]+m[a-1]+m[a] 
    tmp2 = m[a-1]+m[a]+m[a+1] 
    tmp3 = m[a]+m[a+1]+m[a+2] 
    tmp4 = max(tmp1, tmp2, tmp3)
    if tmp4 > ans:
        ans = tmp4
    if a-1 in A2:
        A2.remove(a-1)
    if a in A2:
        A2.remove(a)
    if a+1 in A2:
        A2.remove(a+1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
li = []
for i in range(N):
    ans =  0
    for j in range(N):
        if a[i] == a[j] or a[i] == a[j] + 1 or a[i] == a[j] -1:
            ans += 1
        else:
            ans += 0

    li.append(ans)


print(max(li))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
ans = 1
 
A_ = []
for i in A:
    if i not in A_:
        A_.append(i)

A_.sort()

for a in A_:
    a_ = int(a)
    est = A.count(str(a_)) + A.count(str(a_+1)) + A.count(str(a_+2))
    ans = max(ans, est)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
input()
a = [int(i) for i in input().split()]
freq = a.copy()
for n in a:
    freq.append(n + 1)
    freq.append(n - 1)

best = max(freq.count(i) for i in set(freq))

print(best)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
ans = 1
 
A_ = []
for i in A:
    if i not in A_:
        A_.append(i)

A_.sort()

for a in A_:
    a_ = int(a)
    if (str(a_-1) in A_):
        est1 = 0
    else:
        est1 = A.count(str(a_-1)) + A.count(str(a_)) + A.count(str(a_+1))
    est2 = A.count(str(a_)) + A.count(str(a_+1)) + A.count(str(a_+2))
    ans = max(ans, est1, est2)
 
print(ans)

Submission status: Time Limit Exceeded

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

freq = []
for n in a:
    freq.append(n + 1)
    freq.append(n - 1)
    freq.append(n)
best = max(freq.count(i) for i in set(freq))

print(best)

Submission status: Time Limit Exceeded

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 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.sort()
    ys = dict()
    while xs:
        key = xs[0]
        cnt, xs = first_count_and_pop(xs)
        ys[key] = cnt
    if len(xs) == len(ys.keys()):
        print(3)
        return
    zs = sorted(list(ys.items()), key=(lambda x: x[1]), reverse=True)
    m = 0
    for (i, x) in zs:
        temp = ys.get(i-1, 0) + x + ys.get(i+1, 0)
        if m < temp:
            m = temp
        else:
            break
    print(m)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
ans = 1
 
A_ = []
for i in A:
    if i not in A_:
        A_.append(i)

A_.sort()

for a in A_:
    a_ = int(a)
    if (str(a_-2) in A_) or (str(a_-1) in A_):
        est1 = 0
    else:
        est1 = A.count(str(a_-2)) + A.count(str(a_-1)) + A.count(str(a_))
    if (str(a_-1) in A_):
        est2 = 0
    else:
        est2 = A.count(str(a_-1)) + A.count(str(a_)) + A.count(str(a_+1))
    est3 = A.count(str(a_)) + A.count(str(a_+1)) + A.count(str(a_+2))
    ans = max(ans, est1, est2, est3)
 
print(ans)

Submission status: Time Limit Exceeded

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

num_X = 0

for ele in a:
    X_new = 0
    X_new += sum([ 1 for i in a-ele if i == 0 ])
    X_new += sum([ 1 for i in a-ele-1 if i == 0 ])
    X_new += sum([ 1 for i in a-ele+1 if i == 0 ])
    num_X = max(num_X, X_new)

print(num_X)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
A2 = list(set(A))
ans = 0
for a in A2:
    m1 = A.count(a-2)
    m2 = A.count(a-1)
    m3 = A.count(a)
    m4 = A.count(a+1)
    m5 = A.count(a+2)
    tmp1 = m1+m2+m3 
    tmp2 = m2+m3+m4 
    tmp3 = m3+m4+m5 
    tmp4 = max(tmp1, tmp2, tmp3)
    if tmp4 > ans:
        ans = tmp4
    if a-1 in A2:
        A2.remove(a-1)
    if a in A2:
        A2.remove(a)
    if a+1 in A2:
        A2.remove(a+1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    N = int(input())
    a = list(map(int, input().split()))
    ans = 0
    check = 0
    checkmm = 0
    checkm = 0
    a.sort()
    for i in a:
        if i == i-1:
            break
        if i-2 in a:
            checkmm = checkm
        else:
            checkmm = 0

        if i-1 in a:
            checkm = check
        else :
            checkm = 0

        check = a.count(i)


        if ans < check+checkm+checkmm:
            ans = check+checkm+checkmm

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(list(map(int, input().split(' '))))
A2 = list(set(A))
ans = 0
for a in A2:
    m1 = A.count(a-2)
    m2 = A.count(a-1)
    m3 = A.count(a)
    m4 = A.count(a+1)
    m5 = A.count(a+2)
    tmp1 = m1+m2+m3 
    tmp2 = m2+m3+m4 
    tmp3 = m3+m4+m5 
    tmp4 = max(tmp1, tmp2, tmp3)
    if tmp4 > ans:
        ans = tmp4
    if a-1 in A2:
        A2.remove(a-1)
    if a in A2:
        A2.remove(a)
    if a+1 in A2:
        A2.remove(a+1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    N = int(input())
    a = list(map(int, input().split()))
    ans = 0
    check = 0
    checkmm = 0
    checkm = 0
    a.sort()
    for i in a:
        if i-2 in a:
            checkmm = checkm
        else:
            checkmm = 0

        if i-1 in a:
            checkm = check
        else :
            checkm = 0

        check = a.count(i)


        if ans < check+checkm+checkmm:
            ans = check+checkm+checkmm

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

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 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 = Stdin.read_line(converter=int)
    xs.sort()
    ys = dict()
    while xs:
        key = xs[0]
        cnt, xs = first_count_and_pop(xs)
        ys[key] = cnt
    zs = sorted(list(ys.items()), key=(lambda x: x[1]), reverse=True)
    m = 0
    for (x, _) in zs:
        temp = ys.get(x-1, 0) + ys.get(x, 0) + ys.get(x+1, 0)
        if m < temp:
            m = temp
        else:
            break
    print(m)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
ans = 1
 
A_ = []
for i in A:
    if i not in A_:
        A_.append(i)

for a in A_:
    a_ = int(a)
    est1 = A.count(str(a_-2)) + A.count(str(a_-1)) + A.count(str(a_))
    est2 = A.count(str(a_-1)) + A.count(str(a_)) + A.count(str(a_+1))
    est3 = A.count(str(a_)) + A.count(str(a_+1)) + A.count(str(a_+2))
    ans = max(ans, est1, est2, est3)
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
ans = 1
 
A_ = []
for i in A:
    if i not in A_:
        A_.append(i)
 
A__ = {}
for i in A_:
    A__[int(i)-2] = A.count(str(int(i)-2))
    A__[int(i)-1] = A.count(str(int(i)-1))
    A__[int(i)] = A.count(i)
    A__[int(i)+1] = A.count(str(int(i)+1))
    A__[int(i)+2] = A.count(str(int(i)+2))

for a in A_:
    a_ = int(a)
    est1 = A__[a_-2] + A__[a_-1] + A__[a_]
    est2 = A__[a_-1] + A__[a_] + A__[a_+1]
    est3 = A__[a_-1] + A__[a_] + A__[a_+1]
    ans = max(ans, est1, est2, est3)
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
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 np.median(arr)
sub=[]
for i in set(arr):
    sub.append(list(arr).count(i))
#print sub
print max(sub)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int, input().split()))
s=sorted(list(set(a)))
ans=0
d=[a.count(x) for x in s]
L=len(d)

for i in range(L) :
    cnt=[d[i]]*3
    if i>0 and s[i-1]==s[i]-1 :
        cnt[0]+=d[i-1]
        cnt[1]+=d[i-1]
    if i<L-1 and s[i+1]==s[i]+1 :
        cnt[0]+=d[i+1]
        cnt[2]+=d[i+1]
    if i>1 and s[i-2]==s[i]-2 :
        cnt[1]+=d[i-2]
    if i<L-2 and s[i+2]==s[i]+2 :
        cnt[2]+=d[i+2]

    if ans < max(cnt) :
        ans=max(cnt)

print(ans)

Submission status: Time Limit Exceeded

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

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

a.extend(b)
a.extend(c)
f = set(a)
ans = 0
for i in f:
    ans = max(ans, a.count(i))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def f7(seq):
    seen = set()
    seen_add = seen.add
    return [ x for x in seq if x not in seen and not seen_add(x)]

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

a_list = np.zeros(100005)

for a in A_uniq:
    a_cnt = A.count(a)
    a_list[a] += a_cnt
    a_list[a+1] += a_cnt
    a_list[a+2] += a_cnt
    
print(int(a_list.max()))

Submission status: Time Limit Exceeded

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

num_X = 0

for ele in a:
    X_new = 3*N - np.count_nonzero(a - ele) - np.count_nonzero(a - ele -1) - np.count_nonzero(a - ele +1)
    num_X = max(num_X, X_new)

print(num_X)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

a_list = np.zeros(100005)
# a_list = [0 for _ in range(100005)]

for a in A_uniq:
    a_cnt = A.count(a)
    a_list[a] += a_cnt
    a_list[a+1] += a_cnt
    a_list[a+2] += a_cnt
    
print(int(a_list.max()))

Submission status: Time Limit Exceeded

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

num_X = 0

for ele in a:
    X_new = 0
    X_new += len(a) - np.count_nonzero(a - ele)
    X_new += len(a) - np.count_nonzero(a - ele -1)
    X_new += len(a) - np.count_nonzero(a - ele +1)
    num_X = max(num_X, X_new)

print(num_X)

Submission status: Time Limit Exceeded

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 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 = Stdin.read_line(converter=int)
    xs.sort()
    ys = dict()
    while xs:
        key = xs[0]
        cnt, xs = first_count_and_pop(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: Time Limit Exceeded

Solution code:
import numpy as np

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

e=[]


for X in range(N):
    f=d.count(X)
    e.append(f)

if N==1:
    print("1")
else:
    print(max(e))

Submission status: Time Limit Exceeded

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

a_list = [0 for _ in range(100005)]

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

Submission status: Time Limit Exceeded

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

#print set(out)

sub=[]
for i in set(out):
    sub.append(out.count(i))
#print sub
print max(sub)

Submission status: Time Limit Exceeded

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

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

counting = 0
list_i = []
set_l = set(l)
max_counting = 0
for i in set_l:
	counting = 0
	for j in range(n):
		if (l[j] == i or l[j] == i-1 or l[j] == i+1):
			counting += 1		
	if max_counting < counting:
		max_counting = counting
			 
print(max_counting)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
ans = 1
 
A_ = []
for i in A:
    if i not in A_:
        A_.append(i)
 
A__ = {}
for i in A_:
    A__[int(i)-2] = A.count(str(int(i)-2))
    A__[int(i)-1] = A.count(str(int(i)-1))
    A__[int(i)] = A.count(i)
    A__[int(i)+1] = A.count(str(int(i)+1))
    A__[int(i)+2] = A.count(str(int(i)+2))

for a in A_:
    a_ = int(a) - 1
    if a_ >= 0:
        est = A__[a_-1] + A__[a_] + A__[a_+1]
        ans = max(ans, est)
    a_ = int(a)
    if a_ >= 0:
        est = A__[a_-1] + A__[a_] + A__[a_+1]
        ans = max(ans, est)
    a_ = int(a) + 1
    if a_ >= 0:
        est = A__[a_-1] + A__[a_] + A__[a_+1]
        ans = max(ans, est)
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s1 = input()
s1 = [int(n) for n in s1.split()]
s1 = s1[:N]
dict = {}
for n in range(max(s1)):
    count = 0
    for val in s1:
    	if val in [n,n+1,n+2]:
    		count += 1
    dict.update({n+1:count})

if max(s1) == 0:
  	print (len(s1))
else:
	print (sorted(dict.values(), reverse=True)[0])

Submission status: Time Limit Exceeded

Solution code:

def countA(a, A):
    ans = A.count(a-1) + A.count(a) + A.count(a+1)
    return ans

N = int(input())
A = list(map(int, input().split(' ')))
A2 = list(set(A))
ans = 0
for a in A2:
    tmp1 = countA(a-1, A)
    tmp2 = countA(a, A)
    tmp3 = countA(a+1, A)
    tmp4 = max(tmp1, tmp2, tmp3)
    if tmp4 > ans:
        ans = tmp4
    if a-1 in A2:
        A2.remove(a-1)
    if a in A2:
        A2.remove(a)
    if a+1 in A2:
        A2.remove(a+1)
print(ans)

Submission status: Time Limit Exceeded

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 main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    xs.sort()
    ys = {i: xs.count(i) for i in set(xs)}
    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: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int, input().split()))
s=set(a)
ans=0
d={x:a.count(x) for x in s}
for x in s :
    d[x-1]=d.get(x-1,0)
    d[x-2]=d.get(x-2,0)
    d[x+1]=d.get(x+1,0)
    d[x+2]=d.get(x+2,0)
    cnt=d[x-1] + d[x] + d[x+1]
    if ans < cnt :
        ans=cnt

    cnt=d[x] + d[x+1] + d[x+2]
    if ans < cnt :
        ans=cnt

    cnt=d[x] + d[x-1] + d[x-2]
    if ans < cnt :
        ans=cnt

print(ans)

Submission status: Time Limit Exceeded

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

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

counting = 0
list_i = []
set_l = set(l)
for i in set_l:
	counting = 0
	for j in range(n):
		if (l[j] == i or l[j] == i-1 or l[j] == i+1):
			counting += 1		
	list_i.append(counting)
			 
print(max(list_i))

Submission status: Time Limit Exceeded

Solution code:
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):
    for k in range(j):
        out.append(i-1)
        out.append(i+1)

#print set(out)

sub=[]
for i in set(out):
    sub.append(out.count(i))
#print sub
print max(sub)

Submission status: Time Limit Exceeded

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 main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    xs.sort()
    ys = {i: xs.count(i) for i in set(xs)}
    counts = [ys.get(x-1, 0) + ys.get(x, 0) + ys.get(x+1, 0) for x in ys.keys()]
    print(max(counts))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

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

counting = 0
list_i = []
for i in range(0,100000):
	counting = 0
	for j in range(n):
		if (l[j] == i or l[j] == i-1 or l[j] == i+1):
			counting += 1		
	list_i.append(counting)
			 
print(max(list_i))

Submission status: Time Limit Exceeded

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

num_X = 0

for max_new in range(max(a)+2):
    X_new = 0
    X_new += sum([ 1 for ele in a if ele == max_new ])
    X_new += sum([ 1 for ele in a if ele-1 == max_new ])
    X_new += sum([ 1 for ele in a if ele+1 == max_new ])
    num_X = max(num_X, X_new)

print(num_X)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    N = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i in a:
        check = a.count(i)
        check2 = a.count(i-1)
        check3 = a.count(i+1)
        if ans < check+check2+check3:
            ans = check+check2+check3

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
def countA(a, A):
    ans = A.count(a-1) + A.count(a) + A.count(a+1)
    return ans

N = int(input())
A = list(map(int, input().split(' ')))
A2 = set(A)
ans = 0
for a in A2:
    tmp1 = countA(a-1, A)
    tmp2 = countA(a, A)
    tmp3 = countA(a+1, A)
    tmp4 = max(tmp1, tmp2, tmp3)
    if tmp4 > ans:
        ans = tmp4
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int, input().split()))
s=set(a)
ans=0
d={x:a.count(x) for x in s}
for x in s :
    cnt=d[x] + d.get(x-1,0) + d.get(x+1,0)
    if ans < cnt :
        ans=cnt

    cnt=d[x] + d.get(x+1,0) + d.get(x+2,0)
    if ans < cnt :
        ans=cnt

    cnt=d[x] + d.get(x-1,0) + d.get(x-2,0)
    if ans < cnt :
        ans=cnt

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    N = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i in range(1,500000):
        check = a.count(i)
        check2 = a.count(i-1)
        check3 = a.count(i+1)
        if ans < check+check2+check3:
            ans = check+check2+check3

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

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

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

for a in A:
    L[a] += 1
    if a != 0:
        L[a - 1] += 1
    if a != max(A):
        L[a + 1] += 1

print(max(L))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
ans = 1

A_ = []
for i in A:
    if i not in A_:
        A_.append(i)

for a in A_:
    a_ = int(a) - 1
    if a_ >= 0:
        est = A.count(str(a_-1)) + A.count(str(a_)) + A.count(str(a_+1))
        ans = max(ans, est)
    a_ = int(a)
    if a_ >= 0:
        est = A.count(str(a_-1)) + A.count(str(a_)) + A.count(str(a_+1))
        ans = max(ans, est)
    a_ = int(a) + 1
    if a_ >= 0:
        est = A.count(str(a_-1)) + A.count(str(a_)) + A.count(str(a_+1))
        ans = max(ans, est)

print(ans)

Submission status: Time Limit Exceeded

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

num = [0 for i in range(3)]
num[0] = a.count(0)
num[1] = a.count(1)

ans = 0
for X in range(1, 100000):
    num[(X % 3) - 2] = a.count(X + 1)
    ans = max(ans, sum(num))

print(ans)

Submission status: Time Limit Exceeded

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

res = 0
for a in A:
    res = max(res, A.count(a) + A.count(a+1) + A.count(a-1))


print(res)

Submission status: Time Limit Exceeded

Solution code:
def countA(a, A):
    tmp = [i for i in A if i >= a-1 and i <= a+1]
    return len(tmp) 

N = int(input())
A = list(map(int, input().split(' ')))
A2 = set(A)
ans = 0
for a in A2:
    tmp1 = countA(a-1, A)
    tmp2 = countA(a, A)
    tmp3 = countA(a+1, A)
    tmp4 = max(tmp1, tmp2, tmp3)
    if tmp4 > ans:
        ans = tmp4
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
ans = 1

for i in range(10**5):
    est = A.count(str(i-1)) + A.count(str(i)) + A.count(str(i+1))
    ans = max(ans, est)

print(ans)

Submission status: Time Limit Exceeded

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

b = []

for i in range(100000):
    b.append(a.count(i-1) + a.count(i) + a.count(i+1))

print(max(b))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
ans = 1

for a in A:
    a_ = int(a) - 1
    if a_ >= 0:
        est = A.count(str(a_-1)) + A.count(str(a_)) + A.count(str(a_+1))
        ans = max(ans, est)
    a_ = int(a)
    if a_ >= 0:
        est = A.count(str(a_-1)) + A.count(str(a_)) + A.count(str(a_+1))
        ans = max(ans, est)
    a_ = int(a) + 1
    if a_ >= 0:
        est = A.count(str(a_-1)) + A.count(str(a_)) + A.count(str(a_+1))
        ans = max(ans, est)

print(ans)

Submission status: Time Limit Exceeded

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

num_X = 0

for max_new in range(max(a)+2):
    X_new = 0
    X_new += sum([ 1 for ele in a if ele == max_new ])
    X_new += sum([ 1 for ele in a-1 if ele == max_new ])
    X_new += sum([ 1 for ele in a+1 if ele == max_new ])
    num_X = max(num_X, X_new)
    
print(num_X)

Submission status: Time Limit Exceeded

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 main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    ys = [[x-1, x, x+1] for x in xs]
    zs = list()
    for y in ys:
        zs.extend(y)
    zs.sort()
    counts = [zs.count(i) for i in range(max(zs))]   
    print(max(counts))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

list = [0]*100000
for i in range(n):
  list[a[i]] += 1

ans = 0
for i in range(1,99999):
  sum = list[i-1]+list[i]+list[i+1]
  ans = max(sum, ans)
  
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8


def main():
    _ = int(input())
    A = list(map(int, input().split()))
    B = [0] * 100002
    ans = 0

    for a in A:
        if a != 0: B[a - 1] += 1
        B[a] += 1
        B[a + 1] += 1

    ans = max(B)
    
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
A_dict = dict()
for a in A_list:
    if A_dict.get(a) is None:
        A_dict[a] = 1
    else:
        A_dict[a] += 1
ans = 0
for key, val in A_dict.items():
    temp = 0
    if A_dict.get(key - 1) is not None:
        temp += A_dict.get(key - 1)
    if A_dict.get(key) is not None:
        temp += A_dict.get(key)
    if A_dict.get(key + 1) is not None:
        temp += A_dict.get(key + 1)
    ans = max(temp, ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
ans = 0
from collections import defaultdict
dic = defaultdict(int)
for i in range(N):
    dic[A[i]] += 1
    dic[A[i]+1] += 1
    dic[A[i]-1] += 1
for x in range(-1, 10**5+1):
    ans = max(ans, dic[x])
print(ans)

Submission status: Accepted

Solution code:
N,*A  =map(int,open(0).read().split())

L = [0 for i in range(int(1e5)+1)]

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

ans = 0
for i in range(int(1e5)+1):
  S = sum(L[i:i+3])
  if ans < S:
    ans = S
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

dp=[0 for i in range(max(a)+1)]
for i in range(n):
    dp[a[i]]+=1
 
ans=0

if len(dp)==1:
    ans=dp[0]
else:
    for i in range(1,len(dp)-1):
        ans=max(ans,dp[i-1]+dp[i]+dp[i+1])
 
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
nums = [0]*100000
ans_list=[]

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

for j in range(1,99999):
  ans_list.append(nums[j-1]+nums[j]+nums[j+1])

print(max(ans_list))