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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import Counter

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

if N >= 3:
    counter = Counter(A)
    m = min(A)
    M = max(A)
    cnt = []
    for i in range(m, M - 1):
        ans = counter[i] + counter[i + 1] + counter[i + 2]
        if ans:
            cnt.append(ans)
        print(cnt)
    print(max(cnt))

elif N == 2:
    if abs(A[0] - A[1]) <= 2:
        print(2)
    else:
        print(1)

elif N == 1:
    print(1)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

if N >= 3:
    counter = Counter(A)
    m = min(A)
    M = max(A)
    cnt = []
    for i in range(m, M - 2):
        cnt.append(counter[i] + counter[i + 1] + counter[i + 2])
    print(max(cnt))

elif N == 2:
    if abs(A[0] - A[1]) <= 2:
        print(2)
    else:
        print(1)

elif N == 1:
    print(1)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[0]*10**5
b=input().split()
numbers=[int(a) for a in b]
for a in numbers:
    A[a-1]+=1
list=[]
for z in range(10**5-1):
    y=A[z]+A[z+1]+A[z+2]
    list.append(y)
print(max(list))

Submission status: Runtime Error

Solution code:
import sys

n = input()
a = list(map(int, input().split()))
ans_dict = {}
if len(a)==1:
    print(a[0])
    sys.exit()
for X in range(min(a), max(a)):
    ans_dict[str(X)] = 0
    for j in a:
        if X == j or X == j-1 or X == j+1:
            ans_dict[str(X)] = ans_dict[str(X)]+1
print(max(ans_dict.values()))

Submission status: Runtime Error

Solution code:
n = input()
a = list(map(int, input().split()))
ans_dict = {}
for X in range(min(a), max(a)):
    ans_dict[str(X)] = 0
    for j in a:
        if X == j or X == j-1 or X == j+1:
            ans_dict[str(X)] = ans_dict[str(X)]+1
print(max(ans_dict.values()))

Submission status: Runtime Error

Solution code:
import sys
readline=sys.stdin.readline
n=int(readline())
aa=list(map(int,readline().split()))
laa=len(aa)
cnt=[0]*(10**5+3)
for i in range(laa):
  if i > 0:
    aa[i-1]+=1
  aa[i]+=1
  aa[i+1]+=1

ans=0

for _ in aa:
  ans=max(ans,_)

print(ans)

Submission status: Runtime Error

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

# いもす法 imos法

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

for i in range(N):
    l, r, s = a[i] - 1, a[i] + 1, 1
    l += 1
    r += 1
    # print(l, r)
    imos[l] += s
    imos[r + 1] -= s

for i in range(N + 1):
    imos[i + 1] = imos[i] + imos[i + 1]

# print(imos[: max(a) + 3])

print(max(imos[: max(a) + 3]))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=[-1,0]
i=0
while i<n-1:
    res=0
    while a[i+res]-a[i]<=2:
        res+=1
    if res>ans[1]:
        ans[1]=res
        ans[0]=i
    i+=res
print(ans[1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
x = Counter(a)
cnt = sorted(x.items(), key=lambda x: x[0], reverse=True)
ans = 0
for i in range(len(cnt)):
    x = cnt[i][1]
    print(x)
    if i != 0:
        if cnt[i][0] == cnt[i-1][0] - 1:
            x += cnt[i-1][1]
    if i == len(cnt) - 1:
        if cnt[i][0] == cnt[i+1][0] + 1:
            x += cnt[i+1][1]
    ans = max(ans, x)
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
cnt = [0] * 10 ** 5
for i in a:
    cnt[i - 1] += 1
    cnt[i] += 1
    cnt[i + 1] += 1
print(max(cnt))

Submission status: Runtime Error

Solution code:
def together(n , a):

    listans = [0]*(10**5)

    for i in range(n):
        listans[a[i] - 1] += 1
        listans[a[i]] += 1
        listans[a[i] + 1] += 1

    return max(listans)


def main():
    n = int(input())
    a = list(map(int,input().split()))
    print(together(n , a))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=a.copy()
for i in a:
  b.append(i-1)
  b.append(i+1)
import collection
c=collection.Counter(b)
d=c.most_common()
print(d[0][1])

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int(input().split())))
cnt = [0] * int(1e6)
for i in a:
    cnt[i-1] += 1
    cnt[i] += 1
    cnt[i+1] += 1
print(max(cnt))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
pl = [0]*(n+5)

for i in range(n):
    num = a[i]
    pl[num-1] += 1
    pl[num+2] -= 1

for i in range(1,n):
    pl[i] += pl[i-1]

print(max(pl))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
pl = [0]*(n+5)

for i in range(n):
    num = a[i]
    pl[num-1] += 1
    pl[num+2] -= 1

for i in range(1,n+4):
    pl[i] += pl[i-1]

print(max(pl))

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

li_conut = defaultdict(int)

# 要素ごとの出現数を記録
for a in li:
    li_count[a] += 1

max_x_count = 0

for x in range(1, 10**5):
    # xにできるやつの個数
    x_conut = li_conut[x-1] + li_conut[x] + li_conut[x+1]
    max_x_count = max(max_x_count, x_conut)
print(max_x_count)

Submission status: Runtime Error

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

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

max = 0

for i in range(100000 + 1):

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

  if max < a:
    max = a

print(a)

Submission status: Runtime Error

Solution code:
def main():
  n = int(input())
  a = list(map(int, input().split()))
  ans = [0] * 10**5
  for i in a:
    ans[i] += 1
    ans[i+1] += 1
    ans[i+2] += 1
  print(max(ans))

main()

Submission status: Runtime Error

Solution code:
n = int(input())
a = list( map( int, input().split() ) )
cnt = [0]*10^5
    
for j in a:
    for num in range(10^5):
        if j-1 == num or j == num or j+1 == num:
            cnt[num] += 1
print(max(cnt))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list( map( int, input().split() ) )
cnt = [0]*10^5
    
for j in a:
    for num in range(10^5):
        if j-1 == num or j == num or j+1 == num:
            cnt[i] += 1
print(max(cnt))

Submission status: Runtime Error

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

li = [0 for i in range(n)]
for i in range(n):
    li[a[i]] += 1

x = 0
for i in range(1,n-1):
    x = max(li[i-1]+li[i]+li[i+1])

print(x)

Submission status: Runtime Error

Solution code:
import collections

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

c = collections.Counter(a)
d = list(c.keys())
e = list(c.values())

if n == 1:
    print(1)
    exit()
elif n == 2:
    if a[0] == a[1] or abs(a[0] - a[1]) == 1:
        print(2)
        exit()
    else:
        print(1)
        exit()
elif len(d) == 1:
    print(e[0])
    exit()
elif len(d) == 2:
    if d[0] == d[1] or abs(d[0] - d[1]) == 1:
        print(e[0] + e[1])
        exit()
    else:
        print(max(e[0], e[1]))


for i in range(n-2):
    if abs(d[i] - d[i+1]) == 1 and abs(d[i] - d[i+2]) == 2:
        num = e[i] + e[i+1] + e[i+2]
    elif abs(d[i] -d[i+1]) == 1:
        num = e[i] + e[i+1]
    else:
        num = e[i]
    if num > ans:
        ans = num

if d[-2] == d[-1] or abs(d[-2] - d[-1]) == 1:
    num = e[-2] + e[-1]
else:
    num = max(e[-2], e[-1])

if num > ans:
    ans = num

print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

c = collections.Counter(a)
d = list(c.keys())
e = list(c.values())

if n == 1:
    print(1)
    exit()
elif n == 2:
    if a[0] == a[1] or abs(a[0] - a[1]) == 1:
        print(2)
        exit()
    else:
        print(1)
        exit()


for i in range(n-2):
    if abs(d[i] - d[i+1]) == 1 and abs(d[i] - d[i+2]) == 2:
        num = e[i] + e[i+1] + e[i+2]
    elif abs(d[i] -d[i+1]) == 1:
        num = e[i] + e[i+1]
    else:
        num = e[i]
    if num > ans:
        ans = num

if d[-2] == d[-1] or abs(d[-2] - d[-1]) == 1:
    num = e[-2] + e[-1]
else:
    num = max(e[-2], e[-1])

if num > ans:
    ans = num

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

N = ri()
A = np.array(rl())
answer = 0
c = np.bincount(A)

for i in range(1, len(c)):
    result = c[i-1] + c[i] + c[i+1]
    if result > answer:
        answer = result

print(answer)
# 32

Submission status: Runtime Error

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

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

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

        if ans < ans1:
            ans = ans1
        ans1 = 0

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import Counter



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

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
from typing import List, Set



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

    print(max_count)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

ans = [0 for i in range(max(a))]

for i in a:
  ans[i-1]+=1
  if i <max(a):
    ans[i]+=1
  if i-2 >= 0:
    ans[i-2]+=1
print(max(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
dct = {}
for i in range(-1,10**5):
  dct[i] = 0
for i in A:
  dct[i-1] += 1
  dct[i] += 1
  dct[i+1] += 1

sorted_dct = sorted(dct.items(), key=lambda x:-x[1])
print(sorted_dct[0][1])

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
dct = {}
for i in range(10**5):
  dct[i] = 0
for i in A:
  dct[i-1] += 1
  dct[i] += 1
  dct[i+1] += 1

sorted_dct = sorted(dct.items(), key=lambda x:-x[1])
print(sorted_dct[0][1])

Submission status: Runtime Error

Solution code:
import collections
import sys
n=int(input())
a=list(map(int,input().split()))
A=collections.Counter(a)
b=list(A.items())
b.sort()
cnt=0
if len(b)==1:
  print(b[0][1])
  sys.exit()
if len(b)==2:
  if int(b[1][0])-int(b[0][0])==1:
    print(b[1][1]+b[0][1])
    sys.exit()
  else:
    print(max(b[1][1],b[0][1]))
    sys.exit()
for i in range(len(b)-2):
  if int(b[i+2][0])-int(b[i+1][0])==1 and int(b[i+1][0])-int(b[i][0])==1:
    cnt=max(cnt,b[i][1]+b[i+1][1]+b[i+2][1]) 
  elif int(b[i+1][0])-int(b[i][0])==1:
    cnt=max(cnt,b[i+1][1]+b[i][1])
  else:
    cnt=max(cnt,b[i])
    
if int(b[len(b)-1][0])-int(b[len(b)-2][0])==1 and int(b[len(b)-2][0])-int(b[len(b)-3][0])!=1:
  cnt=cnt
elif int(b[len(b)-1][0])-int(b[len(b)-2][0])==1:
  cnt=max(cnt,b[len(b)-1][1]-b[len(b)-2][1])
else:
  cnt=max(cnt,max(b[len(b)-1][1],b[len(b)-2][1]))
print(cnt)

Submission status: Runtime Error

Solution code:
import collections
import sys
n=int(input())
a=list(map(int,input().split()))
if n==1:
  print(1)
  sys.exit()
if n==2:
  if abs(a[1]-a[0])<2:
    print(2)
    sys.exit()
  else:
    print(1)
    sys.exit()    
A=collections.Counter(a)
b=list(A.items())
b.sort()
cnt=0
for i in range(len(b)-2):
  if int(b[i+2][0])-int(b[i+1][0])==1 and int(b[i+1][0])-int(b[i][0])==1:
    cnt=max(cnt,b[i][1]+b[i+1][1]+b[i+2][1]) 
  elif int(b[i+1][0])-int(b[i][0])==1:
    cnt=max(cnt,b[i+1][1]+b[i][1])
  else:
    cnt=max(cnt,b[i])
    
if int(b[len(b)-1][0])-int(b[len(b)-2][0])==1 and int(b[len(b)-2][0])-int(b[len(b)-3][0])!=1:
  cnt=cnt
elif int(b[len(b)-1][0])-int(b[len(b)-2][0])==1:
  cnt=max(cnt,b[len(b)-1][1]-b[len(b)-2][1])
else:
  cnt=max(cnt,max(b[len(b)-1][1],b[len(b)-2][1]))
print(cnt)

Submission status: Runtime Error

Solution code:
import collections
import sys
n=int(input())
a=list(map(int,input().split()))
if n==1:
  print(1)
  sys.exit()
if n==2:
  if abs(a[1]-a[0])<2:
    print(2)
    sys.exit()
  else:
    print(1)
    sys.exit()    
A=collections.Counter(a)
b=list(A.items())
b.sort()
cnt=0
for i in range(len(b)-2):
  if int(b[i+2][0])-int(b[i+1][0])==1 and int(b[i+1][0])-int(b[i][0])==1:
    cnt=max(cnt,b[i][1]+b[i+1][1]+b[i+2][1]) 
  elif int(b[i+1][0])-int(b[i][0])==1:
    cnt=max(cnt,b[i+1][1]+b[i][1])
  else:
    cnt=max(cnt,b[i])
if int(b[len(b)-1][0])-int(b[len(b)-2][0])==1:
  cnt=max(cnt,b[len(b)-1][1]-b[len(b)-2][1])
else:
  cnt=max(cnt,max(b[len(b)-1][1],b[len(b)-2][1]))
print(cnt)

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
A=collections.Counter(a)
b=list(A.values())
b.sort()
lst=[]
for i in range(len(b)-1):
  lst.append(b[i]+b[i+1])
print(max(lst))

Submission status: Runtime Error

Solution code:
N = int(input())
arr = list(map(int, input().split()))
arr2 = [0]*(max(arr)+1)
if max(arr) == 1:
    print(len(arr))
    exit()
for i in range(N):
    arr2[arr[i]] += 1
ans = arr2[1] + arr2[2] + arr2[3]
tmp = ans
for i in range(4,len(arr2)):
    tmp = tmp - arr2[i-3] + arr2[i]
    if ans < tmp:
        ans = tmp
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
arr = list(map(int, input().split()))
arr2 = [0]*(max(arr)+1)
if len(arr2) == 3:
    arr2 = [0]*4
for i in range(N):
    arr2[arr[i]] += 1
ans = arr2[1] + arr2[2] + arr2[3]
tmp = ans
for i in range(4,len(arr2)):
    tmp = tmp - arr2[i-3] + arr2[i]
    if ans < tmp:
        ans = tmp
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
arr = list(map(int, input().split()))
arr2 = [0]*(max(arr)+1)
for i in range(N):
    arr2[arr[i]] += 1
ans = arr2[1] + arr2[2] + arr2[3]
tmp = ans
for i in range(4,len(arr2)):
    tmp = tmp - arr2[i-3] + arr2[i]
    if ans < tmp:
        ans = tmp
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = [0]*(N+10)
for a in A:
    for i in range(3): M[a+i]+=1
print(max(M))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
if n == 1:
    print(1)
    exit()

a.sort()
li = []
count = 1
for i in range(n-1):
    if a[i] == a[i+1]:
        count += 1
    else:
        li.append(count)
        count = 1

li.sort()
count2 = 0

if len(li) == 1:
    print(li[0])
    exit()
elif len(li) == 2:
    if abs(a[0] - a[-1]) <= 2:
        print(li[0] + li[1])
    else:
        print(max(li[0], li[1]))
else:

    for i in range(len(li)-2):
        x = li[i] + li[i+1] + li[i+2]
        if x >= count2:
            count2 = x

    print(x)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
if n == 1:
    print(1)
    exit()

a.sort()
li = []
count = 1
for i in range(n-1):
    if a[i] == a[i+1]:
        count += 1
    else:
        li.append(count)
        count = 1

li.sort()
count2 = 0
for i in range(len(li)-2):
    x = li[i] + li[i+1] + li[i+2]
    if x >= count2:
        count2 = x

print(x)

Submission status: Runtime Error

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

i = 0
three_num = list()
while i + 2 < n:
    three_num.append(array.count(i) + array.count(i + 1) + array.count(i + 2))
    i += 1
print(max(three_num))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().split(' ')]
A.sort()
B = [0]*(A[N-1]-A[0]+3)

for a in A:
    B[a] += 1
    B[a-1] += 1
    B[a+1] += 1
print(max(B))

Submission status: Runtime Error

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

    c = [0] * (100000 + 1)
    for ai in A:
        c[ai+1] += 1
        c[ai] += 1
        c[ai+2] += 1

    print(max(c))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N=int(input())
a=list(map(int,input().split()))
m=max(a)
c=[0]*(m+1)

for i in a:
    c[i]=c[i]+1
T=c[0]+c[1]+c[2]
for i in range(m):
    T=max(T,c[i-1]+c[i]+c[i+1])
print(T)

Submission status: Runtime Error

Solution code:
N=int(input())
A=sorted(list(map(int,input().split())))
C=[0]*(max(A)+1)

for i in A:
    C[i]+=1

if len(C)==0:
    print(C[0])
else:
    T=max(C[0]+C[1],C[-1]+C[-2])
    for i in range(1,max(A)):
        T=max(T,C[i-1]+C[i]+C[i+1])
    print(T)

Submission status: Runtime Error

Solution code:
N=int(input())
A=sorted(list(map(int,input().split())))
C=[0]*(max(A)+1)

for i in A:
    C[i]+=1

T=max(C[0]+C[1],C[-1]+C[-2])
for i in range(1,max(A)):
    T=max(T,C[i-1]+C[i]+C[i+1])

print(T)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
flag = 1
cur0 = 0
cur1 = 0
cur2 = 0
cnt = 0
for i in range(1,N):
    if A[i]>A[i-1]:
        flag += 1
        if flag==1:
            cur1 = i
        elif flag==2:
            cur2 = i
        elif flag==3:
            cnt = max(cnt,i-cur0)
            cur0 = cur1
            cur1 = cur2
            flag -= 1
            cur2 = i
cnt = max(cnt,n-cur0)
print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
flag = 1
cur0 = 0
cur1 = 0
cur2 = 0
cnt = 0
for i in range(1,N):
    if A[i]>A[i-1]:
        flag += 1
        if flag==1:
            cur1 = i
        elif flag==2:
            cur2 = i
        elif flag==3:
            cnt = max(cnt,i-cur0)
            cur0 = cur1
            cur1 = cur2
            flag -= 1
            cur2 = i
#     print("cnt({})={}".format(i,cnt))
cnt = max(cnt,n-cur0)
print(cnt)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
CNT=[]
cnt=0
for i in range(n-1):
  for j in range(n-i):
    if a[i+j]-a[i]<2:
      cnt+=1
    else:
      CNT.append(cnt)
      cnt-=cnt
      break
print(max(CNT))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
CNT=[]
cnt=0
for i in range(n-1):
  cnt=0
  for j in range(n-i):
    if a[i+j]-a[i]<2:
      cnt+=1
    else:
      CNT.append(cnt)
      break
print(max(CNT))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

cnt = [0] * 100000
for i in a:
    cnt[i] += 1
    cnt[i+1] += 1
    cnt[i-1] += 1

print(max(cnt))

Submission status: Runtime Error

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

l=[0]*(max(a)+1)
for i in range(n):
    l[a[i]-1]+=1
#print(l)
ans=0
for i in range(len(l)-2):
    ans=max(ans,l[i]+l[i+1]+l[i+2])
ans=max(ans,l[0]+l[1],l[-1]+l[-2])
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))
cnt = [0]*100002
for a in A:
  cnt[a-1]+=1
  cnt[a]+=1
  cnt[a+1]+=1
print(max(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
ary = [0 for _ in range(10**5)]
​
for i in range(n):
    if a[i] > 1:
        ary[a[i]-2] += 1
        ary[a[i]-1] += 1
    ary[a[i]] += 1
​
print(max(ary))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
ary = [0 for _ in range(10**5)]

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

print(max(ary))

Submission status: Runtime Error

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

Submission status: Runtime Error

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
i = 1
for a in a_unique[1:-1]:
    val = np.sum(a_s==a)
    if (a_unique[i-1]+1==a):
        val += np.sum(a_s==a_unique[i-1])
            
    if (a_unique[i+1]-1==a):
        val += np.sum(a_s==a_unique[i+1])
    
    if val > ans:
        ans = val
    
    i += 1

#i=0
val = np.sum(a_s==a_unique[0])
val += np.sum(a_s==a_unique[1])
if val > ans:
    ans = val   

#i=len(a_unique)-1
val = np.sum(a_s==a_unique[-1])
val += np.sum(a_s==a_unique[-2])
if val > ans:
    ans = val   

#     if ans >= sum(a_counts[i:]):
#         break
        
print(ans)

Submission status: Runtime Error

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_s):
    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: Runtime Error

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: Runtime Error

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 += 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: Runtime Error

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)&(a_unique[i-1]+1==a_unique[i]):
        val += a_counts[i-1]
            
    if (i<len(a_unique)-1)&(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: Runtime Error

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, a_counts = np.unique(a_s, return_counts=True)

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: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
lcount=[]
count=0
now=l[0]
for i in range(n):
  if now==l[i]:
    count+=1
  else:
    lcount.append([count,now])
    count=1
    now=l[i]
if count!=1:
  lcount.append([count,now])
if len(lcount)==1:
  print(n)
elif len(lcount)==2:
  l1=lcount[0][0]
  l2=lcount[1][0]
  if lcount[1][1]-lcount[0][1]==1:
    print(l1+l2)
  else:
    print(max(l1,l2))
else:
  count=0
  for i in range(1,len(lcount)-1):
    scount=0
    scount+=lcount[i][0]
    if lcount[i][1]-lcount[i-1][1]==1:
      scount+=lcount[i-1][0]
    if lcount[i][1]-lcount[i+1][1]==-1:
      scount+=lcount[i+1][0]
    if scount>count:
      count=scount
  count1=lcount[0][0]
  if lcount[1][1]-lcount[0][1]==1:
    count1+=lcount[1][0]
  count2=lcount[-1][0]
  if lcount[-2][1]-lcount[-1][1]==-1:
    count2+=lcount[-2][0]
  print(max(count,count1,count2))

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
lcount=[]
count=0
now=l[0]
for i in range(n):
  if now==l[i]:
    count+=1
  else:
    lcount.append([count,now])
    count=1
    now=l[i]
if count!=1:
  lcount.append([count,now])
count=0
for i in range(1,len(lcount)-1):
  scount=0
  scount+=lcount[i][0]
  if lcount[i][1]-lcount[i-1][1]==1:
    scount+=lcount[i-1][0]
  if lcount[i][1]-lcount[i+1][1]==-1:
    scount+=lcount[i+1][0]
  if scount>count:
    count=scount
count1=lcount[0][0]
if lcount[1][1]-lcount[0][1]==1:
  count1+=lcount[1][0]
count2=lcount[-1][0]
if lcount[-2][1]-lcount[-1][1]==-1:
  count2+=lcount[-2][0]
print(max(count,count1,count2))

Submission status: Runtime Error

Solution code:
import counter

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 = s.collections.Counter(1)
        current_ans = c[start]+c[start+1]+c[start+2]
        max_ans = max(current_ans,max_ans)
    print(max_ans)

Submission status: Runtime Error

Solution code:
import counter

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

Submission status: Runtime Error

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

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

a.sort()
l = 0
r = 0
ans = 0
cnt = [0, 0, 0]
while l < n and r < n:
    a_l = {a[l] - 1, a[l], a[l] + 1}
    a_r = {a[r] - 1, a[r], a[r] + 1}
    l_r = a_l & a_r

    if l_r:
        for ele in l_r:
            diff = ele - a[l]
            if diff == 0:
                cnt[1] += 1
            elif diff < 0:
                cnt[0] += 1
            else:
                cnt[2] += 1
        r += 1

    else:
        ans = max(ans, max(cnt))
        l += 1
        if l < n:
            diff = a[l] - a[l-1]
            if diff == 0:
                cnt = cnt
            elif diff == 1:
                cnt = cnt[1:] + [0]
            elif diff == 2:
                cnt = cnt[2] + [0, 0]
            else:
                cnt = [0, 0, 0]

print(ans)