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: Wrong Answer

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=set(a)
al=list(al)
l=len(al)
a1=a.count(al[0])#一個前の合計
if l>=2:
    a2=a.count(al[1])#現在の合計
if l>=3:
    a3=a.count(al[2])#一つ先の合計
if l==1:
    print(a1)
    exit()
elif l==2:
    if abs(al[0]-al[1])<=2:
        print(a1+a2)
        exit()
    else:
        print(max(a1,a2))
        exit()
count=0
result=0#最大値
al.append(" ")
for i in range(1,l-2):
    count=a1+a2+a3
    if count>result:
        result=count
    a1=a2
    a2=a3
    a3=a.count(al[i+2])
print(result)

Submission status: Wrong Answer

Solution code:

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

    ans_lst = [0 for i in range(max(a)+4)]


    for i in a:
        ans_lst[i] += 1
        ans_lst[i+1] += 1
        ans_lst[i-1] += 1



    print(ans_lst)
    print(max(ans_lst))



if __name__ == "__main__":
        main()

Submission status: Wrong Answer

Solution code:

def main():
    n = int(input())
    a = list(map(int,input().split()))
    ans_lst = [0 for i in range(max(a)+2)]

    for i in a:
        ans_lst[i] += 1
        ans_lst[i+1] += 1
        ans_lst[i-1] += 1

    print(max(ans_lst))



if __name__ == "__main__":
        main()

Submission status: Wrong Answer

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

Amax = max(A)
K = [0] * (Amax+1)

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

ans = 1

for i in range(Amax - 1):
  ans = max(ans, K[i] + K[i+1] + K[i+2])

print(ans)

Submission status: Wrong Answer

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

Amax = max(A)
K = [0] * (Amax+1)

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

ans = 0

for i in range(Amax - 1):
  ans = max(ans, K[i] + K[i+1] + K[i+2])

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
def merge(x):
    mid = len(x)
    if mid > 1:
        L = merge(x[:int(mid/2)])
        R = merge(x[int(mid/2):])
        x = []
        while len(L) != 0 and len(R) != 0:
            if L[0] < R[0]:
                x.append(L.pop(0))
            else:
                x.append(R.pop(0))
        if len(L) != 0:
            x.extend(L)
        elif len(R) != 0:
            x.extend(R)
    return x
B = merge(A)
M = max(A)
count_max = 0
flag = 0
for i in range(M):
    count = 0
    tmp = True
    for j in range(flag, N):
        if B[j] == i-1 or B[j] == i+1:
            count += 1
        elif B[j] == i:
            count += 1
            if tmp == True:
                flag = j
                tmp = False
    if count > count_max:
        count_max = count
print(count_max)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
def merge(x):
    mid = len(x)
    if mid > 1:
        L = merge(x[:int(mid/2)])
        R = merge(x[int(mid/2):])
        x = []
        while len(L) != 0 and len(R) != 0:
            if L[0] < R[0]:
                x.append(L.pop(0))
            else:
                x.append(R.pop(0))
        if len(L) != 0:
            x.extend(L)
        elif len(R) != 0:
            x.extend(R)
    return x
B = merge(A)
M = max(A)
count_max = 0
for i in range(M):
    count = 0
    for j in range(N):
        if B[j] == i-1 or B[j] == i+1:
            count += 1
        elif B[j] == i:
            count += 1
    if count > count_max:
        count_max = count
print(count_max)

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    N = int(input())
    A = li_input()

    ans = 1
    Bkt = [0] * 100001

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

    for i in range(1, 5):
        ans = max(ans, Bkt[i - 1] + Bkt[i] + Bkt[i + 1])

    print(ans)


main()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
a=int(sum(l)/n)-1
t=filter(lambda x:abs(x)<=1,map(lambda x:x-a,l))
print(len(list(t)))

Submission status: Wrong Answer

Solution code:
N = int(input())

a = [int(x) for x in input().split()]

a_s = sorted(a)
cnt = 0

m_left = 0
m_right = 0

if N % 2 != 0 :
    m_left = a_s[N // 2] - 1
    m_right = a_s[N // 2] + 1
else :
    m_left = a_s[(N // 2) - 1] - 1
    m_right = a_s[N // 2] + 1
    
m_at = -1
max_cnt = 0
    
for m in range(m_left, m_right + 1) :
    cnt = 0
    for i in a_s :
        if m in (i - 1, i, i + 1) :
            cnt += 1
                
    if cnt >= max_cnt :
        max_cnt = cnt
        m_at = m
        
print(max_cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

a = [int(x) for x in input().split()]

a_s = sorted(a)
cnt = 0

m_left = 0
m_right = 0

if N % 2 != 0 :
    m_left = a_s[N // 2] - 1
    m_right = a_s[N // 2] + 2
else :
    m_left = a_s[(N // 2) - 1] - 1
    m_right = a_s[N // 2] + 1
    
m_at = -1
max_cnt = 0
    
for m in range(m_left, m_right + 1) :
    cnt = 0
    for i in a_s :
        if m in (i - 1, i, i + 1) :
            cnt += 1
                
    if cnt >= max_cnt :
        max_cnt = cnt
        m_at = m
        
print(max_cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

a = [int(x) for x in input().split()]

a_s = sorted(a)
cnt = 0

m_left = 0
m_right = 0

if N % 2 != 0 :
    m_left = a_s[N // 2] - 1
    m_right = a_s[N // 2] + 2
else :
    m_left = a_s[(N // 2) - 1] - 1
    m_right = a_s[N // 2] + 1
    
m_at = -1
max_cnt = 0
    
for m in range(m_left, m_right) :
    cnt = 0
    for i in a_s :
        if m in (i - 1, i, i + 1) :
            cnt += 1
                
    if cnt >= max_cnt :
        max_cnt = cnt
        m_at = m
        
print(max_cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
def line_input(f, type):
    return f(map(type, input().split(" ")))

n = input()
a = line_input(list, int)

c = Counter(a)
so = sorted(c)

cnt = [0] * (max(so) + 1)
for idx in range(0, max(so)+1):
    cnt[idx] = cnt[idx-1] + c[idx]

m = 0
for j in range(1, 4):
    for idx in range(len(cnt)-j):
        m = max(m, cnt[idx + j] - cnt[idx])

for idx in range(max(c) + 1):
    m = max(m, cnt[idx])

print(m)

Submission status: Wrong Answer

Solution code:
from collections import Counter
def line_input(f, type):
    return f(map(type, input().split(" ")))

n = input()
a = line_input(list, int)

c = Counter(a)
so = sorted(c)
cnt = [0] * (max(so) + 1)
for idx in range(0, max(so)+1):
    cnt[idx] = cnt[idx-1] + c[idx]

m = 0
for j in range(1, 4):
    for idx in range(len(cnt)-j):
        m = max(m, cnt[idx + j] - cnt[idx])


print(m)

Submission status: Wrong Answer

Solution code:
from collections import Counter
def line_input(f, type):
    return f(map(type, input().split(" ")))

n = input()
a = line_input(list, int)

c = Counter(a)
so = sorted(c)
cnt = [0] * (max(so) + 1)
for idx in range(1, max(so)+1):
    cnt[idx] = cnt[idx-1] + c[idx]

m = 0
for idx in range(len(cnt)-3):
    m = max(m, cnt[idx + 3] - cnt[idx])
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
alist = list(map(int, input().split()))
aset = set(alist)
max_num = 0
X = 0
for x in aset:
    num = len([xx for xx in alist if x == xx])
    if max_num < num:
        max_num = num
        X = x
max_num = 0
for x in [X - 2, X - 1, X, X + 1, X + 2]:
    num = len([xx for xx in alist if x - 1 <= xx <= x + 1])
    max_num = max(max_num, num)
print(max_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
alist = list(map(int, input().split()))
aset = set(alist)
max_num = 0
X = 0
for x in aset:
    num = len([xx for xx in alist if x == xx])
    if max_num < num:
        max_num = num
        X = x
max_num = 0
for x in [X - 1, X, X + 1]:
    num = len([xx for xx in alist if x - 1 <= xx <= x + 1])
    max_num = max(max_num, num)
print(max_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
alist = list(map(int, input().split()))
aset = set(alist)
max_num = 0
xset = set()
for x in aset:
    xset.add(x)
    xset.add(x - 1)
    xset.add(x + 1)
for x in xset:
    num = len([xx for xx in alist if x == xx])
    max_num = max(max_num, num)
print(max_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
alist = list(map(int, input().split()))
aset = set(alist)
max_num = 0
for x in aset:
    num = len([xx for xx in alist if x == xx])
    max_num = max(max_num, num)
print(max_num)

Submission status: Wrong Answer

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

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

A_RANGE = range(0, 10 ** 5)

num_of = [0] * 10 ** 5
for ai in a:
    num_of[ai] += 1

max_X = 0
max_count = max(num_of)
max_count_indexes = [i for i, x in enumerate(num_of) if x == max_count]
for i in max_count_indexes:
    if i + 1 in A_RANGE:
        if i + 2 in A_RANGE:
            max_X = max(num_of[i] + num_of[i + 1] + num_of[i + 2], max_X)
        if i - 1 in A_RANGE:
            max_X = max(num_of[i - 1] + num_of[i] + num_of[i + 1], max_X)
    if i - 1 in A_RANGE:
        if i - 2 in A_RANGE:
            max_X = max(num_of[i - 2] + num_of[i - 1] + num_of[i], max_X)
print(max_X)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[0]*100005

for i in a:
    b[i-1]+=1
    b[i+2]-=1

for i in range(100004):
    b[i+1]+=b[i]

print(max(b))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[0]*100005

for i in a:
    b[i-1]+=1
    b[i+2]-=1

print(max(b))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
bucket=[0]*(max(A)+1)
for number in A:
    bucket[number]+=1
answer=0
for i in range(1,max(A)):
    candidate=bucket[i-1]+bucket[i]+bucket[i+1]
    if candidate>answer:
        answer=candidate
print(answer)

Submission status: Wrong Answer

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

A.sort()
number_of_items=0
for X in range(A[0], A[N-1]+1):
    if (X+1 in A) and (X-1 in A):
        candidate=A.index(X+1)-A.index(X-1)+1
    elif (X+1 in A) and (X in A):
        candidate=A.index(X+1)-A.index(X)+1
    elif (X-1 in A) and (X in A):
        candidate=A.index(X)-A.index(X-1)+1
    else:
        if X in A:
            candidate=A.count(X)
        elif X-1 in A:
            candidate=A.count(X-1)
        elif X+1 in A:
            candidate=A.count(X+1)
        else:
            pass
    if candidate>number_of_items:
        number_of_items=candidate
print(number_of_items)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
a = list(map(int, input().split()))
max_a = max(a)
l = [0] * (max_a + 1)
c = Counter(a)

for k, v in c.items():
    l[k] = v

max_n = 0
for i in range(1, max_a):
    max_n = max(max_n, sum(l[i - 1:i + 2]))
print(max_n)

Submission status: Wrong Answer

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

biggest = 1
for i in range(min(numbers),max(numbers)):
    count = numbers.count(i-1) + numbers.count(i) + numbers.count(i+1)
    if biggest <= count:
        biggest = count
print(biggest)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())

arr = collections.Counter(map(int,raw_input().split())).values()
l = len(arr)


ans = 0

if l > 2:
	for i in range(l-2):
		ans = max(ans,arr[i]+arr[i+1]+arr[i+2])

else :
	ans = sum(arr)

print ans

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
input_list = sorted([int(i) for i in input().split()])
inupt_dict = (Counter(input_list))
result = 0
input_dict_keys = inupt_dict.keys()

for i in range(N-2):
    if i in input_dict_keys:
        if i+1 in input_dict_keys:
            if i+2 in input_dict_keys:
                result = max(result, (inupt_dict[i] + inupt_dict[i+1] + inupt_dict[i+2]))

for i in range(N-1):
    if i in input_dict_keys:
        if i+1 in input_dict_keys:
            result = max(result, (inupt_dict[i] + inupt_dict[i+1]))

for i in range(N-2):
    if i in input_dict_keys:
        result = max(result, inupt_dict[i])

if N == 1:
    result = 1

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
src = list(map(int,input().split()))
ctr = Counter(src)

mx = max(src)
ans = 0
for i in range(mx):
    ans = max(ans, ctr[i] + ctr[i+1] + ctr[i+2])
print(ans)

Submission status: Wrong Answer

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


for i in range(amax + 1):
    aa.append(0)

for i in range(len(a)):
    aa[a[i]] = aa[a[i]] + 1
    
kouho = 1    
for j in range(len(aa) - 2):
    if kouho < aa[j] + aa[j + 1] + aa[j + 2]:
        kouho = aa[j] + aa[j + 1] + aa[j + 2]

print(kouho)

Submission status: Wrong Answer

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

for i in range(amax + 1):
    aa.append(0)

for i in range(len(a)):
    aa[a[i]] = aa[a[i]] + 1
    
kouho = 0    
for j in range(len(aa) - 2):
    if kouho < aa[j] + aa[j + 1] + aa[j + 2]:
        kouho = aa[j] + aa[j + 1] + aa[j + 2]

print(kouho)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
for x in range(n):
    a.append(x+1)
    a.append(x-1)
counter = Counter(a)
for name, cnt in counter.most_common():
    print(cnt)
    break

Submission status: Wrong Answer

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

b = []

for i in range(len(a)):
    s = 0
    for j in range(len(a)):
        if abs(a[i]-a[j]) < 3:
            s = s + 1
        else:
            None
    b.append(s)
            
print(max(b))

Submission status: Wrong Answer

Solution code:
N=int(input())
d,ans={},1

for i in list(map(int,input().split())):
    d[i]=d.get(i,0)+1
d=list(d.values())
t=len(d)-2
if t<0:
    ans=sum(d)
else:    
    for j in range(t):
        s=d[j]+d[j+1]+d[j+2]
        if s>ans:
            ans=s
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
d,ans={},1

for i in list(map(int,input().split())):
    d[i]=d.get(i,0)+1
d=list(d.values())
t=len(d)-2
if t<1:
    ans=sum(d)
else:    
    for j in range(t):
        s=d[j]+d[j+1]+d[j+2]
        if s>ans:
            ans=s
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
d={}
ans=1
for i in list(map(int,input().split())):
    d[i]=d.get(i,0)+1
d=list(d.values())
for j in range(len(d)-2):
    s=d[j]+d[j+1]+d[j+2]
    if s>ans:
        ans=s
print(ans)

Submission status: Wrong Answer

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

for i in range(0, n+2):
  count = 0
  for j in l:
    if j == i or j == i+1 or j == i-1:
      count += 1
  if count > ans:
    ans = count

print(ans)

Submission status: Wrong Answer

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

for i in range(1, n+1):
  count = 0
  for j in l:
    if j == i or j == i+1 or j == i-1:
      count += 1
  if count > ans:
    ans = count

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = [int(i) for i in input().split()]
x,answer = collections.Counter(a),0
for i in range(min(a)+1,max(a)):
	num = 0
	for j in range(i-1,i+2):
		try:
			num += x[j]
		except:
			pass
	if num>answer:
		answer = num
print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
j = np.array([0 for i in range(int(10e5 + 1))])
m = list(map(int, input().split()))
for i in m:
    j[i-1:  i+2] += 1
print(np.max(j))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(int(i) for i in input().split())
mx = max(a)
ans = 0

for i in range(mx):
    tmp = 0
    for j in range(len(a)):
        if i-a[j] == 0:
            tmp+=1
        elif i-a[j] == 1:
            tmp+=1
        elif i-a[j] == -1:
            tmp+=1
    ans = max(tmp,ans)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

num = int(input())

val = [int(x) for x in input().split()]

counter = collections.Counter(val)
counter[100000] = 0
counter[200000] = 0

sort_counter = sorted(counter.items(), key=lambda x:x[0])

array = []

# ○●●●○黒丸の部分を見て、i-1, i, i+1番目を考える
for i in range(1, len(sort_counter)-1):
    res = 0

    # i±1番目がi±1以内か
    if abs(sort_counter[i-1][0])-abs(sort_counter[i][0]) <= 1:
        res += sort_counter[i-1][1]
    res += sort_counter[i][1]
    if abs(sort_counter[i+1][0])-abs(sort_counter[i][0]) <= 1:
        res += sort_counter[i+1][1]
    array.append(res)

print(max(array))

Submission status: Wrong Answer

Solution code:
import collections

num = int(input())

val = [int(x) for x in input().split()]

counter = collections.Counter(val)
counter[100000] = 0
counter[200000] = 0

sort_counter = sorted(counter.items(), key=lambda x:x[0])

array = []

# ○●●●○黒丸の部分を見て、i-1, i, i+1番目を考える
for i in range(1, len(sort_counter)-1):
    res = 0

    # i±1番目がi±1以内か
    if abs(sort_counter[i-1][0]-sort_counter[i][0]) <= 1:
        res += sort_counter[i-1][1]
    res += sort_counter[i][1]
    if abs(sort_counter[i+1][0]-sort_counter[i][0]) <= 1:
        res += sort_counter[i+1][1]
    array.append(res)

print(max(array))

Submission status: Wrong Answer

Solution code:
import collections

num = int(input())

val = [int(x) for x in input().split()]

counter = collections.Counter(val)
counter[100000] = 0
counter[200000] = 0

sort_counter = sorted(counter.items(), key=lambda x:x[0])

array = []

# ○●●●○黒丸の部分を見て、i-1, i, i+1番目を考える
for i in range(1, len(sort_counter)-1):
    res = 0

    # i±1番目がi±1以内か
    if sort_counter[i-1][0]-sort_counter[i][0] <= 1:
        res += sort_counter[i-1][1]
    res += sort_counter[i][1]
    if sort_counter[i+1][0]-sort_counter[i][0] <= 1:
        res += sort_counter[i+1][1]
    array.append(res)

print(max(array))

Submission status: Wrong Answer

Solution code:
import collections

num = int(input())

val = [int(x) for x in input().split()]

counter = collections.Counter(val)
counter[100000] = 0
counter[200000] = 0

sort_counter = sorted(counter.items(), key=lambda x:x[0])

array = []

# ○●●●○黒丸の部分を見て、i-1, i, i+1番目を考える
for i in range(1, len(sort_counter)-1):
    res = 0

    # i±1番目がi±1以内か
    if sort_counter[i-1][0] == sort_counter[i][0]-1:
        res += sort_counter[i-1][1]
    res += sort_counter[i][1]
    if sort_counter[i+1][0] == sort_counter[i][0]+1:
        res += sort_counter[i+1][1]
    array.append(res)

print(max(array))

Submission status: Wrong Answer

Solution code:
n = int(input())
#k = int(input())
arr = list(map(int, input().split()))
a = [0 for i in range(0,max(arr)+2)]
for ar in arr:
  if ar is not 0:
    a[ar-1] += 1
  a[ar] += 1
  #if ar is not max(arr)+1:
  a[ar+1] += 1 
print(a)
ans = max(a)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
#k = int(input())
arr = list(map(int, input().split()))
a = [0 for i in range(0,max(arr)+2)]
for ar in arr:
  a[ar-1] += 1
  a[ar] += 1
  a[ar+1] += 1 


ans = max(a)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_n = list(map(int, input().split()))
a_n.sort()
a_n.reverse()
def check(idx):
    global a_n
    base = a_n[idx]
    count = 0
    dif = 0
    while dif <= 2:
        idx += 1
        count += 1
        if(idx == n):
            return count
        dif = base - a_n[idx]
    return count

ans = 1
i = 0
c = 0
tmp = a_n[0]
while(i != n):
    if(tmp != a_n[i]):
        tmp = a_n[i]
        c = check(i)
    if(ans < c):
        ans = c
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_n = list(map(int, input().split()))
a_n.sort()
a_n.reverse()
def check(idx):
    global a_n
    base = a_n[idx]
    count = 0
    dif = 0
    while dif <= 2:
        idx += 1
        count += 1
        if(idx == n):
            return count
        dif = base - a_n[idx]
    return count

ans = 1
i = 0
c = 0
tmp = a_n[0]
while(i != n - 1):
    if(tmp != a_n[i]):
        tmp = a_n[i]
        c = check(i)
    if(ans < c):
        ans = c
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_n = list(map(int, input().split()))
a_n.sort()
a_n.reverse()
def check(idx):
    global a_n
    base = a_n[idx]
    count = 0
    dif = 0
    now = a_n[idx]
    while dif <= 2:
        idx += 1
        count += 1
        if(idx == n):
            return count
        dif = base - a_n[idx]
    return count

ans = 1
i = 0
c = 0
tmp = a_n[0]
while(i != n - 1):
    if(tmp != a_n[i]):
        c = check(i)
    if(ans < c):
        ans = c
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-       
from collections import Counter

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

if(n==1):
    print('1')
if(n==2):
    if(abs(a[0]-a[1])<3):
        print('2')
    else:
        print('1')
else:
    ans = 0
    cnt = Counter(a)
    for i in range(max(a)):
        tmpsum = cnt[i-1]+cnt[i]+cnt[i+1]
        ans = max(tmpsum,ans)
    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-       
from collections import Counter

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


ans = 0
cnt = Counter(a)
for i in range(max(a)):
    tmpsum = cnt[i-1]+cnt[i]+cnt[i+1]
    ans = max(tmpsum,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-       
from collections import Counter

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

if(n==1):
    print('1')
else:
    ans = 0
    cnt = Counter(a)
    for i in range(1,max(a)):
        tmpsum = cnt[i-1]+cnt[i]+cnt[i+1]
        ans = max(tmpsum,ans)
    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-       
from collections import Counter

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

if(n==1):
    print(1)
else:
    ans = 0
    cnt = Counter(a)
    for i in range(max(a)):
        tmpsum = cnt[i-1]+cnt[i]+cnt[i+1]
        ans = max(tmpsum,ans)
    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-       
from collections import Counter

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

if(n==1):
    print(1)
else:
    ans = 0
    cnt = Counter(a)
    for i in range(1,max(a)):
        tmpsum = cnt[i-1]+cnt[i]+cnt[i+1]
        ans = max(tmpsum,ans)
    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-       
from collections import Counter

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

if(n==1):
    print(1)
else:
    ans = 0
    cnt = Counter(a)
    for i in range(1,a[n-1]+1):
        tmpsum = cnt[i-1]+cnt[i]+cnt[i+1]
        ans = max(tmpsum,ans)
    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-       
from collections import Counter

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

if(n==1):
    print(1)
else:
    ans = 0
    cnt = Counter(a)
    for i in range(1,a[n-1]):
        tmpsum = cnt[i-1]+cnt[i]+cnt[i+1]
        ans = max(tmpsum,ans)
    print(ans)

Submission status: Wrong Answer

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

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

ans = 0
lp,rp = 0,0
if(n==1):
    ans = 1
else:
    for i in range(1,a[n-1]):
        while(a[lp]<i-1):
            lp += 1
        while(a[min(rp,n-1)]<=i+1 and rp<n):
            rp += 1
        ans = max(rp-lp,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
a=i2()
d=[0 for i in range(10**5)]
for i in range(n):
 d[a[i]]+=1
 if a[i]<n-1:d[a[i]+1]+=1
 d[a[i]-1]+=1
print(max(d))

Submission status: Wrong Answer

Solution code:
dic={}
for i in range(100002):
    dic[i]=0
input()
for n in map(int,input().split()):
    dic[n]+=1
m=0
for i in range(1,100000):
    m=max(m,dic[i]+dic[i+1]+dic[i+2])
print(m)

Submission status: Wrong Answer

Solution code:
dic={}
for i in range(100001):
    dic[i]=0
input()
for n in map(int,input().split()):
    dic[n]+=1
m=0
for i in range(1,99999):
    m=max(m,dic[i]+dic[i+1]+dic[i+2])
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
edge = set()
h = 0
w = 0

for i in range(N):
    if A[i] in edge:
        if A[i] >= h:
            h = A[i]
        elif A[i] > w:
            w = A[i]
    else:
        edge.add(A[i])

print(h*w)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- encoding: utf-8 -*-
n = int(input().rstrip())
array = sorted(list(map(int, input().split(' '))))
count = [0] * 100001

for a in array:
    count[a - 1] += 1
    count[a    ] += 1
    count[a + 1] += 1

print(max(count))

Submission status: Wrong Answer

Solution code:
X=int(input())
a=list(map(int, input().split()))
b=a.count(X-1)
c=a.count(X)
d=a.count(X+1)
print(b+c+d)

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = [0] * 100001
data = list(map(int, input().split()))
for A in data:
    nums[A-1] += 1
    nums[A] += 1
    nums[A+1] += 1
print(max(nums))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N=int(input())
a=list(map(int,input().split()))
d=defaultdict(int)
for item in a:
    d[item-1]+=1
    d[item]+=1
    d[item+1]+=1
b=sorted(d.items(),key=lambda x:x[1],reverse=True)
print(b[0][0])

Submission status: Wrong Answer

Solution code:
from collections import Counter
#Nをセットする
N = int(input())
#aiをセットする
a = list(map(int,input().split()))
a_mai = []
a_pura = []
#ai +- 1したものを作る
for i in range(len(a)):
    #+1したもの
    a_pura.append(a[i] + 1)
    #-1したもの
    a_mai.append(a[i] - 1)
#aiそのままの重複の数
count_a = Counter(a)
#ai + 1重複の数
count_a_pura = Counter(a_pura)
#ai - 1の中腹の数
counter_a_mai = Counter(a_mai)
#一番大きい要素を取得
max_a = count_a.most_common()[0][1]
max_a_pura = count_a_pura.most_common()[0][1]
max_a_mai = counter_a_mai.most_common()[0][1]

#3つの最大値を求める
max = max_a
if max_a_pura >= max:
    max = max_a_pura
if max_a_mai >= max:
    max = max_a_mai
print(max)

Submission status: Wrong Answer

Solution code:
n  = int(input())
ls = list(map(int, input().split()))
ls_plus1  = list(map(lambda x: x + 1, ls))
ls_minus1 = list(map(lambda x: x - 1, ls))
dic = {}
for a in ls_minus1 + ls + ls_plus1:
    dic[a] = dic.get(a, 1) + 1
print(sorted(dic.values())[-1])

Submission status: Wrong Answer

Solution code:
# encoding: "utf-8"

from collections import defaultdict
from functools import reduce
from itertools import groupby

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]


def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    print(xs)
    ys = concat_map(xs, lambda x: [x, x+1, x-1])
    ys.sort()
    print(max(map(lambda x: count(x[1]), groupby(ys))))

def concat_map(xs, f):
    return reduce(lambda accum, x: accum + x, map(f, xs))

def count(iterator):
    cnt = 0
    for _ in iterator:
        cnt += 1
    return cnt

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

a_min, a_max = min(a), max(a)
cnt = 0
p = [0] * N

for j in range(a_min, a_max+1):
    for i in range(N):
        if j-1 <= a[i] <= j+1:
            p[i] = j
    cnt = max(cnt, p.count(j))
    
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
if a[0]==1:
    buf=a[0]
    a[0]=a[1]
    a[1]=buf
    ans += 1

for i in range(1,n-1):
    if a[i]==i+1:
        buf=a[i]
        a[i]=a[i+1]
        a[i+1]=buf
        ans += 1

if a[n-1]==n:
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split(" ")]
b = [0 for _ in range(100001)]

for e in a:
    for i in range(-1,2):
        b[e+i] += 1
print(max(b))