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:
def main():
  n=int(input())
  a=list(map(int,input().split()))
  ap=[i+1 for i in set(a)]
  am=[i-1 for i in set(a)]
  A=set(ap+am+a)
  count=0
  for i in A:
    x=0
    for j in a:
      x+=1 if i==j or i==j+1 or i==j-1 else 0
    count=max(count,x)
  print(count)
if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
count = 0
ans = []
for i in range(n):
  for j in range(n-1):
    if j >= i and a[j]-a[i] <= 2:
      #print(i,j)
      count += 1
    else:
      ans.append(count)
      count = 0
if n == 1:
  print(1)
else:
  print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
max_a = 0
for i in a:
  tmp = a.count(i - 1) +a.count(i) + a.count(i + 1)
  if tmp > max_a:
    max_a = tmp
  tmp = a.count(i) +a.count(i + 1) + a.count(i + 2)
  if tmp > max_a:
    max_a = tmp
print(max_a)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(min(a), max(a)+1):
    cnt = 0
    for j in range(n):
        if abs(a[j]-i) <= 1:
            cnt += 1
    if cnt > 0:
        ans = max(ans, cnt)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
ans=1
for i in range(n-1):
    tmp=a.count(a[i])+a.count(a[i]+1)+a.count(a[i]+2)
    ans=max(tmp,ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
aList = list(map(int, input().split()))
ans = 0
for x in range(10 ** 5):
    num = aList.count(x - 1) + aList.count(x) + aList.count(x + 1)
    if ans < num:
        ans = num
print(ans)

Submission status: Time Limit Exceeded

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

max_count = 0
for i in range(10**5+1):
    count = 0
    for j in range(-1,2):
        count += A.count(i+j)
    max_count = max(count, max_count)
print(max_count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

A = list(map(int, input().split()))
max_count = 0
lower = min(A)-1
upper = max(A)+1
for i in range(lower,upper+1):
    count = 0
    for j in range(N):
        for k in range(-1,2,1):
            if A[j] + k == i:
                count += 1
    max_count = max(count, max_count)
    
print(max_count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
list_a = [int(x) for x in input().split()]

ans = 0
ansX1 = 0
ansX2 = 0

for X in range(min(list_a),max(list_a)+1) :
    ansX0 = list_a.count(X)
    ansX = ansX0 + ansX1 + ansX2
    ans = max(ans,ansX)
    ansX2 = ansX1
    ansX1 = ansX0

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
list_a = [int(x) for x in input().split()]

ans = 0

for X in range(min(list_a),max(list_a)+1) :
    ansX = list_a.count(X) + list_a.count(X+1) + list_a.count(X-1)
    ans = max(ans,ansX)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
list_a = [int(x) for x in input().split()]

ans = 0

for i in range(N) :
    X = list_a[i]
    T0 = list_a.count(X)
    T1 = list_a.count(X+1)
    T2 = list_a.count(X+2)
    Tm1 = list_a.count(X-1)
    Tm2 = list_a.count(X-2)
    ans = max(ans,T0+T1+T2,T0+T1+Tm1,T0+Tm1+Tm2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
list_a = [int(x) for x in input().split()]

ans = 0

for i in range(N) :
    X = list_a[i]
    ans1 = list_a.count(X) + list_a.count(X+1) + list_a.count(X-1)
    ans2 = list_a.count(X) + list_a.count(X+1) + list_a.count(X+2)
    ans3 = list_a.count(X) + list_a.count(X-1) + list_a.count(X-2)
    ans = max(ans,ans1,ans2,ans3)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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

    vals = []
    for i in set(a_list):
        for X in [i]:
            vals.append(len([a for a in a_list if abs(X - a) <= 1]))
    print(max(vals))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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

    vals = []
    for i in set(a_list):
        for X in [i-1, i, i+1]:
            vals.append(len([a for a in a_list if abs(X - a) <= 1]))
    print(max(vals))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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

    vals = []
    for i in a_list:
        for X in [i-1, i, i+1]:
            vals.append(len([a for a in a_list if abs(X - a) <= 1]))
    print(max(vals))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


def check(a_list :list, X :int) -> int:
    count=0
    for num in a_list:
        diff = num - X
        if abs(diff) <=1:
            count += 1
    
    return count
   
#----------
N = int(input().strip())
a_list = list(map(int, input().rstrip().split()))
#----------
a_set=set(a_list)

count = 0
for X in a_set:
    tmp_count=check(a_list,X)
    
    if tmp_count > count:
        count = tmp_count
        result_X = X
    
print(count)

Submission status: Time Limit Exceeded

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


def check(a_list :list, X :int) -> int:
    count=0
    for num in a_list:
        diff = num - X
        if abs(diff) <=1:
            count += 1
    
    return count
   
#----------
N = int(input().strip())
a_list = list(map(int, input().rstrip().split()))
#----------
a_max=max(a_list)
a_min=min(a_list)

count = 0
for X in range( a_min, (a_max+1) ):
    tmp_count=check(a_list,X)
    
    if tmp_count > count:
        count = tmp_count
        #result_X = X
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
al = list(map(int, input().split()))
al_s = list(set(al))

count = 0
for a in al_s:
    ai = al.count(a) + al.count(a + 1) + al.count(a - 1)
    if ai > count:
        count = ai
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
al = list(map(int, input().split()))
al_s = sorted(list(set(al)))

count = 0
for a in al_s:
    ai = al.count(a) + al.count(a + 1) + al.count(a - 1)
    if ai > count:
        count = ai
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a_lst = [int(x) for x in input().split()]

max_a = -1
max_cnt = -1

for a in a_lst:
    if max_a < a:
        max_a = a
for x in range(max_a + 1):
    cnt = 0
    for a in a_lst:
        if x - 1 <= a and a <= x + 1:
            cnt += 1
    if max_cnt < cnt:
        max_cnt = cnt
print(max_cnt)

Submission status: Time Limit Exceeded

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

# aiの各値の個数を数える
a_dict = {}
for i in a_set:
    a_dict[i] = a.count(i)

ans = 0
for i in range(1, 10 ** 5):
    work = 0
    if (i - 1) in a_set:
        work += a_dict[i - 1]
    if i in a_set:
        work += a_dict[i]
    if (i + 1) in a_set:
        work += a_dict[i + 1]
    ans = max(ans, work)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = input()
a_list = list(map(int, input().split()))
ans = 0
check_set = set(a_list)

for i in check_set:
    ans = max(ans, a_list.count(i-1) + a_list.count(i) + a_list.count(i+1))
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = input()
a_list = list(map(int, input().split()))
ans = 0
checked_list = []

for i in a_list:
    ans = max(ans, a_list.count(i-1) + a_list.count(i) + a_list.count(i+1))
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = input()
a_list = list(map(int, input().split()))
ans = 0
checked_list = []

for i in a_list:
  if i in checked_list:
    pass
  else:
    ans = max(ans, a_list.count(i-1) + a_list.count(i) + a_list.count(i+1))
    checked_list.append(i)
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# import statistics
N = int(input())
A = list(map(int,input().split()))
# mode = statistics.mode(A)
# print(mode)
# tar = mode
B = []
for a in A:
    count1 = A.count(a)
    count2 = A.count(a+1)
    count3 = A.count(a-1)
    cnt = count1 + count2 + count3
    B.append(cnt)
print(max(B))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

dList = sorted(list(map(int,input().split())))
  
count = 0
for i in range(n):
  tmpC = 0
  for j in range(n):
      if dList[i]-1 > dList[j]:
        pass
      elif dList[i]+1 < dList[j]:
        break 
      else:
        tmpC +=1
  if tmpC > count:
    count = tmpC

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 1
#print(a)

for i in range(n-1):
    for j in range(i+1, n):
        if a[j] > a[i] + 2:
            #print(i, j)
            if (j - i) > ans:
                ans = (j - i)
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

# max_x = max(numbers) + 1
# max_x = int(sum(numbers) / len(numbers))
res = 0
test = set()
for n in numbers:
    test.add(n)
    test.add(n - 1)
    test.add(n + 1)

# for i in range(max_x + 1):
for i in test:
    c = 0
    for n in numbers:
        if n - 1 == i or n == i or n + 1 == i:
            c += 1
    if res < c:
        res = c

print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

# max_x = max(numbers) + 1
# max_x = int(sum(numbers) / len(numbers))
res = []
test = set()
for n in numbers:
    test.add(n)
    test.add(n - 1)
    test.add(n + 1)

# for i in range(max_x + 1):
for i in test:
    c = 0
    for n in numbers:
        if n - 1 == i or n == i or n + 1 == i:
            c += 1
    res.append(c)

print(max(res))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

# max_x = max(numbers) + 1
max_x = int(sum(numbers) / len(numbers))
res = []

for i in range(max_x + 1):
    c = 0
    for n in numbers:
        if n - 1 == i or n == i or n + 1 == i:
            c += 1
    res.append(c)

print(max(res))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

max_x = max(numbers) + 1
res = []

for i in range(max_x + 1):
    c = 0
    for n in numbers:
        if n - 1 == i or n == i or n + 1 == i:
            c += 1
    res.append(c)

print(max(res))

Submission status: Time Limit Exceeded

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

for x in A:
    cnt = 0
    tmp = [x-1, x, x+1]
    for y in A:
        if y in tmp:
            cnt += 1
    ans.append(cnt)
#print(ans)
print(max(ans))

Submission status: Time Limit Exceeded

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

arr = []
for x in range(10**5):
    count = 0
    for i in range(n):
        if a[i] == x-1 or a[i] == x or a[i] == x+1:
            count += 1
    arr.append(count)

print(max(arr))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
li = np.array([])

N=int(input())
li = list(map(int, input().split()))
arr = np.array(li)

max = 0

for i in range(100000 + 1):

  a = np.count_nonzero(arr == i)
  a += np.count_nonzero(arr == (i + 1))
  a += np.count_nonzero(arr == (i - 1))

  if max < a:
    max = a

print(max)

Submission status: Time Limit Exceeded

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

max = 0

for i in range(100000 + 1):
  X = i

  new = [l for l in li if l == X or l == (X + 1) or l == (X - 1)]

  if max < len(new):
    max = len(new)

print(max)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a = list( map( int, input().split() ) )
    b = set(a)
    b.add(min(b)-1)
    b.add(max(b)+1)

    cnt = [0]*len(b)
    for j in a:
        for i,num in enumerate(b):
            if j-1 == num or j == num or j+1 == num:
                cnt[i] += 1
    print(max(cnt))
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list( map( int, input().split() ) )
b = set(a)
b.add(min(b)-1)
b.add(max(b)+1)

cnt = [0]*len(b)
for i,num in enumerate(b):
    for j in a:
        if j-1 == num or j == num or j+1 == num:
            cnt[i] += 1
print(max(cnt))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
max_x=max(A)+2
min_x=min(A)-1
l=set()
for x in range(min_x,max_x):
    cnt=0
    for a in A:
        if abs(x-a)<=1:
            cnt+=1
    l.add(cnt)
print(max(l))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
max_x=max(A)+2
min_x=min(A)-1
l=[]
for x in range(min_x,max_x):
    cnt=0
    for a in A:
        if abs(x-a)<=1:
            cnt+=1
    l.append(cnt)
print(max(l))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=list(map(int,input().split(' ')))
dic = {}
for i in s:
    a,b,c = i-1,i,i+1
    if a in dic.keys():
        dic[a] += 1
    else:
        dic[a]=1
    if b in dic.keys():
        dic[b] += 1
    else:
        dic[b] = 1
    if c in dic.keys():
        dic[c] += 1
    else:
        dic[c] =1
print(max(dic.values()))

Submission status: Time Limit Exceeded

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

num_list = [0] * (max(a) + 2)

for i in range(n):
    num_list[a[i]] += 1
    if i == n:
        continue
    elif a[i] == 0:
        continue
    else:
        num_list[a[i]-1] += 1
    if i == 0 or a[i] == max(a):
        continue
    else:
        num_list[a[i]+1] += 1

print(max(num_list))

Submission status: Time Limit Exceeded

Solution code:
input()
A=list(map(int,input().split()))
B=set(A)
dict={}
for x in B:
  dict[x]=A.count(x)
max=0
for x in B:
  tmp = dict[x]
  if x-1 in B:
    tmp+=dict[x-1]
  if x+1 in B:
    tmp+=dict[x+1]
  if tmp>max:
    max=tmp
print(max)

Submission status: Time Limit Exceeded

Solution code:
input()
a = list(map(int, input().split()))
b = list(a)
b.extend(list(map(lambda x: x + 1, a)))
b.extend(list(map(lambda x: x - 1, a)))
c_max = 0
for i in list(set(b)):
    if b.count(i) > c_max:
        c_max = b.count(i)
print(c_max)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
maxa=max(a)+1
mina=min(a)-1
count=0
max_count=[0,0]
for i in range(mina,maxa):
    count=0
    for j in a:
        if(i==j or i==(j-1) or i==(j+1)):
            count+=1
    if(count>max_count[1]):
        max_count[0]=i
        max_count[1]=count
print(max_count[1])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
count = [0 for i in range(N)]

for i in range(N):
    for j in range(i, N):
        if abs(A[j] - A[i]) <= 1:
            count[i] += 1
            count[j] += 1

print(max(count)-1)

Submission status: Time Limit Exceeded

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

print(max(count))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
num = list(map(int, input().split(" ")))
num_sort = sorted(num)

num_set = set(num)
num_set_l = list(num_set)

num_set_l = sorted(num_set_l)
#print(num_set_l)
counts = []

for i in range(len(num_set_l)-1):
  if num_set_l[i+1] - num_set_l[i] == 1:
    if i == len(num_set_l) - 2:
      counts.append(len(num_sort) - num_sort.index(num_set_l[i]))
      break
    if num_set_l[i+2] - num_set_l[i] == 2:
      if i == len(num_set_l) - 3:
        counts.append(len(num_sort) - num_sort.index(num_set_l[i]))
        break
      counts.append(num_sort.index(num_set_l[i+3])- num_sort.index(num_set_l[i]))
    else:
      counts.append(num_sort.index(num_set_l[i+2]) - num_sort.index(num_set_l[i]))
  else:
    counts.append(num_sort.index(num_set_l[i+1]) - num_sort.index(num_set_l[i]))

if len(counts) == 0:
  print(len(num_sort))
else:
  print(max(counts))

Submission status: Time Limit Exceeded

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

a.sort()
cur = a[0]
ans1 = 1
ans = 1

for i in range(n - 1):
    if a[i + 1] - a[i] <= 2:
        cur = a[i]
        ans1 = a.count(cur) + a.count(cur + 1) + a.count(cur + 2)

        if ans < ans1:
            ans = ans1
        ans1 = 0

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import scipy.stats as stats

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

#num1 = [int(n) for n in num]
num1_cand = []

# 各要素に-1, 0, 1を加算した値のリスト生成
for i in range(N):
  num1_cand += [num1[i]-1, num1[i], num1[i]+1]
#print(num1_cand)

# 最頻値
num_mode = stats.mode(num1_cand)
# num_mode = (最頻値、その最頻値が頻出した回数)、要素numpy型を返すので、
# int型にして返す
print(int(num_mode[1][0]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import scipy.stats as stats

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

#num1 = [int(n) for n in num]
num1_cand = []

# 各要素に-1, 0, 1を加算した値のリスト生成
for i in range(N):
  num1_cand += [num1[i]-1, num1[i], num1[i]+1]
#print(num1_cand)


# ndarray変換
num1_cand_1 = np.array(num1_cand)

# 最頻値
num_mode = stats.mode(num1_cand_1)
# num_mode = (最頻値、その最頻値が頻出した回数)、要素numpy型を返すので、
# int型にして返す
print(int(num_mode[1][0]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import scipy.stats as stats

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

#num1 = [int(n) for n in num]
num1_cand = []

# 各要素に-1, 0, 1を加算した値のリスト生成
for i in range(N):
  num1_cand += [[num1[i]-1, num1[i], num1[i]+1]]
#print(num1_cand)


# ndarray変換
num1_cand_np = np.array(num1_cand)
# 1次元配列に変換
num1_cand_1 = num1_cand_np.reshape(-1, )

# 最頻値
num_mode = stats.mode(num1_cand_1)
# num_mode = (最頻値、その最頻値が頻出した回数)、要素numpy型を返すので、
# int型にして返す
print(int(num_mode[1][0]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import scipy.stats as stats

N = int(input())
num = input().split(" ")

num1 = [int(n) for n in num]
num1_cand = []

# 各要素に-1, 0, 1を加算した値のリスト生成
for i in range(N):
  num1_cand += [[num1[i]-1, num1[i], num1[i]+1]]
#print(num1_cand)


# ndarray変換
num1_cand_np = np.array(num1_cand)
# 1次元配列に変換
num1_cand_1 = num1_cand_np.reshape(-1, )

# 最頻値
num_mode = stats.mode(num1_cand_1)
# num_mode = (最頻値、その最頻値が頻出した回数)、要素numpy型を返すので、
# int型にして返す
print(int(num_mode[1][0]))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
mn = min(a)
mx = max(a)
res = 0 
for i in range(mn, mx + 1): 
        cnt = 0 
        for j in a:
                if -1 <= i - j <= 1:
                        cnt += 1
        res = max(res, cnt)
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
mn = min(a)
mx = max(a)
res = 0 
for i in range(mn, mx + 1): 
        cnt = a.count(i - 1)
        cnt += a.count(i)
        cnt += a.count(i + 1)
        res = max(res, cnt)
print(res)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter



def main()->None:
    N = int(input())
    a = list(map(int, input().split()))
    a_dict = Counter(a)
    keys = a_dict.keys()
    max_count = 0
    for key in keys:
        tmp_count = 0
        for i in keys:
            if key + 1 == i or key - 1 == i or key == i:
                tmp_count += a_dict[i]
        if tmp_count > max_count:
            max_count = tmp_count
    print(max_count)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter



def main()->None:
    # a_iに１を足すか、１引くか、何もしないかの操作を行って、ある整数個数最大化をする
    # x を決めるとgreedyに決まる。
    # 最後の一つのサンプルがTLEになる。jit の使い方もよくわからん
    N = int(input())
    a = list(map(int, input().split()))
    a_dict = Counter(a)
    keys = a_dict.keys()
    max_count = 0
    for key in keys:
        tmp_count = a_dict[key]
        for i in keys:
            if key - 1 == i or key + 1 == i:
                tmp_count += a_dict[i]
        if tmp_count > max_count:
            max_count = tmp_count
    print(max_count)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter



def main()->None:
    N = int(input())
    a = list(map(int, input().split()))
    a_dict = Counter(a)
    keys = a_dict.keys()
    max_count = 0
    for key in keys:
        tmp_count = 0
        for i in keys:
            if abs(key - i) <= 1:
                tmp_count += a_dict[i]
        if tmp_count > max_count:
            max_count = tmp_count
    print(max_count)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter



def main()->None:
    # a_iに１を足すか、１引くか、何もしないかの操作を行って、ある整数個数最大化をする
    # x を決めるとgreedyに決まる。
    # 最後の一つのサンプルがTLEになる。jit の使い方もよくわからん
    N = int(input())
    a = list(map(int, input().split()))
    a_dict = Counter(a)
    max_count = 0
    for key in a_dict.keys():
        tmp_count = 0
        for i in a_dict.keys():
            if abs(key - i) <= 1:
                tmp_count += a_dict[i]
        if tmp_count > max_count:
            max_count = tmp_count
    print(max_count)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def main()->None:
    # a_iに１を足すか、１引くか、何もしないかの操作を行って、ある整数個数最大化をする
    # x を決めるとgreedyに決まる。
    # どうやってxを決めるのか。
    N = int(input())
    a = list(map(int, input().split()))
    set_a = set(a)
    max_count = 0
    for a_compo in set_a:
        X = a_compo
        tmp_count = 0
        for i in set_a:
            if abs(X - i) <= 1:
                tmp_count += a.count(i)
        if tmp_count > max_count:
            max_count = tmp_count
    print(max_count)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def main()->None:
    # a_iに１を足すか、１引くか、何もしないかの操作を行って、ある整数個数最大化をする
    # x を決めるとgreedyに決まる。
    # どうやってxを決めるのか。
    N = int(input())
    a = list(map(int, input().split()))
    set_a = set(a)
    max_count = 0
    for a_compo in set_a:
        X = a_compo
        tmp_count = 0
        for i in a:
            if abs(X - i) <= 1:
                tmp_count += 1
        if tmp_count > max_count:
            max_count = tmp_count
    print(max_count)

if __name__ == "__main__":
    #import time
    #start = time.time()
    main()
    #print("time:{}".format(time.time() - start))

Submission status: Time Limit Exceeded

Solution code:


def main()->None:
    # a_iに１を足すか、１引くか、何もしないかの操作を行って、ある整数個数最大化をする
    # x を決めるとgreedyに決まる。
    # どうやってxを決めるのか。
    N = int(input())
    a = list(map(int, input().split()))
    range_N = range(N)
    max_counter = 0
    set_a = set(a)
    for i in set_a:
        X = i
        tmp_count = 0
        for j in a:
            if abs(j - X) <= 1:
                tmp_count += 1

        if tmp_count > max_counter:
            max_counter = tmp_count

    print(max_counter)



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:


def main()->None:
    # a_iに１を足すか、１引くか、何もしないかの操作を行って、ある整数個数最大化をする
    # x を決めるとgreedyに決まる。
    # どうやってxを決めるのか。
    N = int(input())
    a = list(map(int, input().split()))
    range_N = range(N)
    max_counter = 0
    for i in range_N:
        X = a[i]
        tmp_count = 0
        for j in a:
            if j + 1 == X or j - 1 == X or j == X:
                tmp_count += 1

        if tmp_count > max_counter:
            max_counter = tmp_count

    print(max_counter)



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:


def main()->None:
    # a_iに１を足すか、１引くか、何もしないかの操作を行って、ある整数個数最大化をする
    # x を決めるとgreedyに決まる。
    # どうやってxを決めるのか。
    N = int(input())
    a = list(map(int, input().split()))
    range_N = range(N)
    max_counter = 0
    for i in range_N:
        X = a[i]
        tmp_count = 0
        for j in a:
            if j + 1 == X:
                tmp_count += 1
            if j - 1 == X:
                tmp_count += 1
            if j == X:
                tmp_count += 1

        if tmp_count > max_counter:
            max_counter = tmp_count

    print(max_counter)



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:


def main()->None:
    # a_iに１を足すか、１引くか、何もしないかの操作を行って、ある整数個数最大化をする
    # x を決めるとgreedyに決まる。
    # どうやってxを決めるのか。
    N = int(input())
    a = list(map(int, input().split()))
    range_N = range(N)
    counter = {}
    for i in range_N:
        X = a[i]
        tmp_count = 0
        for j in a:
            if j + 1 == X:
                tmp_count += 1
            if j - 1 == X:
                tmp_count += 1
            if j == X:
                tmp_count += 1

            counter[X]=tmp_count

    print(max(counter.values()))



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
amin = min(a)
amax = max(a)
ans = 0
for x in range(amin,amax+1):
	    p = 0
	    p += a.count(x)
	    p += a.count(x+2)
	    p += a.count(x+1)
	    ans = max(ans,p)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
amin = min(a)
amax = max(a)
ans = 0
for x in range(amin,amax+1):
	    p = 0
	    p += a.count(x)
	    p += a.count(x+2)
	    p += a.count(x+1)
	    ans = max(ans,p)
print(ans)

Submission status: Time Limit Exceeded

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

a = []

for i in range(n):
	a.append(l[i]-1)
	a.append(l[i])
	a.append(l[i]+1)

maxnum = 0

b = list(set(a))

for i in range(len(b)):
	if maxnum < a.count(b[i]):
		maxnum = a.count(b[i])
print(maxnum)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
ans = 0
for a in A:
    candi = [
        np.sum(np.abs(A - np.ones(N) * (a - 1)) <= 1),
        np.sum(np.abs(A - np.ones(N) * a) <= 1),
        np.sum(np.abs(A - np.ones(N) * (a + 1)) <= 1),
    ]
    ans = max(ans, np.max(candi))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = np.array([int(i) for i in input().split()])
ans = 0
for i in range(max(A) + 1):
    ans = max(ans, np.sum(np.abs(A - np.ones(N) * i) <= 1))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(input().split())
ans=1
for i in range(100000):
  if a.count(str(i))+a.count(str(i+1))+a.count(str(i+2))>ans:
    ans=a.count(str(i))+a.count(str(i+1))+a.count(str(i+2))
print(ans)

Submission status: Time Limit Exceeded

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

a_li.sort()

ans = 0

a_set = set(a_li)

check = [0] * (a_li[-1]+2)
for i in range(a_li[-1]+1):
    check[i] = a_li.count(i)

for i in a_set:
    s = check[i] + check[i-1] + check[i+1]
    
    ans = max(ans,s)

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

a_set = set(a_li)

for i in a_set:
    s = a_li.count(i)
    s += a_li.count(i-1)
    s += a_li.count(i+1)
    
    ans = max(ans,s)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
a = [int(x) for x in input().split()]

c = collections.Counter(a)
counts = []
for i in c.keys():
    counts.append(sum([v for k, v in c.items() if abs(k-i) <= 1]))

print(max(counts))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
cntA = [0 for _ in range(10**5)]
for i in range(10**5):
    if i in A:
        cntA[i] = A.count(i)
sumA = [0 for _ in range(10**5)]
sumA[0] = cntA[0]
sumA[1] = cntA[0] + cntA[1]
for i in range(2,10**5):
    sumA[i] = cntA[i] + cntA[i-1] + cntA[i-2]
print(max(sumA))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split(' ')]
count = 0
answer = 0

A.sort()

for i in range(A[0],A[N-1]+1):
    count = 0
    for a in A:
        if i-1 <= a <= i+1:
            count += 1
    if answer < count:
        answer = count
print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
items=list(map(int,input().split()))
items.sort()
cnt_list=[]
for i in set(items):
  cnt=0
  for j in range(n):
    if abs(items[j]-i)<=1:
      cnt+=1
    if items[j]-i>1:
      break
  cnt_list.append(cnt)
print(max(cnt_list))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
items=list(map(int,input().split()))
items.sort()
cnt_list=[]
for i in set(items):
  cnt=0
  for j in range(n):
    if abs(items[j]-i)<=1:
      cnt+=1
    if cnt>0 & abs(items[j]-i)>1:
      break
  cnt_list.append(cnt)
print(max(cnt_list))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
items=list(map(int,input().split()))
cnt_list=[]
for i in set(items):
  cnt=0
  for j in range(n):
    if abs(items[j]-i)<=1:
      cnt+=1
  cnt_list.append(cnt)
print(max(cnt_list))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
items=list(map(int,input().split()))
items.sort()
cnt_list=[]
for i in set(items):
  cnt=0
  for j in range(n):
    if abs(items[j]-i)<=1:
      cnt+=1
  cnt_list.append(cnt)
print(max(cnt_list))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(lambda x: int(x), input().split()))
ans=0
for i in range(2,100000):
    tmp = a.count(i-1)+a.count(i)+a.count(i+1)
    if ans < tmp:
        ans=tmp
print(ans)

Submission status: Time Limit Exceeded

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