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

# 文字数のカウント
cnt=dict()
for a in A:
  if a in cnt.keys():
    cnt[a]+=1
  else:
    cnt[a]=1
    
# 頻出数を探す
cnt_sort = sorted(cnt.items(), key=lambda x:x[1])
cnt_sort.reverse()

# 頻出数100つとその±1の数字を候補とする
candidates=set()
for i in range(min(100,len(cnt))):
  candidates.add(cnt_sort[i][0])
  candidates.add(cnt_sort[i][0]-1)
  candidates.add(cnt_sort[i][0]+1)

# 配列に渡された配列内に，±1で数xに出来る数がいくつあるか判定
def neigh(array, x):
  cnt = 0
  for a in array:
    if a == x:
      cnt+=1
    elif a-1 == x:
      cnt+=1
    elif a+1 == x:
      cnt+=1
  return cnt

res=[]
for c in candidates:
  res.append(neigh(A,c))
  
print(max(res))

Submission status: Time Limit Exceeded

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

# 文字数のカウント
cnt=dict()
for a in A:
  if a in cnt.keys():
    cnt[a]+=1
  else:
    cnt[a]=1
    
# 頻出数を探す
cnt_sort = sorted(cnt.items(), key=lambda x:x[1])
cnt_sort.reverse()

# 頻出数3つとその±1の数字を候補とする(最大9つ)
candidates=set()
for i in range(len(cnt)):
  candidates.add(cnt_sort[i][0])
  candidates.add(cnt_sort[i][0]-1)
  candidates.add(cnt_sort[i][0]+1)

# 配列に渡された配列内に，±1で数xに出来る数がいくつあるか判定
def neigh(array, x):
  cnt = 0
  for a in array:
    if a == x:
      cnt+=1
    elif a-1 == x:
      cnt+=1
    elif a+1 == x:
      cnt+=1
  return cnt

res=[]
for c in candidates:
  res.append(neigh(A,c))
  
print(max(res))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
count = []
for i in range(1, 10**5):
    count.append(A.count(i))
ans = 0
for j in range(len(count)-2):
    if count[j] + count[j+1] + count[j+2] > ans:
        ans = count[j] + count[j+1] + count[j+2]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = sorted(list(map(int, input().split())))
ans = 0
for x in range(a[0],a[-1]+1):
    cnt = 0
    for i in a:
        if abs(i-x) == 0 or abs(i-x) == 1:
            cnt += 1
    ans = max(cnt, ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
cnt = 0
ans = 0
for x in range(min(a),max(a)+1):
    cnt = 0
    for i in a:
        if abs(i-x) == 0 or abs(i-x) == 1:
            cnt += 1
    ans = max(cnt, ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
cnt = 0
ans = 0
for x in range(min(a),max(a)+1):
    cnt = 0
    for i in a:
        if abs(i-x) == 0:
            cnt += 1
        elif abs(i-x) == 1:
            cnt += 1
    ans = max(cnt, ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
cnt = 0
ans = 0
for x in range(max(a)+1):
    cnt = 0
    for i in a:
        if abs(i-x) == 0:
            cnt += 1
        elif abs(i-x) == 1:
            cnt += 1
    ans = max(cnt, ans)
print(ans)

Submission status: Time Limit Exceeded

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

A = set(a)

ans = 0
for i in A:
    cnt = 0
    J = [i, i - 1, i + 1]
    for j in J:
        if j in a:
            cnt += a.count(j)
    ans = max(ans, cnt)
print(ans)

Submission status: Time Limit Exceeded

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

A = set(a)

ans = 0
for i in A:
    cnt = 0
    for j in a:
        if j == i or j == i + 1 or j == i - 1:
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#
# abc072 c
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """7
3 1 4 1 5 9 2"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10
0 1 2 3 4 5 6 7 8 9"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """1
99999"""
        output = """1"""
        self.assertIO(input, output)


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

    an = {}
    for a in A:
        an.setdefault(a, 0)
        an[a] += 1

    ans = 1
    for x in range(min(A)-1, max(A)+1):
        t = 0
        for k, v in an.items():
            if x == k-1 or x == k or x == k+1:
                t += v
        ans = max(ans, t)

    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Time Limit Exceeded

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

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

	for X in range(10 ** 5 + 1):
		if X == 0:
			ans[0] += a.count(0)
			ans[0] += a.count(1)
		elif X == 10 ** 5:
			ans[10 ** 5] += a.count(10 ** 5 - 1)
			ans[10 ** 5] += a.count(10 ** 5 + 1)
		else:
			ans[X] += a.count(X - 1)
			ans[X] += a.count(X)
			ans[X] += a.count(X + 1)

	print(max(ans))

 
if __name__ == "__main__":
  	main()

Submission status: Time Limit Exceeded

Solution code:
def solve():

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

    m = max(a) 
   # print("max:" + str(m))

    ans = 0
    lists = [0, 0, 0]

    for i in range(N):
        X = a[i]
        tmp = 0
        for k in range(N):
            x = a[k] + 1
            y = a[k] - 1
            z = a[k]
            if X == x or X == y or X == z:
                tmp += 1
        if tmp >= ans:
            ans = tmp
            lists[0] = ans

    ans = 0        

    for i in range(N):
        X = a[i] + 1
        tmp = 0
        for k in range(N):
            x = a[k] + 1
            y = a[k] - 1
            z = a[k]
            if X == x or X == y or X == z:
                tmp += 1
        if tmp >= ans:
            ans = tmp
            lists[1] = ans
    
    ans = 0
            
    for i in range(N):
        X = a[i] - 1
        tmp = 0
        for k in range(N):
            x = a[k] + 1
            y = a[k] - 1
            z = a[k]
            if X == x or X == y or X == z:
                tmp += 1
        if tmp >= ans:
            ans = tmp
            lists[2] = ans

    print(max(lists))


if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
def solve():

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

    m = max(a) 
   # print("max:" + str(m))

    ans = 0

    for i in range(m+1):
        tmp = 0
        for k in range(N):
            x = a[k] + 1
            y = a[k] - 1
            z = a[k]
            if i == x or i == y or i == z:
                tmp += 1
        if tmp >= ans:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
ans=0
for i in range(min(A)-1,max(A)+2):
    x=0
    for a in A:
        if a-1==i or a==i or a+1==i:
            x+=1
    ans=max(ans,x)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
B=[]
C=[]
for i in range(N):
    B.append(A[i]-1)
for i in range(N):
    C.append(A[i]+1)
D=[]
D=A+B+C
mx=0
for i in D:
    cnt=0
    for j in range(N):
        if i==A[j]:
            cnt+=1
        elif i==B[j]:
            cnt+=1
        elif i==C[j]:
            cnt+=1
    mx=max(mx,cnt)
print(mx)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
B=[]
C=[]
for i in range(N):
    B.append(A[i]-1)
for i in range(N):
    C.append(A[i]+1)
mx=0
for i in range(max(C)+1):
    cnt=0
    for j in range(N):
        if i==A[j]:
            cnt+=1
        elif i==B[j]:
            cnt+=1
        elif i==C[j]:
            cnt+=1
    mx=max(mx,cnt)
print(mx)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
*A,=map(int,input().split())
S=[sum(map(lambda x : abs(x-a) if abs(x-a)==1 else 0,A)) for a in A]
print(max(S)+1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int, input().strip().split()))
m=max(a)
n=min(a)
b=[]
for i in range(n,m+1):
    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,=map(int,input().split())
S=[list(map(lambda x : abs(x-a),A)) for a in A]
print(max(s.count(1) for s in S)+1)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

max_a=max(a)
min_a=min(a)
a0=a.count(min_a)
a1=a.count(min_a+1)
ans=1
for i in range(min_a+1,max_a):
    a2=a.count(i+1)
    ans=max(ans,(a0+a1+a2))
    a0=a1
    a1=a2
    if i ==max_a-1:
        print(ans)
        sys.exit()

print(N)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
now = A[0]
start_idx = 0
while now <= A[-1] + 1:
    tmp_max = 0
    flag = True
    for i in range(start_idx, N):
        if flag and now - 1 == A[i]:
            flag = False
            start_idx = i
        if now - 1 <= A[i] <= now + 1:
            tmp_max += 1
    ans = max(tmp_max, ans)
    now += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
maxA = max(A)
minA = min(A)
ans = -1
for i in range(minA,maxA+1):
    ans = max(ans, A.count(i-1) + A.count(i) + A.count(i+1))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = input()
a = list(map(int, input().split()))
b = set(a)
c = sorted(list(b))
M = max(a)
l = list()

ans = 1

if M <= 1:
  print(len(a))

else:
  for i in c:
    if i - 1 in c:
      if z <= a.count(i - 2):
        continue

    x = a.count(i - 1)
    y = a.count(i)
    z = a.count(i + 1)
    if x + y + z > ans:
      ans = x + y + z

    x = y
    y = z
    z = a.count(i + 2)
  
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = input()
a = list(map(int, input().split()))
b = set(a)
M = max(a)
l = list()

ans = 1

if M <= 1:
  print(len(a))

else:
  for i in b:
    x = a.count(i - 1)
    y = a.count(i)
    z = a.count(i + 1)
    if x + y + z > ans:
      ans = x + y + z
      
    x = y
    y = z
    z = a.count(i + 2)
  
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = input()
a = list(map(int, input().split()))
b = set(a)
M = max(a)
l = list()

if M <= 1:
  print(len(a))

else:
  for i in b:
    x = a.count(i - 1)
    y = a.count(i)
    z = a.count(i + 1)
    l.append(x + y + z)
    x = y
    y = z
    z = a.count(i + 2)
  
  print(max(l))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
counter=0
for i in range(a[0]-1,a[n-1]+2):
    sum=a.count(i-1)+a.count(i)+a.count(i+1)
    if sum>counter:
        counter=sum

print(counter)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
A = [int(T) for T in input().split()]
Num = [0]*(max(A)-min(A)+3)
for T in range(0,N):
    Num[A[T]-min(A)+1] += 1
MAX = 0
for T in range(0,max(A)-min(A)+1):
    if MAX<sum(Num[T:T+3]):
        MAX = sum(Num[T:T+3])
print(MAX)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
l = [0]*n
max = 0

for j in range(n):
	L = [a[j] for i in range(n) if abs(a[i] - a[j]) <= 1]
	if max < len(L):
		max = len(L)
print(max)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
A_1 = list(map(lambda x: x-1, A))
A_2 = list(map(lambda x: x+1, A))

ans = 0
for x in set(A):
    cnt = A.count(x) + A_1.count(x) + A_2.count(x)
    ans = max(cnt, ans)
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for x in set(A):
    tmp = [a for a in A if x-1 <= a <= x+1]
    ans = max(ans, len(tmp))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
def main():
  input = sys.stdin.readline
  maxa=0
  N=int(input())
  L=list(map(int,input().split()))
  L=sorted(L)
  R=tuple(set(L))
  for i in range(len(R)):
    s=L.count(R[i])+L.count(R[i]+1)+L.count(R[i]-1)
    maxa=max(maxa,s)
  print(maxa)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
maxa=0
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
R=list(set(L))
for i in range(len(R)):
  s=L.count(R[i])+L.count(R[i]+1)+L.count(R[i]-1)
  maxa=max(maxa,s)
print(maxa)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(min(l), max(l)+1):
    ans = max(l.count(i-1) + l.count(i) + l.count(i+1), ans)

print(ans)

Submission status: Time Limit Exceeded

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

M = len(range(min(A)-1,max(A)+2))
lst = [0]*M

for i in range(M):
    X = min(A)-1+i
    lst[i] = A.count(X-1) + A.count(X) + A.count(X+1)
    if X == N:
        break

print(max(lst))

Submission status: Time Limit Exceeded

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

M = len(range(min(A)-1,max(A)+2))
lst = [0]*M

for i in range(M):
    X = min(A)-1+i
    lst[i] = A.count(X-1) + A.count(X) + A.count(X+1)

print(max(lst))

Submission status: Time Limit Exceeded

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

M = len(range(min(A)-1,max(A)+2))
lst = [0]*M

for i in range(M):
    X = [min(A)-1+i]*N
    for j in range(N):
        if -1 <= X[j]-A[j] <= 1:
            lst[i] += 1

print(max(lst))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
a = list(map(int,input().split()))
cnt = []
a_plus1 = copy.copy(a)
a_minus1 = copy.copy(a)
for x in range(n):
    a_plus1[x] += 1
for y in range(n):
    a_minus1[y] -= 1
a_total = a + a_plus1 + a_minus1
a_el = list(set(a))
for i in range(len(a_el)):
    cnt.append(a_total.count(a_el[i]))
print(max(cnt))

Submission status: Time Limit Exceeded

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

out = 0

for i in set(a):
    out = max(out, a.count(i)+a.count(i-1)+a.count(i+1))

print(out)

Submission status: Time Limit Exceeded

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

out = 0

for i in set(a):
    cnt = 0
    for j in a:
        if j == i or j-1 == i or j+1 == i:
            cnt += 1
    out = max(out, cnt)

print(out)

Submission status: Time Limit Exceeded

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

out = 0

for i in range(max(a)+1):
    cnt = 0
    for j in a:
        if j == i or j-1 == i or j+1 == i:
            cnt += 1
    out = max(out, cnt)

print(out)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

a_processed = []

for i in a:
    a_processed[n:n] = [i-1, i, i+1]

print(a_processed.count(collections.Counter(a_processed).most_common()[0][0]))

Submission status: Time Limit Exceeded

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

mmax = max(a)
mmin = min(a)
mcount = 0
for i in range(mmin, mmax + 1):
    count = 0
    count += a.count(i)
    count += a.count(i + 1)
    count += a.count(i - 1)
    if mcount < count:
        mcount = count

print(mcount)

Submission status: Time Limit Exceeded

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

ans = 0
for n in a:
    ans = max(a.count(n-1) + a.count(n) + a.count(n+1), ans)

print(ans)

Submission status: Time Limit Exceeded

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

a.sort()

ans = 0
for n in a:
    ans = max(a.count(n) + a.count(n+1) + a.count(n+2), ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
sa = sorted(a)
r, ans = 0, 0
for l in range(n):
    cnt = 1
    r = l + 1
    while r < n and abs(sa[r] - sa[l]) <= 2:
        cnt += 1
        r += 1

    ans = max(ans, cnt)
    if l == r:
        r += 1

print(ans)

Submission status: Time Limit Exceeded

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


cnt_list = []
minn = min(a)
maxx= max(a)

for x in range(minn - 1, maxx + 2):
    cnt = 0
    for i in range(n):
        if a[i] == x or a[i] + 1 == x or a[i] - 1 == x:
            cnt += 1
    cnt_list.append(cnt)

print(max(cnt_list))

Submission status: Time Limit Exceeded

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

if n == 1:
  print(1)
else:
  ans = a.count(0) + a.count(1)
  for x in range(1, max(a)):
    res = a.count(x) + a.count(x+1) + a.count(x-1)
    ans = max(ans, res)
    
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
ans = 0
for v in range(min(A), max(A) + 1):
    count = A.count(v - 1) + A.count(v) + A.count(v + 1)
    if ans < count:
        ans = count
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
ans = 0
for v in range(min(A), max(A) + 1):
    ans = max(A.count(v - 1) + A.count(v) + A.count(v + 1), ans)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
check = set(A + [a - 1 for a in A] + [a + 1 for a in A])
ans = 0
for v in check:
    ans = max(A.count(v - 1) + A.count(v) + A.count(v + 1), ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
ans = 0
for v in range(min(A), max(A) + 1):
    ans = max(A.count(v - 1) + A.count(v) + A.count(v + 1), ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
ans = 0
for v in range(min(A), max(A) + 1):
    count = 0
    for a in A:
        if v - 1 <= a <= v + 1:
            count += 1
    ans = max(count, ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
check = set(A + [a - 1 for a in A] + [a + 1 for a in A])
ans = 0
for v in check:
    count = 0
    for a in A:
        if v - 1 <= a <= v + 1:
            count += 1
    ans = max(count, ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
ans = 0
for x in range(min(A), max(A)+1):
    ans = max(A.count(x - 1) + A.count(x) + A.count(x + 1), ans)
print(ans)

Submission status: Time Limit Exceeded

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

l=sorted(a)

ans=1

for i in range(N):
    t=l[i]
    _ans=0
    for j in range (N-i):
        c=l[i+j]
        if c-t<=2:
            pass
        else:
            _ans=j
            break
    if _ans>ans:
        ans=_ans
    else:
        pass
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

r=[]

for _ in a:
    l,m,h=_-1,_,_+1
    _r=[l,m,h]
    r.append(_r)
arr=np.array(r)

ans=0
for i in range (max(a)+2):
    _ans=np.sum(np.count_nonzero(arr==i,axis=1))
    if _ans>ans:
        ans=_ans
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=input()
a=input()
a=a.split(" ")
a=sorted(a)

ans=0

for i in range(len(a)):
    count=0
    x=int(a[i])+1
    y=int(a[i])-1
    z=a[i]
    #print(str(x),str(y),z)
    for j in a:
        if j==str(x) or j==str(y) or j==z:
            count=count+1
    if count>ans:
        ans=count
print(ans)

Submission status: Time Limit Exceeded

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

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

ans=[]

for i in range(min(a), max(a)+1):
  ans.append(a.count(i))

print(max(ans))

Submission status: Time Limit Exceeded

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

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

ans=0

for i in range(min(a), max(a)+1):
  ans = max(ans, a.count(i))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
a = list(map(int, input().split()))
al = [0]*x
for i in range(x):
    for j in range(x):
        abst = abs(i - a[j])
        if abst == 1 or abst == 0:
            al[i] += 1

print(max(1, max(al)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from scipy import stats
n = int(input())
a = np.array([int(i) for i in input().split()])
x = np.hstack([a - 1, a, a + 1])
r = stats.mode(x)
print(int(r[1]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


N = int(input())
A = np.array(list(map(int, input().split())))
ans = []
for x in range(10 ** 5 + 1):
    c = np.sum((A >= (x - 1)) & (A <= (x + 1)))
    ans.append(c)

print(max(ans))

Submission status: Time Limit Exceeded

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

aa=[]

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

ans=0
for i in aa:
    if ans < aa.count(i):
        ans = aa.count(i)
print(ans)

Submission status: Time Limit Exceeded

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

aa=[]

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

ans=0
for i in range(min(aa),max(aa)+1):
    if ans < aa.count(i):
        ans = aa.count(i)
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):
    X = a[i]
    res = 1
    j = i+1
    while (j < N and a[j] - X <= 1):
        j += 1
        res += 1
    j = i-1
    while (j >= 0 and X - a[j] <= 1):
        j -= 1
        res += 1
    ans = max(res, ans)

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
a = list(map(int, input().split()))
s =set(a)
ans = []

for x in s:
    x -= 1
    for _ in range(2):
        l = []
        x += 1
        for i in a:
            if i == x - 1:
                l.append(i+1)
            elif i == x:
                l.append(i)
            elif i == x + 1:
                l.append(i-1)
                
        c = collections.Counter(l).most_common(1)
        ans.append(c[0][1])

print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=1
for i in range(n-1):
    k=1
    while a[i]+2>=a[i+k]:
        k+=1
        if i+k>=n:
            break
    ans=max(ans,k)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls = list(map(int,input().split()))
a = min(ls)
b = max(ls)
c = len(ls)
s = 0
def sub(p,q):
    return p-q
ans = []
aaa = -float("inf")
for i in range(a,b+1):
    new = [i]*(c)
    ans = map(sub,ls,new)
    ans = list(map(str,ans))
    s = ans.count("-1") + ans.count("1") + ans.count("0")
    aaa = max(aaa,s)
print(aaa)

Submission status: Time Limit Exceeded

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

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

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

## Logic

X = 0

tmp1 = A.count(0)
tmp2 = A.count(1)

for i in range(2,100000):
    tmp = tmp1+tmp2+A.count(i)
    if tmp > X:
        X = tmp
    else:
        tmp1 = A.count(i)
print(X)

Submission status: Time Limit Exceeded

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

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

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

## Logic

X = 0

for i in range(0,99999):
    X = max(X, A.count(i-1)+A.count(i)+A.count(i+1))
print(X)

Submission status: Time Limit Exceeded

Solution code:
def main():
  n = int(input())
  a = tuple(map(int ,input().split()))
  ans = 0
  for x in range(min(a)-1, max(a)+2):
    cnt = 0
    for i in range(n):
      if abs(x-a[i]) <= 1:
        cnt += 1
    ans = max(ans, cnt)

  print(ans)
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  n = int(input())
  a = list(map(int ,input().split()))
  ans = 0
  for x in range(min(a)-1, max(a)+2):
    cnt = 0
    for i in range(n):
      if abs(x-a[i]) <= 1:
        cnt += 1
    ans = max(ans, cnt)

  print(ans)
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter as C

n  =  int(input())
a= list(input().split())
al = list([int(i) for i in a])
aset = set([int(i) for i in a])

cnt=0

#print(C(al)[0])
for i in aset:
  #print(i)
  #print(al.count(i-1),al.count(i),al.count(i+1))
  if cnt < C(al)[i-1] + C(al)[i] + C(al)[i+1]:
    cnt = C(al)[i-1] + C(al)[i] + C(al)[i+1]

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n  =  int(input())
a= list(input().split())
al = list([int(i) for i in a])
aset = set([int(i) for i in a])

cnt=0

for i in aset:
  #print(i)
  #print(al.count(i-1),al.count(i),al.count(i+1))
  if cnt < al.count(i-1) + al.count(i) + al.count(i+1):
    cnt = al.count(i-1) + al.count(i) + al.count(i+1)
print(cnt)

Submission status: Time Limit Exceeded

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

#for i in a:
#i=0
b=[0]*n
r=0
#while i<=n:
for i in range(n):
    r=a[i]
    A=a.count(a[i]+1)
    M=a.count(a[i])
    C=a.count(a[i]-1)

    b[i]=A+M+C

print(max(b))

Submission status: Time Limit Exceeded

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

#for i in a:
#i=0
b=[0]*n
r=0
#while i<=n:
for i in range(n):
    r=a[i]
    A=a.count(a[i]+1)
    M=a.count(a[i])
    C=a.count(a[i]-1)

    b[i]=A+M+C

print(max(b))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
x=1
while x<=max(a)+1:
  ans=max(ans,a.count(x-1)+a.count(x)+a.count(x+1))
  x=x+1
print(ans)

Submission status: Time Limit Exceeded

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

for x in range(min(li), max(li)+1):
    if x == min(li):
        a = li.count(x-1)
        b = li.count(x)
        c = li.count(x+1)

    else:
        a = b
        b = c
        c = li.count(x+1)
    
    y = a+b+c
    if y > ans:
        ans = y
    
print(ans)

Submission status: Time Limit Exceeded

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

for x in range(min(li), max(li)+1):
    y = li.count(x-1) + li.count(x) + li.count(x+1)
    if y > ans:
        ans = y
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
A_uniq = sorted(set(A))

result = 0
for n in A_uniq:
    tmp = 0
    tmp += A.count(n-1)
    tmp += A.count(n)
    tmp += A.count(n+1)
    if tmp > result:
        result = tmp

print(result)

Submission status: Time Limit Exceeded

Solution code:
def most_frequent(List): 
    return max(set(List), key = List.count) 

N = int(input())
tmp = []

a = [int(N) for N in input().split()]
for i in range(0,N):
  tmp.append(a[i]%1000-1)
  tmp.append(a[i]%1000)
  tmp.append(a[i]%1000+1)

print(tmp.count(most_frequent(tmp)))

Submission status: Time Limit Exceeded

Solution code:
def most_frequent(List): 
    return max(set(List), key = List.count) 

N = int(input())
tmp = []

a = [int(N) for N in input().split()]
for i in range(0,N):
  tmp.append(a[i]-1)
  tmp.append(a[i])
  tmp.append(a[i]+1)

print(tmp.count(most_frequent(tmp)))