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()))
a.sort()
i = 0
max_count = 0
count = 0
while i < len(a):
    x = a[i]
    j = i
    while j < len(a):
        if x == a[j] or x+1 == a[j] or x+2 == a[j]:
            count += 1
            j += 1
        else:
            break
    if max_count < count:
        max_count = count
    count = 0
    i += 1
print(max_count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def resolve():
	n=int(input())
	a=list(map(int,input().split()))
	l=min(a)+1
	g=max(a)
	if n==1:
		ans=1
	else:
		ans=0
		for i in a:
			ans=max(ans,a.count(i))
		for i in range(l,g):
			ans=max(ans,a.count(i-1)+a.count(i)+a.count(i+1))
	print(ans)
resolve()

Submission status: Time Limit Exceeded

Solution code:
def print_ans(s):
    """Print substring of s, odd_th char
    >>> print_ans([1])
    1
    >>> print_ans([1,4])
    1
    >>> print_ans([0,3,4,5])
    3
    >>> print_ans([1,2,3,2,5,6])
    4
    
    """
    b = list(set(s))
    ans = 1
    """TLE 
    for i in range(b[0],b[-1]+1):
        ans = max(b.count(i)+b.count(i+1)+b.count(i+2),ans)
    """
    
    for i in range(len(b)):
        ans = max(ans,s.count(b[i])+s.count(b[i]+1)+s.count(b[i]+2))
    print(ans)

if __name__ == '__main__':
    N = input()
    a = list(map(int,input().split()))
    print_ans(a)

Submission status: Time Limit Exceeded

Solution code:
def print_ans(s):
    """Print substring of s, odd_th char
    >>> print_ans([1])
    1
    >>> print_ans([1,4])
    1
    >>> print_ans([0,3,4,5])
    3
    >>> print_ans([1,2,3,2,5,6])
    4
    
    """
    b = sorted(s)
    ans = 1
    for i in range(b[0],b[-1]+1):
        ans = max(b.count(i)+b.count(i+1)+b.count(i+2),ans)
    print(ans)

if __name__ == '__main__':
    N = input()
    a = list(map(int,input().split()))
    print_ans(a)

Submission status: Time Limit Exceeded

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

ans = []
a_s = sorted(a)
for i in range(len(a)):
    for j in range(len(a)):
        if a_s[j]-a_s[i] <= 2:
            ans.append(j-i+1)

print(max(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

all_data = list(set(A))

num = 0

for i in all_data:
  tmp = A.count(i) + A.count(i+1) + A.count(i-1)
  num = max(num, tmp)
  
print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

a.sort()

#print (a)

a = a + [-2]
ans = 0
for i in range(N):
    count = 0
    j = 0
    while a[i] <= a[i+j] and a[i+j] <= a[i] + 2:
        count += 1
        j += 1
    ans = max(ans, count)

print (ans)

Submission status: Time Limit Exceeded

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

plus = []
minus = []

for i in a:
    minus.append(i-1)
    plus.append(i+1)

all_l = a + minus + plus
set_all = list(set(all_l))

ans = 0
for i in set_all:
    if all_l.count(i) > ans:
        ans = all_l.count(i)

print(ans)

Submission status: Time Limit Exceeded

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

plus = []
minus = []

for i in a:
    minus.append(i-1)
    plus.append(i+1)

all_l = a + minus + plus
all_l.sort()
set_all = list(set(all_l))

ans = 0
for i in set_all:
    if all_l.count(i) > ans:
        ans = all_l.count(i)

print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0
X = []

for k in a:
    X.append(k+1)
    X.append(k)
    X.append(k-1)

for i in X:
    tmplist = []
    for j in a:
        tmplist.append(i-j)
        if cnt < tmplist.count(1) + tmplist.count(0) + tmplist.count(-1):
            cnt = tmplist.count(1) + tmplist.count(0) + tmplist.count(-1)

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)+2):
    tmplist = []
    for j in a:
        tmplist.append(i-j)
        if cnt < tmplist.count(1) + tmplist.count(0) + tmplist.count(-1):
            cnt = tmplist.count(1) + tmplist.count(0) + tmplist.count(-1)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
t = [1 if a[i] == a[j] or abs(a[i] - a[j]) == 1 else 0 for i in range(n) for j in range(n)]
print(max([sum(t[i:i+n]) for i in range(0, len(t), n)]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lis = sorted(list(map(int,input().split())))
now = -1
ans = 0
for x in range(n):
    if lis[x] == now:
        continue
    now = lis[x]
    val = 0
    for y in range(n-x):
        if lis[x]+2 >= lis[x+y]:
            val += 1
            ans = max(ans,val)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = set(A)
X = 0
for i in B:
	Xlow = A.count(i)
	Xmid = A.count(i+1)
	Xhi = A.count(i+2)
	X = max(X, Xlow + Xmid + Xhi)
print(X)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
Xlow = A.count(0)
Xmid = A.count(1)
Xhi = A.count(2)
X = Xlow + Xmid + Xhi
for i in range(3, max(A)+2):
	X = max(X, Xlow + Xmid + Xhi)
	Xlow, Xmid = Xmid, Xhi
	Xhi = A.count(i)
print(X)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=[a.count(a[0])+a.count(a[0]+1)]
for x in range(a[0]+1,a[-1]):
    b.append(a.count(x-1)+a.count(x)+a.count(x+1))
b.append(a.count(a[-1]-1)+a.count(a[-1]))
print(max(b))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = []
elements = set()
for i in input().split():
    a.append(int(i))
    elements.add(int(i))
    elements.add(int(i)-1)
    elements.add(int(i)+1)
max_count = 0
for X in elements:
    count = 0
    for num in a:
        if X-1 <= num <= X+1:
            count += 1
    max_count = max(max_count, count)
print(max_count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = []
elements = set()
for i in input().split():
    a.append(int(i))
    elements.add(int(i))
max_count = 0
for X in elements:
    count1 = 0
    count2 = 0
    count3 = 0
    for num in a:
        if X-1 <= num <= X+1:
            count1 += 1
        if X <= num <= X+2:
            count2 += 1
        if X-2 <= num <= X:
            count3 += 1
    max_count = max(max_count, count1, count2, count3)
print(max_count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = []
maximum = 0
minimum = 10 ** 5
for i in input().split():
    a.append(int(i))
    maximum = max(maximum, int(i))
    minimum = min(minimum, int(i))
max_count = 0
for X in range(minimum, maximum+1):
    count = 0
    for num in a:
        if X-1 <= num <= X+1:
            count += 1
    max_count = max(max_count, count)
print(max_count)

Submission status: Time Limit Exceeded

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

for k in range(min(a), max(a) + 1):
	tmp = 0
	for x in a:
		if x in [k - 1, k, k + 1]:
			tmp += 1
	s.append(tmp)
print(max(s))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

for k in set(a):
	ans = max(ans, a.count(k) + a.count(k + 1) + a.count(k - 1))
	ans = max(ans, a.count(k - 1) + a.count(k) + a.count(k - 2))
	ans = max(ans, a.count(k + 1) + a.count(k + 2) + a.count(k))

print(ans)

Submission status: Time Limit Exceeded

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

m = {}
for a in sorted(set(A)):
	m[a] = A.count(a)

r = 0
for n in m:
	t = m[n]
	if n + 1 in m:
		t += m[n + 1]
	if n + 2 in m:
		t += m[n + 2]
	r = max(r, t)

print(r)

Submission status: Time Limit Exceeded

Solution code:
#ABC 072 C
N=int(input())
A=[int(j) for j in input().split()]
cnt=0
for a in A:
    tmp=0
    for i in range(len(A)):
        if -1<= A[i]-a <=1:
            tmp+=1
    cnt=max(tmp,cnt)
print(cnt)

Submission status: Time Limit Exceeded

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

setA = set(A)

ans = 0
c = 0
for x in setA:
    for a in A:
        if a == x-1 or a == x or a == x+1:
            c += 1
    ans = max(ans, c)
    c = 0
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())))
amax =max(A)
amin =min(A)
cntm = A.count(amin - 1)
cntz = A.count(amin)
cntp = A.count(amin + 1)
ans = cntm + cntz + cntp
for i in A:
    cntm = cntz
    cntz = cntp
    cntp = A.count(i + 1)
    ans = max(ans,cntm + cntz + cntp)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
amax =max(A)
amin =min(A)
cntm = A.count(amin - 1)
cntz = A.count(amin)
cntp = A.count(amin + 1)
ans = cntm + cntz + cntp
for i in range(amin + 1 , amax):
    cntm = cntz
    cntz = cntp
    cntp = A.count(i + 1)
    ans = max(ans,cntm + cntz + cntp)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())))
amax =max(A)
amin =min(A)
cntm = A.count(amin - 1)
cntz = A.count(amin)
cntp = A.count(amin + 1)
ans = cntm + cntz + cntp
for i in range(amin + 1 , amax):
    cntm = cntz
    cntz = cntp
    cntp = A.count(i + 1)
    ans = max(ans,cntm + cntz + cntp)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())))
amax =max(A)
amin =min(A)
ans = 0
for i in range(amin - 1,amax + 2):
    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()))
amax =max(A)
amin =min(A)
ans = 0
for i in range(amin - 1, amax + 2):
    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 = [int(i) for i in input().split()]
Min = min(a)-1
Max = max(a)+1
num = [[0 for i in range(N)] for j in range(Min, Max+1)]

idx = 0
for i in a:
    num[i-Min-1][idx] = 1
    num[i-Min][idx] = 1
    num[i-Min+1][idx] = 1
    idx += 1

ct = -1
for i in num:
    tmp = i.count(1)
    if tmp > ct:
        ct = tmp
        
print(ct)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

checked = []
zipped = zip(list(range((10**5+1))), [0]*(10**5+1))
nums = dict(zipped)
for i in a:
  if i not in checked:
    nums[i] = a.count(i)
    checked.append(i)
  
  
totals = [0] * (10**5 + 1)
for i in nums:
  if i == 0:
    totals[0] = nums[0] + nums[1]
  elif i == (10**5):
    totals[0] = nums[10**5-1] + nums[10**5]
  else:
    totals[i] = nums[i-1] + nums[i] + nums[i+1]
  
  
print(max(totals))

Submission status: Time Limit Exceeded

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

count_max = 0
for x in range(min(a), max(a)+1):
    count=0
    for k in a:
        if x-1 <= k <= x+1:
            count += 1 
    count_max = max(count_max, count)

print(count_max)

Submission status: Time Limit Exceeded

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

    ai_to_a_num = {}
    for ai in a_s:
        if ai in ai_to_a_num.keys():
            ai_to_a_num[ai] += 1
        else:
            ai_to_a_num[ai] = 1
    
    max_num = 0
    for ai in ai_to_a_num.keys():
        num = 0
        num += ai_to_a_num[ai]
        if ai-1 in ai_to_a_num.keys():
            num += ai_to_a_num[ai-1]
        if ai+1 in ai_to_a_num.keys():
            num += ai_to_a_num[ai+1]
        max_num = max(max_num, num)
    
    print(max_num)

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
alist = np.array(list(map(int, input().split())))
alist
alistp = alist + 1
alistm = alist - 1
k = []
d = {}
for a in alist:
    if a not in k:
        k.append(a)
        d[a] = 1
    else:
        d[a] += 1
for a in alistp:
    if a not in k:
        k.append(a)
        d[a] = 1
    else:
        d[a] += 1
for a in alistm:
    if a not in k:
        k.append(a)
        d[a] = 1
    else:
        d[a] += 1
print(max(d.values()))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
alist = np.array(list(map(int, input().split())))
alist
alistp = alist + 1
alistm = alist - 1
alists = np.hstack([alistm, alist, alistp])
k = []
d = {}
for a in alists:
    if a not in k:
        k.append(a)
        d[a] = 1
    else:
        d[a] += 1
print(max(d.values()))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
a = list(map(int, input().split()))
values_0 = [0,0]
values_1 = [0]
values_2 = []
for i in range(min(a), max(a)+1):
    values_0.append(a.count(i))
    values_1.append(a.count(i))
    values_2.append(a.count(i))

values_1 += [0]
values_2 += [0,0]
values_0 = np.array(values_0)
values_1 = np.array(values_1)
values_2 = np.array(values_2)
print(max(values_0+values_1+values_2))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int, input().split()))
ans = 0
for num in range(min(A), max(A)+1):
    tmp = [1 if abs(a-num)<=1 else 0 for a in A]
    ans = max(ans, sum(tmp))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

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

X=list(set(A))

RES=[]

for i in X:
    a=A.count(i-1)
    b=A.count(i)
    c=A.count(i+1)
    RES.append(a+b+c)
    
print(max(RES))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

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

X=list(set(A))

RES=[]

for i in X:
    a=A.count(i-1)
    b=A.count(i)
    c=A.count(i+1)
    RES.append(a+b+c)
    
print(max(RES))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

input()
arr = np.array(list(map(int, input().split())))
nums = set(arr)

res = 0
for n in nums:
    res = max(sum((arr < (n+2))[arr > (n-2)]), res)
print(res)

Submission status: Time Limit Exceeded

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

afters = []
for ai in range(N):
	for sign in [-1,0,1]:
		afters.append(A[ai]+sign)
		
uniq = set(afters)

counts = []
for u in list(uniq):
	counts.append(afters.count(u))
	
print(max(counts))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = set(A)
cnt = 0
for i in B:
    a, b, c = A.count(i), A.count(i+1), A.count(i+2)
    sums = a+b+c
    if sums > cnt:
        cnt = sums
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i in A:
    a, b, c = A.count(i), A.count(i+1), A.count(i+2)
    sums = a+b+c
    if sums > cnt:
        cnt = sums
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
cnt = 0
for i in A:
    a, b, c = A.count(i), A.count(i+1), A.count(i+2)
    sums = a+b+c
    if sums > cnt:
        cnt = sums
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans = [1] * len(a)
index=0
for i in range(n):
    ans[index] = a.count(a[i]-1)+a.count(a[i])+a.count(a[i]+1)
    index+=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):
    tmp = a.count(a[i]-1)+a.count(a[i])+a.count(a[i]+1)
    if ans < tmp:
        ans = tmp
print(ans)

Submission status: Time Limit Exceeded

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

st_int_group = set(ar_int_a)
max_count = 0

for i in st_int_group:
    # current = ar_int_a.count(i) + ar_int_a.count(i - 1) + ar_int_a.count(i + 1)
    # max_count = current if max_count <= current else max_count
    max_count = max(ar_int_a.count(i) + ar_int_a.count(i - 1) + ar_int_a.count(i + 1), max_count)

print(max_count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=Counter(a)
t=[]
for _ in b.most_common(100):
  t.append(len([i for i in a if _[0]-1<i<_[0]+3]))
  t.append(len([i for i in a if _[0]-2<i<_[0]+2]))
  t.append(len([i for i in a if _[0]-3<i<_[0]+1]))
print(max(t))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=Counter(a)
t=[]
for _ in b.most_common():
  t.append(len([i for i in a if _[0]-1<i<_[0]+3]))
  t.append(len([i for i in a if _[0]-2<i<_[0]+2]))
  t.append(len([i for i in a if _[0]-3<i<_[0]+1]))
print(max(t))

Submission status: Time Limit Exceeded

Solution code:
a = int(input())

B = list(input().split())

A = []

for i in B:
    i = int(i)
    A.append(i)
    A.append(i+1)
    A.append(i-1)

C = set(A)
ans = 0
for i in C:
    a = A.count(i)
    if(a>ans):
        ans = a
print(ans)

Submission status: Time Limit Exceeded

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

st_int_group = set(ar_int_a)
max_count = 0

for i in st_int_group:
    current = ar_int_a.count(i) + ar_int_a.count(i - 1) + ar_int_a.count(i + 1)
    max_count = current if max_count <= current else max_count

print(max_count)

Submission status: Time Limit Exceeded

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

ans = 0

for x in range(0, 100001):
    score = A.count(x-1) + A.count(x) + A.count(x+1)
    if score >= ans:
        ans = score

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
A.sort()
A_max = A[-1]

for x in range(-1, A_max + 1):
    score = 0
    for i in range(N):
        if abs(x - A[i]) <= 1:
            score += 1
    if score >= ans:
        ans = score

print(ans)

Submission status: Time Limit Exceeded

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

max = 0

for x in range(-1, 100002):
    score = 0
    for i in range(N):
        if abs(x - A[i]) <= 1:
            score += 1
    if score >= max:
        max = score

print(max)

Submission status: Time Limit Exceeded

Solution code:
import collections
import math
import re
import numpy


def ai():return input()#s
def a():return int(input())#a,n or k
def ma():return map(int, input().split())#a,b,c,d or n,k
def ms():return map(str, input().split())#,a,b,c,d
def lma():return list(map(int, input().split()))#x or y
def lms():return list(map(str, input().split()))#x or y
k= []
l = []
f = 0
s=0
c=0
e =1
def say(i):return print("Yes" if i == 0 else "No")
def Say(i):return print("YES" if i == 0 else "NO")
#def rep(i):return for i in range()
a = a()
x = lma()
l = set(x)
m=1
for i in l:
    t = x.count(i)+x.count(i+1)+x.count(i-1)
    m=max(m,t)
print(m)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int,input().split()))
cnt = 0
max_A = max(A)

for i in range(-1,max_A+1):
    temp_cnt = 0
    for j in range(n):
        if A[j]-1 == i or A[j] == i or A[j]+1 == i:
            temp_cnt += 1
    if temp_cnt > cnt:
        cnt = temp_cnt

print(cnt)

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 sys
#input = sys.stdin.readline
n=int(input())
a=[int(i) for i in input().split()]

#print(a)
ans=0
if n==1:
  ans=1
else:
  for i in range(1,100000+1):
    cnt=0
    for j in a:
      if j==i or j==i-1 or j==i+1:
        cnt+=1
      if ans <= cnt:
        ans = cnt

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import sys
#input = sys.stdin.readline
n=int(input())
a=[int(i) for i in input().split()]

#print(a)
ans=0
if n==1:
  ans=1
else:
  for i in range(1,100000+1):
    cnt=0
    maxa=max(a)
    for j in range(len(a)):
      if a[j]==i or a[j]==i-1 or a[j]==i+1:
        cnt+=1
      if ans <= cnt:
        ans = cnt

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
a=[int(i) for i in input().split()]
b=a
b+=[a[i]-1 for i in range(n)]
b+=[a[i]+1 for i in range(n)]
#print(a)

ans=0
maxa=max(a)
for i in range(1,max(a)+1):
    cnt=b.count(i)
    if ans <= cnt:
      ans = cnt

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import sys
#input = sys.stdin.readline
n=int(input())
a=[int(i) for i in input().split()]
b=a
b+=[a[i]-1 for i in range(n)]
b+=[a[i]+1 for i in range(n)]
#print(a)

ans=0
maxa=max(a)
for i in range(1,max(a)+1):
    cnt=b.count(i)
    if ans <= cnt:
      ans = cnt

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n=int(input())
a=[int(i) for i in input().split()]
#print(a)

ans=0
for i in range(1,100000+1):
    cnt=a.count(i-1)+a.count(i)+a.count(i+1)
    if ans < cnt:
      ans = cnt

print(ans)

Submission status: Time Limit Exceeded

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

ans=0
for i in range(1,100000+1):
    cnt=a.count(i-1)+a.count(i)+a.count(i+1)
    if ans < cnt:
      ans = cnt

print(ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

    xmin = min(a)
    xmax = max(a)

    ans = count = 0
    for x in range(xmin, xmax+1):
        for i in a:
            if i - 1 <= x <= i + 1:
                count += 1

        ans = max(ans, count)
        count = 0

    print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
l=[]
for i in range(n):
  j=1
  while a[min(i+j,n-1)]-a[i]<=2 and i+j<n:
    j+=1
  l.append(j)
print(max(l))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
check = [0] * (10**5+1)
check[0] = A.count(0)+A.count(1)

for i in range(1, 10**5+1):
    
    check[i] = check[i-1] - A.count(i-2) + A.count(i+1)
print(max(check))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
check = []
check.append(A.count(min(A))+A.count(min(A)+1))

for i in range(min(A)+1, max(A)+1):
    check.append(check[-1]-A.count(i-2)+A.count(i+1))
print(max(check))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
br = []
for r in ar:
    br.append(r)
    br.append(r - 1)
    br.append(r + 1)
cr = set(br)
dr = []
for r in cr:
    dr.append(br.count(r))
print(max(dr))

Submission status: Time Limit Exceeded

Solution code:
## ABC 072 c
n = int(input())
a = [int(i) for i in input().split()]
a.sort()

cnt = 0
for x in range(a[0]-1, a[-1]+2):
    c = a.count(x)+a.count(x-1)+a.count(x+1)
    cnt = max(c,cnt)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
## ABC 072 c
n = int(input())
a = [int(i) for i in input().split()]
a.sort()

cnt = 0
for x in range(a[0]-1, a[-1]+2):
    c = 0
    for v in a:
        if (abs(x-v) <= 1):
            c += 1
    cnt = max(c,cnt)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
## ABC 072 c
n = int(input())
a = [int(i) for i in input().split()]
a.sort()

ans = 0
cnt = 0
for x in range(a[0]-1, a[-1]+2):
    c = 0
    for i, v in enumerate(a):
        if (abs(x-v) <= 1):
            c += 1
    if (c > cnt):
        ans = x
        cnt = c

print(cnt)

Submission status: Time Limit Exceeded

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