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:
N = int(input())
A = list(map(int,input().split()))
ans = 0
count_list = []
A_sl = list(set(A))
if len(A_sl) == 1:
    print(len(A))
elif len(A_sl) == 2:
    if A_sl[1] - A_sl[0] <= 2:
        print(len(A))
    else:
        count_l = A.count(A_sl[1])
        count_s = A.count(A_sl[0])
        print(max(count_l,count_s)) 
else:
    for i in range(min(A),max(A) + 1):
        count_i = A.count(i)
        count_list.append(count_i)
    for i in range(1,max(A)-min(A)):
        count = count_list[i-1] + count_list[i] + count_list[i+1]
        if count > ans:
            ans = count
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
l = []
A_sl = list(set(A))
if len(A_sl) == 1:
    print(len(A))
elif len(A_sl) == 2:
    if A_sl[1] - A_sl[0] <= 2:
        print(len(A))
    else:
        count_l = A.count(A_sl[1])
        count_s = A.count(A_sl[0])
        print(max(count_l,count_s)) 
else:
    for i in range(min(A),max(A) + 1):
        count_i = A.count(i)
        l.append(count_i)
    l_num = [l[i-1] + l[i] + l[i+1] for i in range(1,max(A)-min(A))]
    print(max(l_num))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
count_list = []
A_sl = list(set(A))
if len(A_sl) == 1:
    print(len(A))
elif len(A_sl) == 2:
    if A_sl[1] - A_sl[0] <= 2:
        print(len(A))
    else:
        count_l = A.count(A_sl[1])
        count_s = A.count(A_sl[0])
        print(max(count_l,count_s)) 
else:
    for i in range(min(A),max(A) + 1):
        if i in A_sl:
            count_i = A.count(i)
        else:
            count_i = 0
        count_list.append(count_i)
    for i in range(1,max(A)-min(A)):
        count = count_list[i-1] + count_list[i] + count_list[i+1]
        if count > ans:
            ans = count
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
A_sl = list(set(A))
if len(A_sl) == 1:
    print(len(A))
elif len(A_sl) == 2:
    A_sl.sort()
    if A_sl[1] - A_sl[0] <= 2:
        print(len(A))
    else:
        count_l = A.count(A_sl[1])
        count_s = A.count(A_sl[0])
        print(max(count_l,count_s)) 
else:
    for i in range(min(A) + 1,max(A)):
        count = A.count(i-1) + A.count(i) + A.count(i+1)
        if count > ans:
            ans = count
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
count_list = []
A_sl = list(set(A))
if len(A_sl) == 1:
    print(len(A))
elif len(A_sl) == 2:
    A_sl.sort()
    if A_sl[1] - A_sl[0] <= 2:
        print(len(A))
    else:
        count_l = A.count(A_sl[1])
        count_s = A.count(A_sl[0])
        print(max(count_l,count_s)) 
else:
    for i in range(min(A) + 1,max(A)):
        count = A.count(i-1) + A.count(i) + A.count(i+1)
        count_list.append(count)
    print(max(count_list))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
count_list = []
for i in range(min(A),max(A) + 1):
    count = A.count(i-1) + A.count(i) + A.count(i+1)
    count_list.append(count)
print(max(count_list))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split())) 
res = 0
for i in range(10**5):
    count = L.count(i) + L.count(i+1) + L.count(i+2)
    if count > res:
        res = count
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
x = []
cnt = [0]
for i in range(N):
    if a[i] in x:
        continue
    x.append(a[i])
    count = 0
    for j in range(N):
        if count + len(a[j:]) < max(cnt):
            break
        if a[i] == a[j] or a[i] == a[j]+1 or a[i] == a[j]-1:
            count += 1
    cnt.append(count)

print(max(cnt))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
cnt = [0]
for i in range(N):
    x = a[i]
    count = 0
    for j in range(N):
        if count + len(a[j:]) < max(cnt):
            break
        if x == a[j] or x == a[j]+1 or x == a[j]-1:
            count += 1
    cnt.append(count)

print(max(cnt))

Submission status: Time Limit Exceeded

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

print(max(cnt))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
cnt = []
for i in range(N):
    x = a[i]
    count = 1
    for j in range(N):
        if i == j:
            continue
        if x == a[j] or x == a[j]+1 or x == a[j]-1:
            count += 1
    cnt.append(count)

print(max(cnt))

Submission status: Time Limit Exceeded

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

nums = [0 for _ in range(N)]

for i in range(N):
    nums[i] = nums[i] + A.count(A[i])
    nums[i] = nums[i] + A.count(A[i] +1)
    nums[i] = nums[i] + A.count(A[i] -1)
    
print(max(nums))

Submission status: Time Limit Exceeded

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

d = [0]*(max(a)+3)
s = set(a)
for i in s:
    c = a.count(i)
    d[i+1] += c
    d[i] += c
    d[i+2] += c

print(max(d))

Submission status: Time Limit Exceeded

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

d = [0]*(max(a)+3)

for i in range(0,max(a)+1):
    c = a.count(i)
    d[i+1] += c
    d[i] += c
    d[i+2] += c

print(max(d))

Submission status: Time Limit Exceeded

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

m = 0
s = sorted(a)

d = [0]*(s[-1]+3)

for i in range(0,s[-1]+1):
    d[i+1] += s.count(i)
    d[i] += s.count(i)
    d[i+2] += s.count(i)

print(max(d))

Submission status: Time Limit Exceeded

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

m = 0
s = sorted(a)

d = [0]*(s[-1]+3)

for i in range(0,s[-1]+1):
    d[i+1] = s.count(i)
e = [0]*(s[-1]+3)
for i in range(0,s[-1]+1):
    e[i] = d[i]+d[i+1]+d[i+2]

print(max(e))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A_ = sorted(A_)
A = np.array(A_)

dic = {}
for a in A:
    dic[a] = 0

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

ans = 0
for X in dic.keys():
    tmp = 0
    tmp = np.sum((X-1 <= A) & (A<= X+1))
    ans = max(tmp,ans)


# ans = max(ans,dic[X] + dic[X+1])

# for X in A[1:]:

#     tmp = dic[]


#     tmp = dic[dic.key()] + dic[X] + dic[X+1]

#     ans = max(tmp,ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A_ = sorted(A_)
A = np.array(A_)

ans = 0
for X in A:
    tmp = 0
    tmp = np.sum((X-1 <= A) & (A<= X+1))
    ans = max(tmp,ans)
# dic = {}
# for a in A:
#     dic[a] = 0

# for a in A:
#     dic[a] += 1


# ans = max(ans,dic[X] + dic[X+1])

# for X in A[1:]:

#     tmp = dic[]


#     tmp = dic[dic.key()] + dic[X] + dic[X+1]

#     ans = max(tmp,ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A_ = sorted(A_)
A = np.array(A_)
ans = 0

for X in range(A[0],A[-1]+1):
    tmp = np.sum((X-1 <= A) & (A<= X+1))
    ans = max(tmp,ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A_ = list(map(int, input().split()))
A_ = sorted(A_)

A = np.array(A_)

ans = 0
for X in range(np.min(A),np.max(A)+1):
    tmp = 0
    for a in A:
        if X-1 <= a <= X+1:
            tmp += 1
        elif X+1 < a:
            break
    ans = max(tmp,ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A = np.array(A_)

ans = 0
for X in range(np.min(A),np.max(A)+1):
    tmp = 0
    for a in A:
        if X-1 <= a <= X+1:
            tmp += 1
    ans = max(tmp,ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A = np.array(A_)

ans = 0
for X in range(np.min(A),np.max(A)+1):
    tmp = 0
    for a in A:
        if a == X or a == X+1 or a == X-1:
            tmp += 1
    ans = max(tmp,ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = input()
L = list(map(int,input().split()))
A = []
for a in L:
  if (a not in A):
    A.append(a)
J = [1]
for i in range(len(A)):
  p = L.count(A[i]-1)+L.count(A[i])+L.count(A[i]+1)
  if (J[0] < p):
    del J[0]
    J.append(p)
print(J[0])

Submission status: Time Limit Exceeded

Solution code:
N = input()
L = list(map(int,input().split()))
A = []
for a in L:
  if (a not in A):
    A.append(a)
J = []
for i in range(len(A)):
  J.append(L.count(A[i]-1)+L.count(A[i])+L.count(A[i]+1))
print(max(J))

Submission status: Time Limit Exceeded

Solution code:
N = input()
L = list(map(int,input().split()))
L.sort()
J = []
for i in range(len(L)):
  J.append(L.count(L[i]-1)+L.count(L[i])+L.count(L[i]+1))
print(max(J))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
al=set(a)
al=list(al)
l=len(al)
a1=a.count(al[0])#一個前の合計
if l==1:
    print(a1)
    exit()
a2=a.count(al[1])#現在の合計
if l==2:
    if abs(al[0]-al[1])<=2:
        print(a1+a2)
        exit()
    else:
        print(max(a1,a2))
        exit()
a3=a.count(al[2])#一つ先の合計
count=0
result=0#最大値
for i in range(1,l-1):
    a3=a.count(al[i+1])
    count=a1+a2+a3
    if count>result:
        result=count
    a1=a2
    a2=a3
print(result)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
al=set(a)
al=list(al)
l=len(al)
a1=a.count(al[0])#一個前の合計
if l>=2:
    a2=a.count(al[1])#現在の合計
if l>=3:
    a3=a.count(al[2])#一つ先の合計
if l==1:
    print(a1)
    exit()
elif l==2:
    if abs(al[0]-al[1])<=2:
        print(a1+a2)
        exit()
    else:
        print(max(a1,a2))
        exit()
count=0
result=0#最大値
for i in range(1,l-1):
    a3=a.count(al[i+1])
    count=a1+a2+a3
    if count>result:
        result=count
    a1=a2
    a2=a3
print(result)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
if n==1:
    print(1)
    exit()
elif n==2:
    if abs(a[0]-a[1])<=2:
        print(2)
        exit()
    else:
        print(1)
        exit()
a1=a.count(a[0])#一個前の合計
a2=a.count(a[1])#現在の合計
a3=a.count(a[2])#一つ先の合計
count=0
result=0#最大値
a.append(" ")
for i in range(1,n-1):
    count=a1+a2+a3
    if count>result:
        result=count
    a1=a2
    a2=a3
    a3=a.count(i+2)
print(result)

Submission status: Time Limit Exceeded

Solution code:

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

    lst = [0 for i in range(n*3)]
    for i in range(n):
        lst[3*i] = a[i]
        lst[3*i+1] = a[i]+1
        lst[3*i+2] = a[i]+2

    ans = -1
    for i in set(lst):
        ans = max(lst.count(i),ans)

    print(ans)



if __name__ == "__main__":
        main()

Submission status: Time Limit Exceeded

Solution code:

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


    lst = []
    for i in a:
        lst.append(i)
        lst.append(i-1)
        lst.append(i+1)

    ans = -1
    for i in set(lst):
        ans = max(lst.count(i),ans)

    print(ans)



if __name__ == "__main__":
        main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(map(int,input().split()))
s.sort()
ans=0
if n==1:
    print(1)
    exit()
for i in range(n):
    c=j=k=0
    while 0<=i-j:
        if s[i-j]==s[i] or s[i-j]==s[i]-1:
            c+=1
            j+=1
        else:break
    while i+k<n:
        if s[i+k]==s[i] or s[i+k]==s[i]+1:
            c+=1
            k+=1
        else:break
    ans=max(ans,c-1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=list(map(int,input().split()))
s.sort()
ans=0
for i in range(n):
    c=s.count(s[i]-1)+s.count(s[i])+s.count(s[i]+1)
    ans=max(ans,c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
alist = list(map(int, input().split()))
aset = set(alist)
xset = set()
for a in aset:
    xset.add(a - 1)
    xset.add(a)
    xset.add(a + 1)
max_num = 0
for x in xset:    
        num = len([xx for xx in alist if x -1 <= xx <= x + 1])
        max_num = max(max_num, num)
print(max_num)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
alist = list(map(int, input().split()))
aset = set(alist)
min_x, max_x = min(alist), max(alist)
max_num = 0
for x in range(min_x, max_x + 1):
    if x in aset:
        num = len([xx for xx in alist if x -1 <= xx <= x + 1])
        max_num = max(max_num, num)
print(max_num)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
alist = list(map(int, input().split()))
min_x, max_x = min(alist), max(alist)
max_num = 0
for x in range(min_x, max_x + 1):
    if x in alist:
        num = len([xx for xx in alist if x -1 <= xx <= x + 1])
        max_num = max(max_num, num)
print(max_num)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
alist = list(map(int, input().split()))
min_x, max_x = min(alist), max(alist)
max_num = 0
for x in range(min_x, max_x + 1):
    num = len([xx for xx in alist if x -1 <= xx <= x + 1])
    max_num = max(max_num, num)
print(max_num)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
print(max([len(list(filter(lambda x: i-1 <= x and x <= i+1, a))) for i in set(a)]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
if min(a)+1 < max(a):
    print(max([len(list(filter(lambda x: i-1 <= x and x <= i+1, a))) for i in range(min(a)+1,max(a))]))
else:
    print(len(a))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
         
number_of_items=[]
for X in range(min(A)-1, max(A)+1):
    number_of_items.append(A.count(X)+A.count(X-1)+A.count(X+1))
print(max(number_of_items))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
     
number_of_items=0
A.sort()
for X in range(min(A)-1, max(A)+1):
    if number_of_items < A.count(X)+A.count(X-1)+A.count(X+1):
        number_of_items = A.count(X)+A.count(X-1)+A.count(X+1)
print(number_of_items)

Submission status: Time Limit Exceeded

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

number_of_items=0
for X in range(min(A)-1, max(A)+1):
    if number_of_items < A.count(X)+A.count(X-1)+A.count(X+1):
        number_of_items = A.count(X)+A.count(X-1)+A.count(X+1)
print(number_of_items)

Submission status: Time Limit Exceeded

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

biggest = 1
for i in range(min(numbers),max(numbers)+1):
    count = numbers.count(i-1) + numbers.count(i) + numbers.count(i+1)
    if biggest <= count:
        biggest = count
print(biggest)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
i = 0
b = []
while i <= 100000:
  n = a.count(i)
  b.append(n)
  i += 1
l = len(b)
j = 1
c = []
while j < l-1:
  nn = b[j-1]+b[j]+b[j+1]
  c.append(nn)
  j += 1
print(max(c))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
input_list = sorted([int(i) for i in input().split()])
inupt_dict = (Counter(input_list))
result = 0
input_dict_keys = inupt_dict.keys()

if N == 1:
    result = 1
elif N == 2 and input_list[0] == input_list[1]:
    result = 2
elif N == 2 and input_list[0] != input_list[1]:
    if input_list[1] == input_list[0] + 1:
        result = 2
    else:
        result = 1
else:
    for i in range(N-2):
        if i in input_dict_keys:
            if i+1 in input_dict_keys:
                if i+2 in input_dict_keys:
                    result = max(result, (inupt_dict[i] + inupt_dict[i+1] + inupt_dict[i+2]))

        for i in range(N-1):
            if i in input_dict_keys:
                if i+1 in input_dict_keys:
                    result = max(result, (inupt_dict[i] + inupt_dict[i+1]))

        for i in range(N):
            if i in input_dict_keys:
                result = max(result, inupt_dict[i])


print(result)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
count = lambda x: a.count(x-1)+a.count(x)+a.count(x+1)
print(max(count(x) for x in range(min(a),max(a)+1)))

Submission status: Time Limit Exceeded

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


Xhairetsu={}


for i in range(len(AN)):
    for X in range(1,10**5):
        if AN[i]<=X+1 and AN[i]>=X-1 and X  not in Xhairetsu.keys():
            Xhairetsu[X]=1
        elif AN[i]<=X+1 and AN[i]>=X-1 and X in Xhairetsu.keys():
            Xhairetsu[X]+=1
        
print(max(Xhairetsu.values()))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = sorted(list(map(int, input().split())))
b = [0 for _ in range (N)]
for i in range(N):
    j = i-1
    while j >= 0:
        if abs(a[i]-a[j])<=1:
            b[i] += 1
            j -= 1
        else:
            break
    j = i+1
    while j <= N-1:
        if abs(a[i]-a[j])<=1:
            b[i] += 1
            j += 1
        else:
            break
print(max(b)+1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
    
#dics min max
dicsmin = min(a)
dicsmax = max(a)

counter = []
for i in range(dicsmin,dicsmax + 1):
    xcount = 0
    x = i
    for k in range(len(a)):
        if a[k] == x or a[k] == x-1 or a[k] == x + 1:
            xcount = xcount + 1
    counter.append(xcount)

print(max(counter))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
    
#dics min max
dicsmin = min(a)
dicsmax = max(a)

counter = []
for i in range(dicsmin,dicsmax + 1):
    xcount = 0
    x = i
    xcount = a.count(x) + a.count(x-1) + a.count(x + 1)
    counter.append(xcount)

print(max(counter))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
dics = {}
for i in range(len(a)):
    if a[i] in dics:
        dics[a[i]] = dics[a[i]]  + 1
    else:
        dics.update({a[i]:1})
    
#dics min max
dicsmin = min(list(dics.keys()))
dicsmax = max(list(dics.keys()))

counter = []
for i in range(dicsmin,dicsmax + 1):
    xcount = 0
    x = i
    for k in range(len(a)):
        if a[k] == x or a[k] == x-1 or a[k] == x + 1:
            xcount = xcount + 1
    counter.append(xcount)

print(max(counter))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
dics = {}
for i in range(len(a)):
    if a[i] in dics:
        dics[a[i]] = dics[a[i]]  + 1
    else:
        dics.update({a[i]:1})
    
#dics min max
dicsmin = min(list(dics.keys()))
dicsmax = max(list(dics.keys()))

counter = []
for i in range(dicsmin,dicsmax + 1):
    xcount = 0
    x = i
    xcount = a.count(x) + a.count(x-1) + a.count(x + 1)
    counter.append(xcount)

print(max(counter))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
ans = 0
for x in range(100000):
    cnt = 0
    for elem in a:
        if elem == x-1 or elem == x or elem == x + 1:
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
ans = 0

for i in range(0, 10**5+1):
  count = 0
  for j in l:
    if j == i or j == i+1 or j == i-1:
      count += 1
  if count > ans:
    ans = count

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
ans = 0
maximum = max(l)+1
minimum = min(l)-1

for i in range(minimum, maximum+1):
  count = 0
  for j in l:
    if j == i or j == i+1 or j == i-1:
      count += 1
  if count > ans:
    ans = count

print(ans)

Submission status: Time Limit Exceeded

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


# ある数の誤差１で収まる個数を計算する
# 最も多い物を出力
# 一度全て展開する
# 数列の最初の数について全て走査して、つぎはその次の数、、、と繰り返していく
# どこにカウンターを設置するのがよいか
# 外側にゼロでカウンターを配置して最も内側で外にあるカウンターよりも数値が大きければ入れ替える

ans = 0
for i in nums:
    cnt = 0
    for n in nums:
        if n in range(i-1, i+2):
            cnt += 1
    if ans < cnt:
        ans = cnt

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
Data=list(map(int,input().split()))
mindata=min(Data)-1
maxdata=max(Data)+1
ans=0
for i in range(mindata,maxdata+1):
    cnt=0
    for j in range(N):
        if abs(Data[j]-i)<=1:cnt+=1
    if ans<cnt:
        ans=cnt
    if ans==N:break
print(ans)

Submission status: Time Limit Exceeded

Solution code:

N=int(input())
Data=list(map(int,input().split()))
mindata=min(Data)-1
maxdata=max(Data)+1
ans=0
for i in range(mindata,maxdata+1):
    cnt=0
    for j in range(N):
        if abs(Data[j]-i)<=1:cnt+=1
    if ans<cnt:
        ans=cnt
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
p = [0] * 100005
for i in range(100005):
    p[i] += a.count(i - 1)
    p[i] += a.count(i)
    p[i] += a.count(i + 1)

print(max(p))

Submission status: Time Limit Exceeded

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

num = [A.count(A[i]) + A.count(A[i]-1) + A.count(A[i]+1) for i in range(N)]
print(max(num))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=set(a)
mx=0
for i in b:
  mx=max(mx,a.count(i-1)+a.count(i+1)+a.count(i))
print(mx)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
count=0
ans=[]
for i in range(min(a),max(a)+1):
    for j in a:
        if j==i or i==j-1 or i==j+1:
            count+=1
    ans.append(count)
    count=0
print(max(ans))

Submission status: Time Limit Exceeded

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

def count(n,a):
    count = 0
    cmax = 0
    if n == 1:
        return 1
    else:
        for i in range(n):
            j = i
            while j <= n-1  and a[j]-a[i] <= 2:
                count += 1
                j += 1
            if count > cmax:
                cmax = count
            count = 0
        return cmax
        
print(count(n,a))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

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

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
val = [int(x) for x in input().split()]
res_val = []
for i in val:
    res_val.append(i-1)
    res_val.append(i)
    res_val.append(i+1)

set_val = set(res_val)

res = 0
for j in set_val:
    if res < res_val.count(j):
        res = res_val.count(j)
print(res)

Submission status: Time Limit Exceeded

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


possibles = set()
for x in xs:
    possibles.add(x - 1)
    possibles.add(x)
    possibles.add(x + 1)


res = 0
for p in possibles:
    d = 0
    for x in xs:
        c = abs(x - p)
        if c <= 1: d += 1
    if res < d: res = d

print(res)

Submission status: Time Limit Exceeded

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


possibles = set()
for x in xs:
    possibles.add(x - 1)
    possibles.add(x)
    possibles.add(x + 1)


ds = []
for p in possibles:
    d = 0
    for x in xs:
        c = abs(x - p)
        if c <= 1: d += 1
    ds.append(d)


print(max(ds))

Submission status: Time Limit Exceeded

Solution code:

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


possibles = []
for x in xs:
    possibles.append(x - 1)
    possibles.append(x)
    possibles.append(x + 1)

possibles = set(possibles)

ds = []
for p in possibles:
    d = 0
    for x in xs:
        c = abs(x - p)
        if c <= 1: d += 1
    ds.append(d)

print(max(ds))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def main():
    N = int(raw_input())
    As = np.array(raw_input().split(' ')).astype(int)
    score = together(As)
    print score

def together(As):
    score = - np.inf
    target = 0
    for k in range(len(As)):
        for j in [1, 0, -1]:
            proposal = As[k] + j
            delta = np.abs(As - proposal)
            scorenow = len( np.where((delta == 1) | (delta == 0))[0])
            if scorenow > score:
                score = scorenow
                target = proposal
    return int(score)

def checkpasses(value):
    return value in [0,1]

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
inlis = list(map(int,input().split()))
donelis =[]
numlis=[]

for i in inlis:
    donelis.append(i+1)
    donelis.append(i)
    donelis.append(i-1)
    if not i in numlis:
        numlis.append(i)
    if not i+1 in numlis:
        numlis.append(i+1)
    if not i-1 in numlis:
        numlis.append(i-1)
estc =0
for i in numlis:
    a =donelis.count(i)
    if estc < a:
        estc = a
print(estc)

Submission status: Time Limit Exceeded

Solution code:
N= int(input())
inlis = list(map(int,input().split()))
donelis =[]
for i in inlis:
    donelis.append(i+1)
    donelis.append(i)
    donelis.append(i-1)
estc =0
for i in donelis:
    a =donelis.count(i)
    if estc < a:
        estc = a
print(estc)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_n = list(map(int, input().split()))
a_n.sort()
a_n.reverse()
def check(idx):
    global a_n
    base = a_n[idx]
    count = 0
    dif = 0
    now = a_n[idx]
    while dif <= 2:
        idx += 1
        count += 1
        if(idx == len(a_n)):
            return count
        dif = base - a_n[idx]
        
    return count

ans = -1
for i in  range(n):
    if(ans < check(i)):
        ans = check(i)
print(ans)

Submission status: Time Limit Exceeded

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

if N ==1:
    ans[0] = 1
else:
    for X in range(N):
        for i in range(N):
            if abs(X-A[i])<=1:
                ans[X]+=1

print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N = input()
a_raw = list(map(int, input().split()))
a_plus = [num + 1 for num in a_raw]
a_minus = [num - 1 for num in a_raw]
numbers = set(a_raw) | set(a_minus) | set(a_plus)
num_count = list()
for number in numbers:
    num_count.append(a_raw.count(number) + a_plus.count(number) + a_minus.count(number))

print(max(num_count))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N = input()
a_raw = list(map(int, input().split()))
a_plus = [num + 1 for num in a_raw]
a_minus = [num - 1 for num in a_raw]
numbers = set(a_raw) | set(a_minus) | set(a_plus)
num_count = defaultdict(int)
for number in numbers:
    num_count[number] += a_raw.count(number) + a_plus.count(number) + a_minus.count(number)

print(max(num_count.values()))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
if N>2:
    x = [0]*(N-2)
    for i in range(N-2):
        x[i] = a.count(i) + a.count(i+1) + a.count(i+2)
    print(max(x))
elif N == 2:
    if a[0] == a[1] or a[0] == a[1] +1 or a[0] == a[1] -1  :
        print(2)
    else:
        print(1)
else:
    print(1)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def main():
    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())) 

main()

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

def main():
    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())) 

main()

Submission status: Time Limit Exceeded

Solution code:
ans=0#1
n=int(input())
num_l=list(map(int,input().split()))
for i in range(n):
    for j in [0,1,-1]:
        s=num_l[i]+j
        score=sum(1 for k in range(n) if k != i and num_l[k]-s in [0,1,-1])#+1
        if score > ans:
            ans=score
print(ans+1)

Submission status: Time Limit Exceeded

Solution code:
ans=1
n=int(input())
num_l=list(map(int,input().split()))
for i in range(n):
    for j in [0,1,-1]:
        s=num_l[i]+j
        score=sum([1 for k in range(n) if k != i and num_l[k]-s in [0,1,-1]])+1
        if score > ans:
            ans=score
print(ans)

Submission status: Time Limit Exceeded

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: accum + x, map(f, xs))

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

a_min, a_max = min(a), max(a)
cnt = 0
p = [-1] * N

for j in range(a_min, a_max+1):
    for i in range(N):
        if j-1 <= a[i] <= j+1:
            p[i] = j
    cnt = max(cnt, p.count(j))
print(cnt)