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 = 0
for i in A:
    a = A.count(i-1)+A.count(i)+A.count(i+1)
    cnt = max(cnt,a)
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
nums = set(a_list)
r_list = [0]*(10**5+2)
for n in nums:
	count = a_list.count(n)
	r_list[n] += count
	r_list[n+1] += count
	if n > 0:
		r_list[n-1] += count
print(max(r_list))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
nums = set(a_list)
r_list = []
for n in nums:
	count = a_list.count(n) + a_list.count(n-1) + a_list.count(n+1)
	r_list.append(count)
print(max(r_list))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
nums = list(set(a_list))
nums.sort()
if len(nums) > 2:
	nums.pop(0)
	nums.pop(-1)
r_list = []
for n in nums:
	count = a_list.count(n) + a_list.count(n-1) + a_list.count(n+1)
	r_list.append(count)
print(max(r_list))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
nums = list(set(a_list))
r_list = []
for n in nums:
	count = a_list.count(n) + a_list.count(n-1) + a_list.count(n+1)
	r_list.append(count)
print(max(r_list))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
a_list.sort()
nums = list(set(a_list))
r_list = []
for n in nums:
	count = a_list.count(n) + a_list.count(n-1) + a_list.count(n+1)
	r_list.append(count)
print(max(r_list))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
st = min(a)
ed = max(a)
count = a.count(st) + a.count(st+1) + a.count(st+2)
mx = count
for i in range(3,ed-st+1):
  count = count + a.count(st+i) -a.count(st+i-3)
  if count > mx:
    mx = count
print(mx)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
L = []
num = 0
for X in range(min(a)-1, max(a)+2):
  L.append(a.count(X))
for i in range(len(L)-2):
  n = L[i]+L[i+1]+L[i+2]
  if n > num:
    num = n
print(num)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
num = 0
for X in range(min(a)-1, max(a)+2):
  n = a.count(X-1) + a.count(X) + a.count(X+1)
  if n > num:
    num = n
print(num)

Submission status: Time Limit Exceeded

Solution code:
#ABC072-C
import collections
import itertools

n = int(input())
a = list(map(int,input().split()))
 
cnt = [0] * 100000000


for i in a:
    cnt[i] += 1
    cnt[i+1] += 1
    cnt[i+2] += 1
    
    

    
        
print(max(cnt))

Submission status: Time Limit Exceeded

Solution code:
#ABC072-C
import collections
import itertools

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

cnt = 0
a.sort()

for i in range(len(a)):
    tmp = a.count(a[i]-1) + a.count(a[i]) + a.count(a[i]+1)
    if tmp > cnt:
        cnt = tmp
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#ABC072-C
import collections
import itertools

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

cnt = 0

for i in range(len(a)):
    tmp = a.count(a[i]-1) + a.count(a[i]) + a.count(a[i]+1)
    if tmp > cnt:
        cnt = tmp
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#ABC072-C
import collections
import itertools

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

cnt = 0

for i in a:
    tmp = a.count(i-1) + a.count(i) + a.count(i+1)
    if tmp > cnt:
        cnt = tmp
        
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 0
def count(i):
    res = 0
    for x in a[i:]:
        if x - a[i] <= 1:
            res += 1
    for y in a[:i]:
        if a[i] - y <= 1:
            res += 1
    return res

for i in range(n):
    ans = max(ans,count(i))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# ABC072C(

n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
n = range(len(a))
b = set(a)
Max = 0
for i in b:
    count = 0
    for j in n:
        if a[j] >= i + 2:
            break
        elif i - 1 <= a[j] <= i + 1:
            count += 1
    Max = max(Max, count)
print(Max)

Submission status: Time Limit Exceeded

Solution code:
import sys

def input():
    return sys.stdin.readline().strip()

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

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def input():
    return sys.stdin.readline().strip()

def main():
    N = int(input())
    a = list(map(int,input().split()))
    cnt = 0

    for i in range(1,10**5):
        cnt = max(a.count(i-1)+a.count(i)+a.count(i+1),cnt)
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def input():
    return sys.stdin.readline().strip()

def main():
    N = int(input())
    a = list(map(int,input().split()))
    cnt = 0

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

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def input():
    return sys.stdin.readline().strip()

def main():
    N = int(input())
    a = sorted(list(map(int,input().split())))
    cnt = 0

    for i in range(a[0],a[N-1]+1):
        cnt = max(a.count(i-1)+a.count(i)+a.count(i+1),cnt)
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

    for i in range(a[0],a[N-1]+1):
        cnt = max(a.count(i-1)+a.count(i)+a.count(i+1),cnt)
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

for i in range(a[0],a[N-1]+1):
    cnt = max(a.count(i-1)+a.count(i)+a.count(i+1),cnt)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
r=a[:]
r.extend([i-1 for i in a])
r.extend([i+1 for i in a])
for i in set(r):
  x=0
  for ai in a:
    if ai==i or ai-1==i or ai+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()))
ans=0
r=a[:]
r.extend([i-1 for i in a])
r.extend([i+1 for i in a])

for i in r:
  x=0
  for ai in a:
    if ai==i or ai-1==i or ai+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()))
ans=0
for i in range(max(a)+1):
  x=0
  for ai in a:
    if ai==i or ai-1==i or ai+1==i:
      x+=1
  ans=max(ans,x)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
g=list(map(int,input().split()))
l=[0]*(max(g)+2)
for i in g:
  for j in range(max(0,i-1),min(i+2,max(g)+1)):
    l[j]+=1
print(max(l))

Submission status: Time Limit Exceeded

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

max_count = 0

for X in range(1, 10**5):
    count = 0
    for i in A:
        if X-1 <= i <= X+1:
            count += 1
        if count > max_count:
            max_count = count

print(max_count)

Submission status: Time Limit Exceeded

Solution code:

import sys
import collections
import numpy as np

readline = sys.stdin.readline

def main():
    N = int(input())
    A1 = np.array(list(map(int, readline().split())))

    A0 = A1 - 1; A2 = A1 + 1

    ans = 0
    for X in range(max(A2)):
        tmp = 0
        tmp += np.count_nonzero(A0 == X)
        tmp += np.count_nonzero(A1 == X)
        tmp += np.count_nonzero(A2 == X)
        ans = max(ans, tmp)

    print(ans)  


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cnt = 0

for X in range(min(A),max(A)+1):
    transient = A.count(X-1) + A.count(X) + A.count(X+1)
    if transient > cnt:
        cnt = transient

print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0
X=[]
for n in A:
    X.append(n)
    X.append(n-1)
    X.append(n+1)

Y = set(X)

y = list(Y)

for x in y:
    transient = 0
    for a in A:
        if -1 <= a - x <= 1:
            transient += 1
    else:
        if transient > cnt:
            cnt = transient

print(cnt)

Submission status: Time Limit Exceeded

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

cnt = 0

for X in range(min(A),max(A)+1):
    transient = 0
    for a in A:
        if -1 <= a -X <= 1:
            transient += 1
    else:
        if transient > cnt:
            cnt = transient

print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(min(li), max(li)+1):
  x = 0
  for j in li:
    if i-1 <= j <= i+1:
      x += 1
  if x > ans:
    ans = x
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    number = sorted(set(A))
    c = defaultdict(int)
    for k in number:
        c[k] = A.count(k-1) + A.count(k) + A.count(k+1)
    ma = 0
    for k, v in c.items():
        if v > ma:
            ma = v
    print(ma)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = Counter(a)
ans, count = 1, 0
for k in b.keys():
    for l in b.keys():
        if 0<=(k-l)<=2:
            count += b[l]
    ans = max(ans, count)
    count = 0
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

temp = {}
for i in a_:
    temp[i] = a.count(i)

temp3 = []
for i in a_:
    if i in temp:
        a1 = temp[i]
    else :
        a1 = 0

    if i+1 in temp:
        a2 = temp[i+1]
    else :
        a2 = 0

    if i-1 in temp:
        a3 = temp[i-1]
    else :
        a3 = 0
        
    temp3.append(a1+a2+a3)
 
print(max(temp3))

Submission status: Time Limit Exceeded

Solution code:

import sys  
import numpy as np
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
 
a_ = list(set(a))
temp = []
for i in a_:
    temp.append(a.count(i+1) + a.count(i) + a.count(i-1))
 
print(max(temp))

Submission status: Time Limit Exceeded

Solution code:
import sys  
import numpy as np

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

a_ = list(set(a))
temp = []
for i in a_:
    temp.append(a.count(i+1) + a.count(i) + a.count(i-1))

print(max(temp))

Submission status: Time Limit Exceeded

Solution code:
import sys  
import numpy as np

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

a_ = list(set(a))
temp = []
for i in a:
    temp.append(a.count(i+1) + a.count(i) + a.count(i-1))

print(max(temp))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = input()
a = np.array(list(map(int,input().strip().split())))
b = [[a_-1,a_,a_+1] for a_ in a]

flat = [flatten for inner in b for flatten in inner]
all_type = set(flat)

counter = [0]*len(all_type)

for i,n in enumerate(all_type):
    counter[i] = flat.count(n)

print(max(counter))

Submission status: Time Limit Exceeded

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""
# 最大公約数 と 最小公倍数
"""def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def lcm(a,b):
  g = gcd(a,b)
  return (a * b) // g"""

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7

def main():
  n = int(input())
  LIST = readInts()
  LIST = sorted(LIST)
  ans = 1
  pr_ = LIST[0]
  for i in range(1,n):
    cnt = 1
    for j in range(i,n):
      if abs(pr_ - LIST[j]) <= 2:
        cnt += 1
      else:
        ans = max(ans,cnt)
    pr_ = LIST[i]
  print(ans)
  
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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

m = 0
for i in range(1, 10**5):
    if m < l.count(i-1)+l.count(i)+l.count(i+1):
        m = l.count(i-1)+l.count(i)+l.count(i+1)
        
print(m)

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):
    tmp = 0
    for i in range(N):
        if a[i]+1 == x or a[i] == x or a[i]-1 == x:
            tmp += 1
    
    ans = max(ans,tmp)
    
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):
    tmp = 0
    tmp += a.count(x)
    tmp += a.count(x-1)
    tmp += a.count(x+1)
    
    ans = max(ans,tmp)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = np.array([[int(i) + 1, int(i), int(i)-1] for i in input().split()])

maxs = 0
for i in range(a.min(), a.max() + 1):
  maxs = max(maxs, (a==i).sum())

print(maxs)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
ap = [i+1 for i in a]
am = [i-1 for i in a]
a = np.array([ap, a, am])

maxs = 0
for i in range(a.min(), a.max() + 1):
  maxs = max(maxs, (a==i).sum())

print(maxs)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
a_m1 = list(map(lambda x: x-1, a))
a_p1 = list(map(lambda x:x+1, a))

ans = 0
for i in range(N):
  n = a[i]
  A = a.count(n) + a_m1.count(n) + a_p1.count(n)
  if ans < A:
    ans = A
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
ans=int(0)
for i in range(0,100100):
    co=int(0)
    for j in range(n):
        if i-1<=A[j]<=i+1:
            co+=1
        if ans<=co:
            ans=co
print(ans)

Submission status: Time Limit Exceeded

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

max_n = max(max(A),1)
cnt = [0]*max_n
for i in range(max_n):
    for a in A:
        if abs(a-i)<=1:
            cnt[i] += 1
print(max(cnt))

Submission status: Time Limit Exceeded

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


Ap = list(map(lambda x: x+1, A))
Am = list(map(lambda x: x-1, A))

ans = 0
for a in set(A):
    tmp = A.count(a) + Am.count(a) + Ap.count(a)
    ans = max(ans, tmp)

print(ans)

Submission status: Time Limit Exceeded

Solution code:

def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in s_li:
        v_1 = s_li.count(v - 1)
        v_0 = s_li.count(v) + s_li.count(v + 1)
        v_2 = s_li.count(v + 2)
        t_c = v_1 + v_0
        t_c2 = v_2 + v_0

        if t_c > count:
            count = t_c
        if t_c2 > count:
            count = t_c2
        if count > len(s_li):
            break
        s_li = s_li[s_li.index(v):]
    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in s_li:
        t_c = s_li.count(v - 1) + s_li.count(v) + s_li.count(v + 1)
        t_c2 = s_li.count(v) + s_li.count(v + 1) + s_li.count(v + 2)

        if t_c > count:
            count = t_c
        if t_c2 > count:
            count = t_c2
        if count > len(s_li):
            break
        s_li = s_li[s_li.index(v):]
    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in s_li:
        t_c = s_li.count(v - 1) + s_li.count(v) + s_li.count(v + 1)
        t_c2 = s_li.count(v) + s_li.count(v + 1) + s_li.count(v + 2)

        if t_c > count:
            count = t_c
        if t_c2 > count:
            count = t_c2
        if count > len(s_li):
            break
    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    c1 = 0
    b_num = s_li[0]
    for v in range(s_li[0] - 1, s_li[-1] + 1, 2):
        t_c = 0
        c1 = s_li.count(v - 1)
        c2 = s_li.count(v)
        c3 = s_li.count(v + 1)
        c4 = s_li.count(v + 2)

        t_c = c1 + c2 + c3
        t_c2 = c2 + c3 + c4
        if t_c > count:
            count = t_c
        if t_c2 > count:
            count = t_c2
        if c1 != 0:
            s_li = s_li[s_li.index(v - 1):]
        if count > len(s_li):
            break
        if t_c == 0:
            v = s_li[0]
    print(count)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    c1 = 0
    for v in range(s_li[0] - 1, s_li[-1] + 1, 2):
        t_c = 0
        c1 = s_li.count(v - 1)
        c2 = s_li.count(v)
        c3 = s_li.count(v + 1)
        c4 = s_li.count(v + 2)

        t_c = c1 + c2 + c3
        t_c2 = c2 + c3 + c4
        if t_c > count:
            count = t_c
        if t_c2 > count:
            count = t_c2
        if c1 != 0:
            s_li = s_li[s_li.index(v - 1):]
        if count > len(s_li):
            break
    print(count)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    c1 = 0
    for v in range(s_li[0] - 1, s_li[-1] + 1):
        t_c = 0
        c1 = s_li.count(v - 1)
        c2 = s_li.count(v)
        c3 = s_li.count(v + 1)

        t_c = c1 + c2 + c3
        if t_c > count:
            count = t_c
        if c1 != 0:
            s_li = s_li[s_li.index(v - 1):]
        if count > len(s_li):
            break
    print(count)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    c1 = 0
    for v in range(s_li[0] - 1, s_li[-1] + 1):
        t_c = 0
        c1 = s_li.count(v - 1)
        c2 = s_li.count(v)
        c3 = s_li.count(v + 1)

        t_c = c1 + c2 + c3
        if t_c > count:
            count = t_c
        if c1 != 0:
            s_li = s_li[s_li.index(v - 1):]
    print(count)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    ind = 0
    for v in range(s_li[0] - 1, s_li[-1] + 1):
        t_c = 0
        t_c += s_li.count(v - 1)
        t_c += s_li.count(v)
        t_c += s_li.count(v + 1)
        if t_c > count:
            count = t_c
    print(count)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:


def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in range(s_li[0] - 1, s_li[-1] + 1):
        t_c = 0
        for vv in s_li:
            if v == vv or v - 1 == vv or v + 1 == vv:
                t_c += 1
            if vv > v + 2:
                break
        if t_c > count:
            count = t_c

    print(count)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in range(s_li[0] - 1, s_li[-1] + 1):
        t_c = 0
        for vv in s_li:
            if v == vv or v - 1 == vv or v + 1 == vv:
                t_c += 1
            if vv > v + 2:
                break
        if t_c > count:
            count = t_c

    print(count)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in range(s_li[0] - 1, s_li[-1] + 1):
        t_c = 0
        for vv in s_li:
            if v == vv or v - 1 == vv or v + 1 == vv:
                t_c += 1
            if vv + 2 > v:
                continue
        if t_c > count:
            count = t_c

    print(count)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in range(s_li[0] - 1, s_li[-1] + 1):
        t_c = 0
        for vv in s_li:
            if v == vv or v - 1 == vv or v + 1 == vv:
                t_c += 1
        if t_c > count:
            count = t_c

    print(count)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N=int(input())
    A=list(map(int,input().split()))
    cnt=[0]*N
    for i in range(N):
        for j in range(N):
            if abs(A[i]-A[j])<=1:
                cnt[i]+=1
    print(max(cnt))




resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N=int(input())
    A=list(map(int,input().split()))
    cnt=[0]*N
    for i in range(N):
        for j in range(N):
            if abs(A[i]-A[j])<=1:
                cnt[i]+=1
    print(max(cnt))




resolve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = [0] * len(A)
C = [0] * len(A)
for i in range(len(A)):
  B[i] = A[i] + 1
  C[i] = A[i] - 1

t= 0
m = 0
for X in range(1 ,10 ** 5 + 1):
  t = A.count(X) + B.count(X) + C.count(X)
  m = max(m,t)
print(m)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int,input()
a=list(map(int,input().split()))
m=max(a)
ans=0
for i in range(m+2):
    pre=0
    for j in range(len(a)):
        if (a[j]-1<=i) and (i<=a[j]+1):
            pre+=1
        else:
            pre=pre
    ans=max(ans,pre)
    
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

b = set(a)
c = []
for i in b:
  x = a.count(i)
  c.append([i, x])

t = []
m = len(c)
for j in range(m):
  total = c[j][1]
  
  if c[j][0]-1 in b:
    total += c[j-1][1]
  
  if c[j][0]+1 in b:
    total += c[j+1][1]

  t.append(total)

print(max(t))

Submission status: Time Limit Exceeded

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

b = set(a)
c = []
for i in b:
  c.append([i, a.count(i)])

t = []
m = len(c)
for j in range(m):
  total = c[j][1]
  
  if c[j][0]-1 in b:
    total += c[j-1][1]
  
  if c[j][0]+1 in b:
    total += c[j+1][1]

  t.append(total)

print(max(t))

Submission status: Time Limit Exceeded

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

b = set(a)
c = []
for i in b:
  c.append([i, a.count(i)])

t = []
for j in range(len(c)):
  total = c[j][1]
  
  if c[j][0]-1 in b:
    total += c[j-1][1]
  
  if c[j][0]+1 in b:
    total += c[j+1][1]

  t.append(total)

print(max(t))

Submission status: Time Limit Exceeded

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

b = set(a)
c = []
for i in b:
  c.append([i, a.count(i)])

t = []
for j in range(len(c)):
  total = 0
  total += c[j][1]
  
  if c[j][0]-1 in b:
    total += c[j-1][1]
  
  if c[j][0]+1 in b:
    total += c[j+1][1]

  t.append(total)

print(max(t))

Submission status: Time Limit Exceeded

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

b = set(a)
c = []
for i in b:
  c.append([i, a.count(i)])

t = []
for j in range(len(c)):
  total = 0
  total += c[j][1]
  
  if c[j][0]-1 in a:
    total += c[j-1][1]
  
  if c[j][0]+1 in a:
    total += c[j+1][1]

  t.append(total)

print(max(t))

Submission status: Time Limit Exceeded

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

am = list(map(lambda x :x + 1, a))
ap = list(map(lambda x :x - 1, a))
a_all = a+am+ap

count = 0
for cur in range(min(a), max(a)+1):
    count = max(count, a_all.count(cur))

print(count)

Submission status: Time Limit Exceeded

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

count = 0
for cur in range(min(a), max(a)+1):
    t_count = 0
    for aa in a:
        if abs(cur - aa) <= 1:
            t_count += 1

    count = max(count, t_count)

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

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

t.sort()

if len(t) == 1:
    print(1)
    exit()

ans = 0

for i in range(n-1):  
    move = i+1
    memo = 1
    while t[i]+2 >= t[move]:
        memo += 1
        move += 1
        if move > n-1:
            break
    ans = max(memo, ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=0
for x in range(min(a)-1,max(a)+2):
    xp=a.count(x+1)
    xm=a.count(x-1)
    m=max(a.count(x)+xp+xm,m)
print(m)

Submission status: Time Limit Exceeded

Solution code:
import copy
n=int(input())
a=list(map(int,input().split()))
m=0
for x in range(min(a)-1,max(a)+2):
    xp=a.count(x+1)
    xm=a.count(x-1)
    m=max(a.count(x)+xp+xm,m)
print(m)

Submission status: Time Limit Exceeded

Solution code:
import copy
n=int(input())
a=list(map(int,input().split()))
tmp=copy.copy(a)
m=0
for i in range(min(a)-1,max(a)+1):
    for j in range(n):
        if tmp[j]<i:
            tmp[j]+=1
        elif tmp[j]>i:
            tmp[j]-=1
    m=max(tmp.count(i),m)
    tmp=copy.copy(a)
print(max(tmp.count(max(a)),m))

Submission status: Time Limit Exceeded

Solution code:
def main():
  n=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)
  a=tuple(a)
  count=0
  for i in A:
    x=a.count(i)+a.count(i+1)+a.count(i-1)
    count=x if x>count else count
  print(count)
if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  n=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=a.count(i)+a.count(i+1)+a.count(i-1)
    count=x if x>count else count
  print(count)
if __name__=='__main__':
  main()