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: Accepted

Solution code:
from collections import Counter

N = int(input())
listA = [int(_) for _ in input().split()]
listA_plus = [-1 for i in range(N)]
listA_minus = [-1 for i in range(N)]
for i in range(N):
    listA_plus[i] = listA[i] + 1
    listA_minus[i] = listA[i] - 1  
list_all = listA + listA_plus + listA_minus
count = Counter(list_all)
top = count.most_common(1)
print(top[0][1])

Submission status: Accepted

Solution code:
N = int(input())
k = []
for a in input().split():
    a = int(a)
    b = a - 1
    c = a + 1
    k += [a,b,c]
from collections import Counter
print(Counter(k).most_common(1)[0][1])

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = [0] * 100002
m = 0
for i in range(N):
    for j in range(3):
        b[a[i] + j] += 1
        if b[a[i] + j] > m:
            m = b[a[i] + j]
print(m)

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    _ = int(input())

    d = defaultdict(lambda: 0)
    for a in [int(i) for i in input().split()]:
        d[a-1] += 1
        d[a] += 1
        d[a+1] += 1
    print(sorted(d.items(), key=lambda x: x[1], reverse=True)[0][1])
        

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
As = list(map(int, input().split()))
box = []

for a in As:
    box.append(a)
    box.append(a+1)
    box.append(a-1)
    
cnt = Counter(box).most_common(1)
print(cnt[0][1])

Submission status: Accepted

Solution code:
from collections import Counter

N = map(int, input())

cnt = Counter()

a = input().split()
for v in a:
    cnt[str(int(v) - 1)] += 1
    cnt[v] += 1
    cnt[str(int(v) + 1)] += 1

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

Submission status: Accepted

Solution code:
N = int(input())
d = dict()
for a in map(int,input().split()):
  if a-1 in d:
    d[a-1] += 1
  else:
    d[a-1] = 1
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
  if a+1 in d:
    d[a+1] += 1
  else:
    d[a+1] = 1
print(max(d.values()))

Submission status: Accepted

Solution code:
N = int(input())
src = list(map(int, input().split()))
MAX = 10**5

counts = [0 for i in range(MAX+1)]
for a in src:
    if a > 0: counts[a-1] += 1
    counts[a] += 1
    counts[a+1] += 1

print(max(counts))

Submission status: Accepted

Solution code:
temp = input().split(" ")
n = int(temp[0])
inp = input().split(" ")
nums = [0 for a in range(100003)]
for a in range(n):
    nums[int(inp[a])+1]+=1
    nums[int(inp[a])+2]+=1
    nums[int(inp[a])]+=1
print(max(nums))

Submission status: Accepted

Solution code:
from sys import stdin
di = {}
n = int(stdin.readline())
a = map(int,stdin.readline().split())
for i in a:
 di[i] = di.get(i,0) + 1
 di[i-1] = di.get(i-1,0) + 1
 di[i+1] = di.get(i+1,0) + 1
ans = -5
for i in di:
 if di[i] > di.get(ans,0):
  ans = i
print di[ans]

Submission status: Accepted

Solution code:
# coding: utf-8
def get_ln_inputs():
    return input().split()


def get_ln_int_inputs():
    return list(map(int, get_ln_inputs()))


def main():
    A_MAX = 10 ** 5

    N = get_ln_int_inputs()[0]
    a = get_ln_int_inputs()
    counts = [0 for _ in range(A_MAX)]

    for num in a:
        counts[num] += 1
    
    max_count = 0
    for target in range(1, A_MAX - 1):
        count = counts[target - 1] + counts[target] + counts[target + 1]
        max_count = max(count, max_count)

    print(max_count)

main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
f = [0 for x in range(10**5 + 10)]
for i in a:
    f[i] += 1
    f[i + 1] += 1
    f[i - 1] += 1


print(max(enumerate(f), key=lambda x: x[1])[1])

Submission status: Accepted

Solution code:
from collections import  Counter
N =int(input())

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

c = Counter(a)
new_c = Counter(a)
for key,val in c.items():
    new_c[key-1] +=val
    new_c[key+1] += val

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

Submission status: Runtime Error

Solution code:
N,*A  =map(int,open(0).read().split())

L = [0 for i in range(N+3)]

for a in A:
  L[a]+=1

ans = 0
for i in range(N+3):
  S = sum(L[i:i+3])
  if ans < S:
    ans = S
  
print(ans)

Submission status: Runtime Error

Solution code:
N,*A  =map(int,open(0).read().split())

L = [0 for i in range(N+3)]

for a in A:
  L[a]+=1

ans = 0
for i in range(N+2):
  S = sum(L[i:i+3])
  if ans < S:
    ans = S
  
print(ans)

Submission status: Runtime Error

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

dp=[0 for n in range(max(a)+1)]
for n in range(N):
    dp[a[n]]+=1

ans=0
for n in range(len(dp)):
    if n==0:
        ans=max(ans,a[0]+a[1])
    elif n==N-1:
        ans=max(ans,a[N-2]+a[N-1])
    else:
        ans=max(ans,dp[n-1]+dp[n]+dp[n+1])

print(ans)

Submission status: Runtime Error

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

dp=[0 for n in range(max(a))]
for n in range(N):
    dp[a[n]-1]+=1

ans=0
for n in range(1,len(dp)-1):
    ans=max(ans,dp[n-1]+dp[n]+dp[n+1])

print(ans)

Submission status: Runtime Error

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

M = max(a)

def counter(x):
    cnt = 0
    for i in range(n):
        if a[i] == x or a[i] - 1 == x or a[i] + 1 == x:
            cnt += 1
    return cnt

cnt_list =[]
for j in range(M):
    cnt_list.append(counter(j))

print(max(cnt_list))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

t = [0] * (max(a) + 1)
for v in a:
    t[v] += 1

if max(a) <= 1:
    print(t[0] + t[1])
    sys.exit(0)

ans = 0
for i in range(0, max(a) - 1):
    ans = max(ans, t[i] + t[i+1] + t[i+2])

print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

t = [0] * (max(a) + 1)
for v in a:
    t[v] += 1

if max(a) <= 1:
    pritn(t[0] + t[1])
    sys.exit(0)

ans = 0
for i in range(0, max(a) - 1):
    ans = max(ans, t[i] + t[i+1] + t[i+2])

print(ans)

Submission status: Runtime Error

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

if n == 1:
    print(1)
else:
    m = max(al)
    num = [0]*m
    for a in al:
        num[a-1] += 1

    ans = 0
    for i in range(m-3):
        ans = max(ans, sum(num[i:i+3]))

    print(ans)

Submission status: Runtime Error

Solution code:
import statistics
import math

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

a.sort()
num = a[N-1]

cnt_list = []

cnt = 0
cnt_v = 0
for j in range(num+1):
  for i in range(cnt_v,N):
    if a[i] == j:
      cnt += 1
      cnt_v += 1
  cnt_list.append(cnt)
  cnt = 0
  
sub = []
for i in range(num-1):
  sub.append(cnt_list[i]+cnt_list[i+1]+cnt_list[i+2])
  
print(max(sub))

Submission status: Runtime Error

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

a.sort()
num = a[N-1]

cnt_list = []

cnt = 0
for j in range(num+1):
  for i in range(N):
    if a[i] == j:
      cnt += 1
  cnt_list.append(cnt)
  cnt = 0
    
sub = []
for i in range(num-1):
  sub.append(cnt_list[i]+cnt_list[i+1]+cnt_list[i+2])
  
print(max(sub))

Submission status: Runtime Error

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

if N == 1:
    print(1)
    sys.exit(0)
    
cnt = [0 for _ in range(10**5)]
for a in A:
    if a == 0:
        cnt[a] += 1
        cnt[a+1] += 1
    else:
        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()))
d = {}
for a in A:
  for i in range(a - 1, a + 2)
  d[i] = d.get(i, 0) + 1
x = sorted(d.values())
print(max(x))

Submission status: Runtime Error

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

b.sort()
print(b[-1])

Submission status: Runtime Error

Solution code:
N, *A = map(int, open(0).read().split())

import numpy as np

max_a = max(A)

mat = np.array([0]*max_a)

for a in A:
    mat[max(a-2, 0):min(a+1,max_a)] += 1

print(max(mat))

Submission status: Runtime Error

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

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

list = []
for i in range(N):
    list += [a[i]-1,a[i],a[i]+1]
num = []
for i in range(min(a),max(a)):
    num.append(list.count(i))
print(max(num))

Submission status: Runtime Error

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

print(max(num))

Submission status: Runtime Error

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
s1 = len(a_list)
a_set = list(set(a_list))
s2 = len(a_set)
max_cnt = 0

if s1 == 1 :
    max_cnt = 1
elif s1 == 2 :
    if s2 == 1 :
        max_cnt = 2
    else :
        max_cnt = 1
else:
    cnt0 = a_list.count(a_set[0])
    cnt1 = a_list.count(a_set[1])
    
    for i in range(2, len(a_set)):
        cnt2 = a_list.count(a_set[i])
        cnt = cnt0 + cnt1 + cnt2
        
        if cnt > max_cnt :
            max_cnt = cnt
            
        cnt0 = cnt1
        cnt1 = cnt2

print(max_cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
s = sorted(a)
k = s[(n//2)-1]
ans = 0
for i in s:
  if i == s[k] or i == s[k]-1 or i ==s[k]+1:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

d = defaultdict(int)

for x in arr:
    d[x] += 1

ans = []
for i in range(1, max(arr)):
    ans.append(d[i - 1] + d[i] + d[i + 1])

print(max(ans))

Submission status: Runtime Error

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

d = defaultdict(int)

for x in arr:
    d[x] += 1

ans = []
for i in range(1, max(arr)):
    ans.append(d[i - 1] + d[i] + d[i + 1])

print(max(ans))

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
l = sorted(list(map(int, input().split())) )
c = collections.Counter(l)
L = [0]*10**5
M = [0]*10**5

for x,y in c.items():
    L[x-1] += y

M[0] = L[0]
M[n] = L[n]
for i in range(1,10**5-1):
    M[i] = L[i-1] + L[i] + L[i+1]
print(max(M))

Submission status: Runtime Error

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

cnt = [0]*10**5+5
for i in a:
    cnt[i] += 1

ans = 0
for i in range(1, 10**5+3):
    ans = max(ans, sum(cnt[i-1:i+2]))
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input(),split()))
s = [0]*max(a)+2
for i in a:
    i += 1
    s[i-1] += 1
    s[i] += 1
    s[i+1] += 1

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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:
#
# abc072 c
#

import sys
from io import StringIO
import unittest


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

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

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

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


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

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

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

    print(ans)


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

Submission status: Runtime Error

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

    lists = [0] * ((10**5)+2)

    for i in range(a):
        lists[v] += 1
        lists[v+1] += 1
        lists[v-1] += 1

    print(max(lists))    

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

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

    lists = [0] * ((10**5)+2)

    for i in range(a):
        lists[v] += 1
        lists[v+1] += 1
        lists[v-1] += 1

    print(max(lists))    

if __name__ = "__main__":
    solve()

Submission status: Runtime Error

Solution code:
import collections

def main():
  N = int(input())
  A = [int(a) for a in input().split(" ")]
  CA = collections.Counter(A)
  minA = min(A)
  maxA = max(A)
  X = [CA[i] for i in range(minA, maxA + 1)]
  if len(X) == 1:
    print(X[0])
    return 0
  if len(X) == 2:
    print(X[0] + X[1])
    
  Y = [X[j] + X[j+1] + X[j+2] for j in range(len(X) - 2)]
  print(max(Y))

main()

Submission status: Runtime Error

Solution code:
def main():
  N = int(input())
  A = [int(a) for a in input().split(" ")]
  minA = min(A)
  maxA = max(A)
  X = [A.count(i) for i in range(minA, maxA + 1)]
  if len(X) == 1:
    print(X[0])
    return 0
  if len(X) == 2:
    print(X[0] + X[1])
    
  Y = [X[j] + X[j+1] + X[j+2] for j in range(len(X) - 2)]
  print(max(Y))

main()

Submission status: Runtime Error

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

mx=0
for i in D:
    cnt=0
    for j in range(N):
        if i==A[j]:
            cnt+=1
        elif i==B[j]:
            cnt+=1
        elif i==C[j]:
            cnt+=1
    mx=max(mx,cnt)
print(mx)

Submission status: Runtime Error

Solution code:
import collections
n,cc = raw_input(),collections.Counter(map(int, raw_input().split()))
print max([cc[k] + cc[k+1] + cc[k-1] for k in cc] or [0)

Submission status: Runtime Error

Solution code:
n,cc = raw_input(),collections.Counter(map(int, raw_input().split()))
print max([cc[k] + cc[k+1] + cc[k-1] for k in cc] or [0)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

for i in a:
    cnt[i] += 1
    cnt[i+1] += 1
    cnt[i+2] += 1
    
print(max(cnt))

Submission status: Runtime Error

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

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

a.sort()
a.append(-1)

b = []
c = []
cn = 1

for i in range(n):
  if a[i] != a[i+1]:
    b.append(cn)
    c.append(a[i])
    cn = 1
  else:
    cn += 1

#print(a)
#print(b)
#print(c)

k = []
k_ = []
for i in range(1,len(b)-1):
  k_.append(c[i])
  k.append(b[i-1]+b[i]+b[i+1])

kk = zip(k,k_)
kk = sorted(kk)
k,k_ = zip(*kk)
print(k[-1])

Submission status: Runtime Error

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

def func(a):
  count = [0] * (max(a)+1)

  for i in a:
      count[i] += 1

  max_n = 0
  for j in range(1, len(count)-1):
      max_n = max(max_n, count[j] + count[j-1] + count[j+1])
  max_n = max(max_n, count[-1] + count[-2])
  
  return max_n

ptint(n if len(set(a)) == 1 else func(a))

Submission status: Runtime Error

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

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

for i in a:
    count[i] += 1

max_n = 0
for j in range(1, len(count)-1):
    max_n = max(max_n, count[j] + count[j-1] + count[j+1])
max_n = max(max_n, count[-1] + count[-2])

print(max_n)

Submission status: Runtime Error

Solution code:
IN = iter(Input.split('\n')).__next__
def input():
    return IN()

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

result_list = []
for a in l:
    result_list.extend([a-1,a,a+1])
    
result_list

import collections

count = collections.Counter(result_list) # dictionary としてCounter({5: 1, 1: 3, 3: 2, 2: 2, 4: 2})
hindo_jun = count.most_common() 

print(hindo_jun[0][1])

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
!/usr/bin/env python3

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

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

if n >= 3:
    d = [0 for _ in range(100001)]
    for i in range(n):
        d[a[i]] += 1
    ans = 0 
    for i in range(n-2):
        tmp = d[i] + d[i+1] + d[i+2]
        if ans <= tmp:
            ans = tmp 

print(ans)

Submission status: Runtime Error

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

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

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

if n >= 3:
    d = [0 for _ in range(n)]
    for i in range(n):
        d[a[i]] += 1
    ans = 0 
    for i in range(n-2):
        tmp = d[i] + d[i+1] + d[i+2]
        if ans <= tmp:
            ans = tmp 

print(ans)

Submission status: Runtime Error

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

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

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

if n >= 3:
    d = [0 for _ in range(10)]
    for i in range(n):
        d[a[i]] += 1
    ans = 0 
    for i in range(n-2):
        tmp = d[i] + d[i+1] + d[i+2]
        if ans <= tmp:
            ans = tmp 

    print(ans)

Submission status: Runtime Error

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

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

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

if n >= 3:
    d = [0 for _ in range(10)]
    for i in range(n):
        d[a[i]] += 1

    ans = 0 
    for i in range(n-2):
        tmp = d[i] + d[i+1] + d[i+2]
        if ans <= tmp:
            ans = tmp 

print(ans)

Submission status: Runtime Error

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

nums = [0]*(max(a)+1)
for i in a: nums[i] += 1

if n == 1:
  print(1)
  exit()
elif n == 2:
  if abs(a[0]-a[1]) <= 2: print(2)
  else: print(1)
  exit()
    
ans = 0
for i in range(1,n-1):
  if ans < nums[i-1] + nums[i] + nums[i+1]:
    ans = nums[i-1] + nums[i] + nums[i+1]

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
l = [0]*10**5+2

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

print(max(l))

Submission status: Runtime Error

Solution code:
N = int(input())
a = map(int, input().split())
l = [0]*10**5+2
ans = 0
num = 0

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


print(max(l))

Submission status: Runtime Error

Solution code:
N = int(input())
a = map(int, input().split())
l = [0]*10**5
ans = 0
num = 0

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

print(max(l))

Submission status: Runtime Error

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

l=[0]*10**5+2

for v in a:
    l[v]+=1
    l[v+1]+=1
    l[v+2]+=1

print(max(l))

Submission status: Runtime Error

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

l=sorted(a)

# N=10
# l=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
if N>=10**4:
    math.
else:
    pass

ans=1

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

Submission status: Runtime Error

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

l=sorted(a)

# N=10
# l=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
if N>=10**3:
    math.


ans=1

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

Submission status: Runtime Error

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

l=sorted(a)

ans=1
targetindex=0
t=l[targetindex]

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

Submission status: Runtime Error

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

l=sorted(a)

ans=1
targetindex=0
t=l[targetindex]

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

Submission status: Runtime Error

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

num=[0]*(max(a))
for i in a:
  num[i-1]+=1
#print(num)
mx=0
for i in range(1,max(a)-1):
  #print(num[i-1:i+2])
  m=sum(num[i-1:i+2])
  if m>mx:
    mx=m

print(mx)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-06-26 15:12:37 +0900
# LastModified: 2020-06-26 15:31:15 +0900
#


import os
import sys
from collections import Counter
# import numpy as np
# import pandas as pd


def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    cnt_list = Counter(a)

    a_max = a[-1]
    a_min = a[0]
    cnt_max = 0
    for center in range(a_min-1, a_max+2):
        if center in cnt_list.keys():
            cnt = cnt_list[center]
        if center-1 in cnt_list.keys():
            cnt += cnt_list[center-1]
        if center+1 in cnt_list.keys():
            cnt += cnt_list[center+1]
        if cnt > cnt_max:
            cnt_max = cnt
    print(cnt_max)



if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

count=[0 for _ in range(max(A)+1)]
for i in range(n):
  count[A[i]]+=1

  
answer=0
for i in range(0,n-3):
  tmp=int(count[i])+int(count[i+1])+int(count[i+2])
  if tmp>answer:
    answer=tmp
    
print(answer)

Submission status: Runtime Error

Solution code:
N = int(input())
a = [map(int, input().split())]
x = [0] * (10**5+2)

for i in a:
    x[i] += 1
    x[i+1] += 1
    x[i+2] += 1 
    
print(max(a))

Submission status: Runtime Error

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

for i in a:
    a[i] += 1
    a[i+1] += 1
    a[i+2] +=1 
    
print(max(a))

Submission status: Runtime Error

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

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

al = [0]*(max(a)+1)
for i in a:
    al[i] += 1
index = al.index(max(al))

if index == min(a):
    index += 1
elif index == max(a):
    index -= 1

print(al[index-1] + al[index] + al[index+1])

Submission status: Runtime Error

Solution code:
x = int(input())
a = list(map(int, input().split()))
al = [0]*(max(a)+1)
for i in a:
    al[i] += 1
index = al.index(max(al))

if index == 1:
    index += 1
elif index == max(a)-1:
    index -= 1

if x == 1:
    print(x)
elif x == 2:
    if abs(a[0] - a[1]) <= 1:
        print(2)
    else:
        print(1) 
else:
    print(al[index-1] + al[index] + al[index+1])

Submission status: Runtime Error

Solution code:
from collections import Counter


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

nc = Counter(A)
C = []
for i in range(1, max(A)):
    c = nc[i - 1] + nc[i] + nc[i + 1]
    C.append(c)

print(max(C))

Submission status: Runtime Error

Solution code:
from statistics import mode

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

aa=[]

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

print(aa.count(mode(aa)))

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    a = list(map(int, input().split()))
    num_dict = {}
    a.sort()
    a_max = a[N-1]
    temp = a[0]
    sum = 1

    for i in range(1,N):
        if temp == a[i]:
            sum += 1
        else:
            num_dict[temp] = sum
            sum = 1
            temp = a[i]
    num_dict[a[N-1]] = sum

    ans = 0
    judge = 0
    for j in range(1, a_max):
        #j=1のときは特別
        if j == 1 and j in num_dict:
            if j+1 in num_dict:
                judge = num_dict[j] + num_dict[j+1]
                ans = judge
                continue
            else:
                judge = num_dict[j]
                ans = judge
                continue

        if (j in num_dict) and (j-1 in num_dict) and (j+1 in num_dict):
            if judge <= (num_dict[j-1] + num_dict[j] + num_dict[j+1]):
                judge = num_dict[j-1] + num_dict[j] + num_dict[j+1]
                ans = judge
                continue
            else:
                continue

        elif (j in num_dict) and (j-1 in num_dict):
            if judge <= (num_dict[j-1] + num_dict[j]):
                judge = num_dict[j-1] + num_dict[j]
                ans = judge
                cintinue
            else:
                continue

        elif (j in num_dict) and (j+1 in num_dict):
            if judge <= (num_dict[j+1] + num_dict[j]):
                judge = num_dict[j+1] + num_dict[j]
                ans = judge
                cintinue
            else:
                continue

        elif (j-1 in num_dict) and (j+1 in num_dict):
            if judge <= (num_dict[j+1] + num_dict[j-1]):
                judge = num_dict[j+1] + num_dict[j-1]
                ans = judge
                cintinue
            else:
                continue

        elif j in num_dict:
            if judge <= (num_dict[j]):
                judge = num_dict[j]
                ans = judge
                cintinue
            else:
                continue

        else:
            continue

    if a_max-1 in num_dict:
        if judge <= num_dict[a_max-1] + num_dict[a_max]:
            ans = num_dict[a_max-1] + num_dict[a_max]
    else:
        if judge <= num_dict[a_max]:
            ans = num_dict[a_max]
    return ans

print(main())

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    a = list(map(int, input().split()))
    num_dict = {}
    a.sort()
    a_max = a[N-1]
    temp = a[0]
    sum = 1

    for i in range(1,N):
        if temp == a[i]:
            sum += 1
        else:
            num_dict[temp] = sum
            sum = 1
            temp = a[i]
    num_dict[a[N-1]] = sum
    
    ans = 0
    judge = 0
    for j in range(1, a_max):
        #j=1のときは特別
        if j == 1 and j in num_dict:
            if j+1 in num_dict:
                judge = num_dict[j] + num_dict[j+1]
                ans = judge
                continue
            else:
                judge = num_dict[j]
                ans = judge
                continue

        if (j in num_dict) and (j-1 in num_dict) and (j+1 in num_dict):
            if judge <= (num_dict[j-1] + num_dict[j] + num_dict[j+1]):
                judge = num_dict[j-1] + num_dict[j] + num_dict[j+1]
                ans = judge
                continue
            else:
                continue

        elif (j in num_dict) and (j-1 in num_dict):
            if judge <= (num_dict[j-1] + num_dict[j]):
                judge = num_dict[j-1] + num_dict[j]
                ans = judug
                cintinue
            else:
                continue

        elif (j in num_dict) and (j+1 in num_dict):
            if judge <= (num_dict[j+1] + num_dict[j]):
                judge = num_dict[j+1] + num_dict[j]
                ans = judug
                cintinue
            else:
                continue

        elif (j-1 in num_dict) and (j+1 in num_dict):
            if judge <= (num_dict[j+1] + num_dict[j-1]):
                judge = num_dict[j+1] + num_dict[j-1]
                ans = judug
                cintinue
            else:
                continue

        elif j in num_dict:
            if judge <= (num_dict[j]):
                judge = num_dict[j]
                ans = judug
                cintinue
            else:
                continue

        else:
            continue

    if a_max-1 in num_dict:
        if judge <= num_dict[a_max-1] + num_dict[a_max]:
            ans = num_dict[a_max-1] + num_dict[a_max]
    else:
        if judge <= num_dict[a_max]:
            ans = num_dict[a_max]
    return ans

print(main())

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().split()))
c = [0]*(max(a)+1)
max_num = 0
for i in a:
  c[i] += 1
for x in range(max(a)+1):
  if max_num < (c[x-1]) + (c[x]) + (c[x+1]):
      max_num = (c[x-1]) + (c[x]) + (c[x+1])
print(max_num)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().split()))
c = [0]*(max(a)+1)
max_num = 0
for i in a:
  c[i] += 1
for x in range(1,max(a)+1):
  if max_num < (c[x-1]) + (c[x]) + (c[x+1]):
      max_num = (c[x-1]) + (c[x]) + (c[x+1])
print(max_num)