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())
nums = list(map(int,input().split()))
nums.sort()

res = 1 if len(nums) == 1 else 0
for i in range(n):
	neo_nums = []
	target = nums[i]

	for num in nums[i:-1]:
		if num == target :
			neo_nums.append(num)
		elif num-1 == target :
			neo_nums.append(num)
		else :
			break
	
	for num in nums[:i]:
		if num == target :
			neo_nums.append(num)
		elif num+1 == target :
			neo_nums.append(num)
		else :
			break

	new = len(neo_nums)
	res = new if new > res else res
print(res)

Submission status: Time Limit Exceeded

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

res = 0
for i in range(n):
	neo_nums = []
	target = nums[i]
	for num in nums :
		if num == target :
			neo_nums.append(num)
		elif num+1 == target :
			neo_nums.append(num)
		elif num-1 == target :
			neo_nums.append(num)
	new = len(neo_nums)
	res = new if new > res else res
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def test():
    n = int(input())
    a = np.array([int(x) for x in input().split()])
    m = max(a)
    ans = 0
    for x in range(m+1):
        ans = max(ans,sum(a==x+1)+sum(a==x)+sum(a==x-1))
    print(ans)


if __name__ == "__main__":
    test()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(min(a),max(a)+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=list(map(int,input().split()))
b=list(set(a))
c=[]
for i in range(len(b)):
  count=0
  for j in range(n):
    if abs(b[i]-a[j])<=1:
      count+=1
  c.append(count)
print(max(c))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
l1 = [1] * N
a1 = [_ + 1 for _ in a]
a2 = [_ - 1 for _ in a]
lst = a + a1 + a2
set_lst = list(set(lst))
ans = 0

if len(lst) == len(set_lst):
    print(1)
else:
    for i in set_lst:
        tmp = lst.count(i)
        if tmp > ans:
            ans = tmp
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
l1 = [1] * N
a1 = [_ + 1 for _ in a]
a2 = [_ - 1 for _ in a]
lst = a + a1 + a2
lst = list(lst)
set_lst = list(set(lst))
ans = 0
for i in set_lst:
    tmp = lst.count(i)
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*-coding: utf-8 -*-
import numpy as np
def main():
    N = int(input())
    a = np.array(list(map(int, input().split())))
    a1 = a + 1
    a2 = a - 1
    lst = np.concatenate([a, a1, a2], 0)
    lst = list(lst)
    set_lst = list(set(lst))
    ans = 0
    for i in set_lst:
        tmp = lst.count(i)
        if tmp > ans:
            ans = tmp
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
a = np.array(list(map(int, input().split())))

a1 = a + 1
a2 = a - 1

lst = np.concatenate([a, a1, a2], 0)
lst = list(lst)

set_lst = list(set(lst))
ans = 0
for i in set_lst:
    tmp = lst.count(i)
    if tmp > ans:
        ans = tmp

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cnt = 0
for i in aset:
    tmp = a.count(i) + a.count(i + 1) + a.count(i - 1)
    if cnt <= tmp:
        cnt = tmp

print(cnt)

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

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

max_a = max(a)
min_a = min(a)
ruiseki = []

if N == 1:
    print(1)
    exit()

for i in range(min_a,max_a + 1):
    tmp = a.count(i)
    ruiseki.append(tmp)

b = []
l = len(ruiseki)

if l == 1:
    print(ruiseki[0])
    exit()

for j,v in enumerate(ruiseki):
    if j == 0:
        tmp = ruiseki[0] + ruiseki[1]
        b.append(tmp)
    elif j == l - 1:
        tmp = ruiseki[j] + ruiseki[j-1]
        b.append(tmp)
    else:
        tmp = ruiseki[j-1]+ ruiseki[j] + ruiseki[j+1]  
        b.append(tmp)

print(max(b))

Submission status: Time Limit Exceeded

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

sarr = []

tc = 0
sc = 0

for i in range(n):
    x = arr[i]

    for k in range(n):
        if abs(arr[k] - x) <= 1:
            sc += 1

    if tc < sc:
        tc = sc

    sc = 0

print(tc)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc072/tasks/arc082_a

from functools import reduce
n = int(input())
l = list(map(int, input().split()))

def get_process(arg):
    def process(accumulator, currentValue):
        if currentValue == arg or currentValue+1 == arg or currentValue-1 == arg:
            return accumulator + 1
        else:
            return accumulator
    return process

rl = [0 for _ in range(n)]
for i in range(n):
    for option in range(-1, 2):
        rl[i] = (reduce(get_process(l[i]+option), l, 0))

print(max(rl))

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc072/tasks/arc082_a

from functools import reduce
n = int(input())
l = list(map(int, input().split()))

def get_process(arg):
    def process(accumulator, currentValue):
        if currentValue == arg or currentValue+1 == arg or currentValue-1 == arg:
            return accumulator + 1
        else:
            return accumulator
    return process

def eachX(accumulator, currentValue):
    a = reduce(get_process(currentValue+1), l, 0)
    b = reduce(get_process(currentValue), l, 0)
    c = reduce(get_process(currentValue-1), l, 0)
    if accumulator < max(a, b, c):
        return max(a, b, c)
    else:
        return accumulator

print(reduce(eachX, l, 0))

Submission status: Time Limit Exceeded

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

k = []

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

max = 0
for i in range(N):
    cnt = k.count(a[i])
    if cnt > max:
        max = cnt
    
    cnt = k.count(a[i]-1)
    if cnt > max:
        max = cnt

    cnt = k.count(a[i]+1)
    if cnt > max:
        max = cnt

print(max)

Submission status: Time Limit Exceeded

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

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

maxcount = 1
for i in ary:
    if ary.count(i) > maxcount:
        maxcount = ary.count(i)

print(maxcount)

Submission status: Time Limit Exceeded

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

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

maxcount = 1
for i in range(10**5):
    if ary.count(i) > maxcount:
        maxcount = ary.count(i)

print(maxcount)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

a_unique = np.unique(a_s)

ans = 0
for i,a in enumerate(a_unique):
    val = np.sum(a_s==a)
    if (i>0):
        if (a_unique[i-1]+1==a):
            val += np.sum(a_s==a_unique[i-1])
            
    if (i<len(a_unique)-1):
        if (a_unique[i+1]-1==a):
            val += np.sum(a_s==a_unique[i+1])
    
    if val > ans:
        ans = val
        
#     if ans >= sum(a_counts[i:]):
#         break
        
print(ans)

Submission status: Time Limit Exceeded

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

a_unique = np.unique(a_s)
# a_counts = []
# for i,a in enumerate(a_unique):
#     a_counts.append(np.sum(a_s==a))
# a_counts = np.array(a_counts)

ans = 0
for i in range(len(a_unique)):
    val = np.sum(a_s==a_unique[i]) #a_counts[i]
    if (i>0):
        if (a_unique[i-1]+1==a_unique[i]):
            val += np.sum(a_s==a_unique[i-1]) #a_counts[i-1]
            
    if (i<len(a_unique)-1):
        if (a_unique[i+1]-1==a_unique[i]):
            val += np.sum(a_s==a_unique[i+1]) #a_counts[i+1]
    
    if val > ans:
        ans = val
        
#     if ans >= sum(a_counts[i:]):
#         break
        
print(ans)

Submission status: Time Limit Exceeded

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

a_unique = np.unique(a_s)
a_counts = []
for i,a in enumerate(a_unique):
    a_counts.append(np.sum(a_s==a))
a_counts = np.array(a_counts)

ans = 0
for i in range(len(a_unique)):
    val = a_counts[i]
    if i>0:
        if a_unique[i-1]+1==a_unique[i]:
            val += a_counts[i-1]
            
    if i<len(a_unique)-1:
        if a_unique[i+1]-1==a_unique[i]:
            val += a_counts[i+1]
            
    if val > ans:
        ans = val
        
    if ans >= sum(a_counts[i:]):
        break
        
print(ans)

Submission status: Time Limit Exceeded

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

a_unique = np.unique(a_s)
a_counts = []
for i,a in enumerate(a_unique):
    a_counts.append(np.sum(a_s==a))
a_counts = np.array(a_counts)

ans = 0
for i in range(len(a_unique)):
    val = a_counts[i]
    if i>0:
        if a_unique[i-1]+1==a_unique[i]:
            val += a_counts[i-1]
            
    if i<len(a_unique)-1:
        if a_unique[i+1]-1==a_unique[i]:
            val += a_counts[i+1]
            
    if val > ans:
        ans = val
        
    if ans > sum(a_counts[i:]):
        break
        
print(ans)

Submission status: Time Limit Exceeded

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

a_unique = np.unique(a_s)
a_counts = []
for i,a in enumerate(a_unique):
    a_counts.append(sum(a_s==a))

ans = 0
for i in range(len(a_unique)):
    val = a_counts[i]
    if i>0:
        if a_unique[i-1]+1==a_unique[i]:
            val += a_counts[i-1]
            
    if i<len(a_unique)-1:
        if a_unique[i+1]-1==a_unique[i]:
            val += a_counts[i+1]
            
    if val > ans:
        ans = val
        
    if ans > sum(a_counts[i:]):
        break
        
print(ans)

Submission status: Time Limit Exceeded

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

a_unique = np.unique(a_s)
a_counts = []
for i,a in enumerate(a_unique):
  a_counts.append(sum(a_s==a))

ans = 0
for i in range(len(a_unique)):
    val = a_counts[i]
    if i>0:
        if a_unique[i-1]+1==a_unique[i]:
            val += a_counts[i-1]
            
    if i<len(a_unique)-1:
        if a_unique[i+1]-1==a_unique[i]:
            val += a_counts[i+1]
            
    if val > ans:
        ans = val
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

num = int(input())
s = sorted(list(map(int, input().split())))
if num == 1:
    print(1)
else:
    max_ans = 0
    for i in range(num):
        start = s[i]
        c = collections.Counter(s)
        current_ans = c[start]+c[start+1]+c[start+2]
        max_ans = max(current_ans,max_ans)
        i += c[start]
    print(max_ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

num = int(input())
s = sorted(list(map(int, input().split())))
if num == 1:
    print(1)
else:
    max_ans = 0
    for i in range(num):
        start = s[i]
        c = collections.Counter(s)
        current_ans = c[start]+c[start+1]+c[start+2]
        max_ans = max(current_ans,max_ans)
    print(max_ans)

Submission status: Time Limit Exceeded

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

import numpy as np

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

ans = 0
for ele in a:
    m = np.sum(a - 1 == ele)
    s = np.sum(a == ele)
    p = np.sum(a + 1 == ele)
    cnt = m + s + p

    ans = max(ans, cnt)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        a = list(map(int, input().split()))

        ans = 0
        for x in range(10 ** 5 + 1):
            ans = max(ans, a.count(x - 1) + a.count(x) + a.count(x + 1))
        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a.sort()
ca = Counter(a)
maxa = a[-1]
mina = a[0]
ans = 0
for i in range(mina, maxa+1):
  cnt = sum([v for k, v in ca.items() if i - 1 <= k <= i + 1])
  if ans < cnt:
    ans = cnt
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a.sort()
ca = Counter(a)

ans = 0
for i in ca.keys():
  cnt = sum([v for k, v in ca.items() if i-1 <= k <= i+1])
  if ans < cnt:
    ans = cnt
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a.sort()
ca = Counter(a)

ans = 0
for i in ca.keys():
  cnt = sum([v for k, v in ca.items() if i-1 <= k <= i+1])
  if ans < cnt:
    ans = cnt
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input().strip())
counter = Counter()
for i in list(map(int, input().strip().split(' '))):
  counter += Counter([i-1,i,i+1])

print(counter.most_common(1)[0][1])

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
a=list(map(int,input().split()))
fl=1
def absX(n):
	ab=abs(i-n)
	if ab==0:
		ab=1
	return ab
for i in range(min(a),max(a)+1):
	fl_=list(map(absX,a)).count(1)
	if fl_>fl:fl=fl_
print(fl)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
a=list(map(int,input().split()))
fl=1
def absX(n):
	ab=abs(X-n)
	if ab==0:
		ab=1
	return ab
for i in range(min(a),max(a)+1):
	X=i
	fl_=list(map(absX,a)).count(1)
	if fl_>fl:
		fl=fl_
print(fl)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=list(map(int,input().split()))
fl=0
def absX(n):
	ab=abs(X-n)
	if ab==0:
		ab=1
	return ab
for i in range(min(a),max(a)+1):
	X=i
	fl_=list(map(absX,a)).count(1)
	if fl_>fl:
		fl=fl_
print(fl)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

sa=sorted(a)

ans=0
I=list(set(sa))
for i in I:
    ans=max(ans,sa.count(i-1)+sa.count(i)+sa.count(i+1))
print(ans)

Submission status: Time Limit Exceeded

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

if max(a)==min(a):
  print(n)
else:
  ans=1
  b=[0]*(10**6)
  for i in range(max(a)+1):
    b[i]=a.count(i)
  for i in range(10**5+3):
    ans=max(ans,b[i]+b[i+1]+b[i+2])
  print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
ans=1
b=[0]*(a[-1]-a[0]+2)
if a[0]==a[-1]:
  print(n)
else:
  for i in range(a[0]-1,a[-1]+1):
    b[i-a[0]+1]=a.count(i)
  for i in range(n+1):
    ans=max(ans,sum(b[i:i+3]))
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
ans=1
b=[]
if a[0]==a[-1]:
  print(n)
else:
  for i in range(a[0]-1,a[-1]+1):
    b+=[a.count(i)]
  for i in range(n+1):
    ans=max(ans,sum(b[i:i+3]))
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
ans=1
if a[0]==a[-1]:
  print(n)
else:
  for i in range(a[0],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 collections
N = int(input())
a = list(map(int, input().split()))
cand = collections.Counter(a)
cand_list = cand.most_common(len(set(a)))
ans = 0
for i in range(len(set(a))):
  num = cand_list[i][0]
  count = cand[num]
  if num + 1 in a:
    count += cand[num + 1]
  if num - 1 in a:
    count += cand[num - 1]
  ans = max(ans,count)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
a = list(map(int, input().split()))
cand = collections.Counter(a)
cand_list = cand.most_common(len(set(a)))
ans = 0
for i in range(len(set(a))):
  num = cand_list[i][0]
  count = cand[num]
  if num + 1 in a:
    count += cand[num + 1]
  if num - 1 in a:
    count += cand[num - 1]
  if ans < count:
    ans = count

print(ans)

Submission status: Time Limit Exceeded

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

set_a = set(a)
for i in set_a:
  counter = a.count(i-1) + a.count(i)+a.count(i+1)
  if ans < counter:
    ans = counter
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
ans= max(a.count(a[0]) + a.count(a[0]+1),a.count(a[-1]) + a.count(a[-1]-1))

set_a = set(a)
for i in set_a:
  counter = a.count(i-1) + a.count(i)+a.count(i+1)
  if ans < counter:
    ans = counter
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort()
ans= max(a.count(a[0]) + a.count(a[0]+1),a.count(a[-1]) + a.count(a[-1]-1))

for i in range(len(a)):
  counter = a.count(a[i]-1) + a.count(a[i])+a.count(a[i]+1)
  if ans < counter:
    ans = counter
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int,input().split()))
ans = 0
for i in A:
  cnt = A.count(i)
  if i-1 in A:
    cnt += A.count(i-1)
  if i+1 in A:
    cnt += A.count(i+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
for i in range(min(A),max(A)+1):
  cnt = A.count(i)
  cnt += A.count(i-1)
  cnt += A.count(i+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
for i in range(min(A),max(A)+1):
  cnt = A.count(i)
  if i-1 in A:
    cnt += A.count(i-1)
  if i+1 in A:
    cnt += A.count(i+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
for i in range(min(A),max(A)+1):
  cnt = 0
  if i in A:
    cnt += A.count(i)
  if i-1 in A:
    cnt += A.count(i-1)
  if i+1 in A:
    cnt += A.count(i+1)
  ans = max(ans,cnt) 
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import chain
n=int(input())
As=list(map(int,input().split()))
As = [[a-1, a, a+1] for a in As]
As = list(chain.from_iterable(As))

ans=-100
for i in list(set(As)):
  tmp=As.count(i)
  if ans<tmp:
    ans=tmp
print(ans)

Submission status: Time Limit Exceeded

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

Asmin=[i-1 for i in As]
Aspul=[i+1 for i in As]

ans=-100
for i in As:
  tmp=As.count(i+1)+As.count(i)+As.count(i-1)
  if ans<tmp:
    ans=tmp
print(ans)

Submission status: Time Limit Exceeded

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

Asmin=[i-1 for i in As]
Aspul=[i+1 for i in As]

ans=-100
for i in As:
  tmp=As.count(i+1)+As.count(i)+As.count(i-1)
  if ans<tmp:
    ans=tmp
for i in Asmin:
  tmp=As.count(i+1)+As.count(i)+As.count(i-1)
  if ans<tmp:
    ans=tmp
for i in Aspul:
  tmp=As.count(i+1)+As.count(i)+As.count(i-1)
  if ans<tmp:
    ans=tmp

print(ans)

Submission status: Time Limit Exceeded

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

ans=-100
for i in range(min(As)-1,max(As)+1):
  tmp=As.count(i+1)+As.count(i)+As.count(i-1)
  if ans<tmp:
    ans=tmp
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc072/tasks/arc082_a
# C - Together

n = int(input().split()[0])
a_list = list(map(int, input().split()))

a_op_list = [(a-1, a, a+1)for a in a_list]
max_count = 0

for a in set(a_list):
    count = len([x for x in a_list if x in [a+1, a, a-1]])
    max_count = count if count > max_count else max_count

print(max_count)

Submission status: Time Limit Exceeded

Solution code:
nums = int(input())
ary  = list(map(int,input().split()))
count =0
max_count = 0
ary.sort()
ary_count = [0 for i in range(100005)]
ary_count.append(0)

for i in range(100005):
    ary_count[i] = ary.count(i)

for i in range(1,100005):
    count += ary_count[i]
    count += ary_count[i+1]
    count += ary_count[i-1]
    if count > max_count:
        max_count = count
    count = 0
print(max_count)

Submission status: Time Limit Exceeded

Solution code:
nums = int(input())
ary  = list(map(int,input().split()))
count =0
max_count = 0
ary.sort()

for x in ary:
    count += ary.count(x-1)
    count += ary.count(x)
    count += ary.count(x+1)
    if count > max_count:
        max_count = count
    count = 0

print(max_count)

Submission status: Time Limit Exceeded

Solution code:
nums = int(input())
ary  = list(map(int,input().split()))
count =0
max_count = 0
ary.sort()

for x in ary:
    for i in range(nums):
        if ary[i] == x+1 or ary[i] == x or ary[i] == x-1:
            count += 1
        if ary[i] == x+2:
            break
    if count > max_count:
        max_count = count
    count = 0
print(max_count)

Submission status: Time Limit Exceeded

Solution code:
nums = int(input())
ary  = list(map(int,input().split()))
count =0
max_count = 0

for x in ary:
    for i in range(nums):
        if ary[i] == x+1 or ary[i] == x or ary[i] == x-1:
            count += 1
    if count > max_count:
        max_count = count
    count = 0
print(max_count)

Submission status: Time Limit Exceeded

Solution code:
nums = int(input())
ary  = list(map(int,input().split()))
count =0
max_count = 0

for x in range(max(ary)+1):
    for i in range(nums):
        if ary[i] == x+1 or ary[i] == x or ary[i] == x-1:
            count += 1
    if count > max_count:
        max_count = count
    count = 0
print(max_count)

Submission status: Time Limit Exceeded

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

ys = [0] * (max(a)+ 1)

for x in range(len(ys)):
    y = a.count(x-1) + a.count(x) + a.count(x+1)
    ys[x] = y

print(max(ys))

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
count_dict = collections.Counter(A)
d = []
for k,v in count_dict.items():
	d.append(k)
	d.append(k-1)
	d.append(k+1)

d = list(set(d))
ans = 0
for i in d:
	count = 0
	for j in range(N):
		if A[j] == i or A[j]+1 == i or A[j]-1 == i:
			count += 1
		ans = max(ans,count)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
count_dict = collections.Counter(A)
d = []
for k,v in count_dict.items():
	d.append(k)

ans = 0
for i in range(max(d)+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 = max(ans,count)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
x =[0]*(10**5+1)
a_set =  set(a)
a_list = list(a_set)

a_list.sort()
ans = 0
temp = 0
x[a_list[0]-1]=0

for i in a_list:
    x[i]=a.count(i)
    if i+1 in a_list:
        temp = x[i-1]+x[i]+a.count(i+1)
    else:
        temp = x[i-1]+x[i]

    if temp>ans:
        ans = temp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
x =[0]*(10**5+1)
a_set =  set(a)
a_list = list(a_set)

a_list.sort()

for i in a_list:
    x[i]=a.count(i)

ans = 0

mi = min(a_list)
mx = max(a_list)

for i in a_list:
    temp = x[i-1]+x[i]+x[i+1]
    if temp>ans:
        ans = temp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

def dec(a):
    return a-1

def inc(a):
    return a+1

a = list(map(int,input().split()))
b = list(map(dec,a))
c = list(map(inc,a))

count = a+b+c

set_c = list(set(count))

c = {}
for i in range(len(set_c)):
    c[set_c[i]] = count.count(set_c[i])

print(max(c.values()))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a2=sorted(a)
num=-1
ans=0
for i in range(n):
    if a2[i]!=num:
        num=a2[i]
        total=a2.count(num)+a2.count(num-1)+a2.count(num+1)
        if total>ans:
            ans=total
    else:
        continue
print(ans)

Submission status: Time Limit Exceeded

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

A_list = []
for a in A:
  A_list.append(a)
  A_list.append(a+1)
  A_list.append(a-1)

A_unique = list(set(A_list))
A_dict = {}

for a_unique in A_unique:
  count = 0
  for a in A:
    if a_unique == a or a_unique == (a-1) or a_unique == (a+1):
      count +=1
  A_dict[a_unique] = count

ans = max(A_dict.values())
print(ans)

Submission status: Time Limit Exceeded

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

    cnt = 0

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

main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, = read_h()
    arr = sorted(read_h())

    cnt = 0
    for X in set(arr):
        tmp_cnt = 0
        for a in arr:
            if a > X + 1:
                break
            if X - 1 <= a <= X + 1:
                tmp_cnt += 1

        cnt = max(cnt, tmp_cnt)

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, = read_h()
    arr = read_h()

    cnt = 0
    for X in set(arr):
        tmp_cnt = 0
        for a in arr:
            if X - 1 <= a <= X + 1:
                tmp_cnt += 1

        cnt = max(cnt, tmp_cnt)

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, = read_h()
    arr = read_h()

    cnt = 0
    for X in set(arr):
        cnt = max(cnt, sum([1 for a in arr if X - 1 <= a <= X + 1]))

    print(cnt)


if __name__ == '__main__':
    main()