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:
"""
    中央値が使えないのであれば，全パターン試すしかない．
    for文でXをiとして決めている．
"""


def main():
    length = int(input())
    numbers = list(map(int, input().split()))
    count = [0] * 10 ** 5
    for num in numbers:
        count[num] += 1
    answer = 0
    for i in range(1, 10 ** 5 - 2):
        answer = max(answer, sum(count[i:i + 3]))
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    length = int(input())
    numbers = list(map(int, input().split()))
    count = [0] * (10 ** 5 + 1)
    for num in numbers:
        count[num] += 1
    answer = 0
    for i in range(1, 10 ** 5 - 2):
        answer = max(answer, sum(count[i:i + 3]))
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    length = int(input())
    numbers = list(map(int, input().split()))
    count = [0] * (10 ** 5 + 1)
    for num in numbers:
        count[num] += 1
    answer = 0
    for i in range(1, 10 ** 5 + 1):
        answer = max(answer, sum(count[i:i + 3]))
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    numbers = sorted(list(map(int, input().split())))
    target = [numbers[N // 2 + i] for i in range(-1, -1 + min(N, 3))]
    answer = [0, 0, 0]
    for num in numbers:
        for i in range(min(N, 3)):
            if target[i] == num or target[i] == num - 1 or target[i] == num + 1:
                answer[i] += 1
    print(max(answer))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    numbers = sorted(list(map(int, input().split())))
    target = numbers[N // 2 - 1]
    answer = 0
    for num in numbers:
        if target == num or target == num - 1 or target == num + 1:
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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]
    if i != 0:
        if cnt[i][0] == cnt[i-1][0] - 1:
            x += cnt[i-1][1]
    if i == len(cnt) - 1:
        continue
    if cnt[i][0] == cnt[i+1][0] + 1:
        x += cnt[i+1][1]
    ans = max(ans, x)
print(ans)

Submission status: Wrong Answer

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()))
a.sort()
counter = Counter(a).most_common()
a_cnt = sorted(counter)
# print(type(a_cnt))
ans = 1
# print(a_cnt)
for i in range(2, len(a_cnt)):
    num1 = a_cnt[i - 2][0]
    num2 = a_cnt[i - 1][0]
    num3 = a_cnt[i][0]
    cnt1 = a_cnt[i - 2][1]
    cnt2 = a_cnt[i - 1][1]
    cnt3 = a_cnt[i][1]
    # if i == 2:
    #     # print(num1, num2, num3, cnt1, cnt2, cnt3)
    if 0 <= num3 - num1 <= 2:
        ans = max(ans, cnt1 + cnt2 + cnt3)
    elif 0 <= num3 - num2 <= 2:
        ans = max(ans, cnt2 + cnt3)
    elif 0 <= num2 - num1 <= 2:
        ans = max(ans, cnt1 + cnt2)
print(ans)

Submission status: Wrong Answer

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()))
a.sort()
counter = Counter(a).most_common()
a_cnt = sorted(counter)
# print(type(a_cnt))
ans = 1
print(a_cnt)
for i in range(2, len(a_cnt)):
    num1 = a_cnt[i - 2][0]
    num2 = a_cnt[i - 1][0]
    num3 = a_cnt[i][0]
    cnt1 = a_cnt[i - 2][1]
    cnt2 = a_cnt[i - 1][1]
    cnt3 = a_cnt[i][1]
    # if i == 2:
    #     # print(num1, num2, num3, cnt1, cnt2, cnt3)
    if 0 <= num3 - num1 <= 2:
        ans = max(ans, cnt1 + cnt2 + cnt3)
    elif 0 <= num3 - num2 <= 2:
        ans = max(ans, cnt2 + cnt3)
    elif 0 <= num2 - num1 <= 2:
        ans = max(ans, cnt1 + cnt2)
print(ans)

Submission status: Wrong Answer

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()))
a.sort()
counter = Counter(a).most_common()
a_cnt = sorted(counter)
# print(type(a_cnt))
ans = 1
# print(a_cnt)
for i in range(2, len(a_cnt)):
    num1 = a_cnt[i - 2][0]
    num2 = a_cnt[i - 1][0]
    num3 = a_cnt[i][0]
    cnt1 = a_cnt[i - 2][1]
    cnt2 = a_cnt[i - 1][1]
    cnt3 = a_cnt[i][1]
    # if i == 2:
    #     # print(num1, num2, num3, cnt1, cnt2, cnt3)
    if 0 <= num3 - num1 <= 2:
        ans = max(ans, cnt1 + cnt2 + cnt3)
    if 0 <= num3 - num2 <= 2:
        ans = max(ans, cnt2 + cnt3)
    if 0 <= num2 - num1 <= 2:
        ans = max(ans, cnt1 + cnt2)
print(ans)

Submission status: Wrong Answer

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()))
a_cnt = Counter(a).most_common()
ans = 1
for i in range(2, len(a_cnt)):
    num1 = a_cnt[i - 2][0]
    num2 = a_cnt[i - 1][0]
    num3 = a_cnt[i][0]
    cnt1 = a_cnt[i - 2][1]
    cnt2 = a_cnt[i - 1][1]
    cnt3 = a_cnt[i][1]
    if 0 <= num3 - num1 <= 4:
        ans = max(ans, cnt1 + cnt2 + cnt3)
    if 0 <= num3 - num2 <= 2:
        ans = max(ans, cnt2 + cnt3)
    if 0 <= num2 - num1 <= 2:
        ans = max(ans, cnt1 + cnt2)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = [0] * (10 ** 5 + 1)
for a in al_s:
    ans[a] += 1
    ans[a + 1] += 1
    ans[a - 1] += 1

print(max(ans))

Submission status: Wrong Answer

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

for i in range(N):
    lis[a[i]-1]+=1
ans = 0
for i in range(n):
    if i== 0:
        ans = lis[i] +lis[i+1]
    elif i== 10**5 - 1:
        ans = lis[i-1]+lis[i]
    else:
        if ans <= lis[i-1]+lis[i]+lis[i+1]:
            ans= lis[i-1]+lis[i]+lis[i+1]

print(ans)

Submission status: Wrong Answer

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

for i in range(N):
    lis[a[i]-1]+=1
ans = 0
for i in range(n):
    if i== 0:
        ans = lis[i] +lis[i+1]
    else:
        if ans <= lis[i-1]+lis[i]+lis[i+1]:
            ans= lis[i-1]+lis[i]+lis[i+1]

print(ans)

Submission status: Wrong Answer

Solution code:
# 2020/02/01
# AtCoder Beginner Contest 072 - C

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

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

# Count

for i in range(n):
    for j in range(-1, 2):
        wk_val = a[i] + j
        if wk_val < 0:
            wk_val = 10**5

        cntlist[wk_val] = cntlist[wk_val] + 1

ans = max(cntlist)

# Output
print(ans)

Submission status: Wrong Answer

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

for i in range(n-1):
    for j in range(i+1, n):
        if a[j] > a[i] + 2:
            #print(i, j)
            if (j - i) > ans:
                ans = (j - i)
            break
print(ans)

Submission status: Wrong Answer

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


for i in range(n-1):
    for j in range(i+1, n):
        if j > i + 2:
            if j - i > ans:
                ans = j - i
            break
print(ans)

Submission status: Wrong Answer

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

# max_x = max(numbers) + 1
# max_x = int(sum(numbers) / len(numbers))
# res = 0
test = set()
for n in numbers:
    test.add(n)
    test.add(n - 1)
    test.add(n + 1)
length = len(test)
res = {}
# print(test)
# for i in range(max_x + 1):
for n in numbers:
    c = 0
    sub = set([n - 1, n, n + 1]) & test
    # print(sub)
    for s in sub:
        if res.get(s) is None:
            res[s] = 1
        else:
            res[s] += 1
# for i in test:
#     c = 0
#     for n in numbers:
#         if n - 1 == i or n == i or n + 1 == i:
#             c += 1
#     if res < c:
#         res = c

# print(res)
print(max(res.values()))

Submission status: Wrong Answer

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

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

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

print(max(pl))

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = [0] * 100000
a = 0
for x in map(int, input().split()):
    a = max(a, x)
    lst[x - 1] += 1

ret = 0
for x in range(100000):
    ret = max(sum(lst[x : x + 3]), ret)
print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = [0] * 100000
a = 0
for x in map(int, input().split()):
    a = max(a, x)
    lst[x - 1] += 1

ret = 0
for x in range(99999):
    ret = max(sum(lst[x : x + 3]), ret)
print(ret)

Submission status: Wrong Answer

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

max = 0

for i in range(N):
  X = i

  new = [l for l in li if l == X or l == (X + 1) or l == (X - 1)]

  if max < len(new):
    max = len(new)

print(new)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

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

x = []
x_append = x.append

for a in A:
    x_append(a-1)
    x_append(a)
    x_append(a+1)


X = collections.Counter(x)

print(X.most_common(1))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
cnt = [0]*(max(a)+1)

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
cnt=0
ans=[]
a=A[0]
for i in range(1,N):
    if A[i]-a<=2:
        cnt+=1
    else:
        a=A[i]
        ans.append(cnt)
        cnt=0
ans.append(cnt)
MAX=max(ans)
if MAX>0:
    print(MAX+1)
else:
    print(MAX)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
l=[]
for i in range(N):
    l.extend([a[i]-1,i,a[i]+1])

import collections
c=collections.Counter(l)

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

Submission status: Wrong Answer

Solution code:
N = int(input())


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

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

for i in range(len(A)):
    up = A[i]+1
    down = A[i]-1
    no = A[i]
    L[up]=L[up]+1
    L[down]=L[down]+1
    L[no] = L[no]+1

print(max(L))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input()
listaEmStr=[]
listaNeutra=[]
listaMais=[]
listaMenos=[]
pos=0
cont=0
maior=0
for transformando in a:
    if transformando != ' ':
        listaEmStr.append(transformando)
for char in listaEmStr:
    num=int(char)
    listaNeutra.append(num)
for mais in listaNeutra:
    listaMais.append(mais)
for menos in listaNeutra:
    listaMenos.append(menos)
for soma in listaMais:
    listaMais[pos]+=1
    pos+=1
for subtracao in listaMenos:
    listaMenos[cont]-=1
    cont+=1
listaTotal=listaNeutra+listaMais+listaMenos
for qtd in listaTotal:
    vezes=listaTotal.count(qtd)
    if vezes>=maior:
        maior=vezes
print(maior)

Submission status: Wrong Answer

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

t = max(a)
num_list = [0] * (t + 2)

for i in range(n):
    num_list[a[i]] += 1
    if i == n or a[i] == 0:
        continue
    else:
        num_list[a[i]-1] += 1
    if i == 0 or a[i] == t:
        continue
    else:
        num_list[a[i]+1] += 1

print(max(num_list))

Submission status: Wrong Answer

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

num_list = [0] * (max(a) + 2)

for i in range(n):
    num_list[a[i]] += 1
    if i == n:
        continue
    else:
        num_list[a[i]-1] += 1
    if i == 0:
        continue
    else:
        num_list[a[i]+1] += 1

print(max(num_list))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
N = int(input())
A = Counter(sorted([int(_) for _ in input().split()])).items()
if N == 1:
    print(1)
    sys.exit()

A = list(A)
ans = 0
for n in range(1, len(A) - 1):
    tmp = A[n][1]
    if A[n - 1][0] + 1 == A[n][0]:
        tmp += A[n - 1][1]
    if A[n][0] + 1 == A[n + 1][0]:
        tmp += A[n + 1][1]
    ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = Counter(sorted([int(_) for _ in input().split()])).items()

A = list(A)
ans = 1
for n in range(1, len(A) - 1):
    tmp = A[n][1]
    if A[n - 1][0] + 1 == A[n][0]:
        tmp += A[n - 1][1]
    if A[n][0] + 1 == A[n + 1][0]:
        tmp += A[n + 1][1]
    ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
X = [0]*(10**5+1)
for x in A:
  X[x-1] += 1
  X[x] += 1
  X[x+1] += 1
answer = max(X)
print(answer)

Submission status: Wrong Answer

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 = 1
c = np.bincount(A)

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

print(answer)
# 32

Submission status: Wrong Answer

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)-1):
    result = c[i-1] + c[i] + c[i+1]
    if result > answer:
        answer = result

print(answer)
# 32

Submission status: Wrong Answer

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

Memory = {}

# ひとつひとつの要素を見て、+1~-1の範囲の値を確定させる
for i in a:
  p = i + 1
  q = i
  r = -1
  if i >= 0: 
    r = i-1 
  
  # 確定した範囲の値を+1する
  if p in Memory:
    Memory[p] += 1
  else:
    Memory[p] = 1
  if q in Memory:
    Memory[q] += 1
  else:
    Memory[q] = 1
  if r != -1:
    if r in Memory:
      Memory[r] += 1
    else:
      Memory[r] = 1
  
#print(Memory)
  # 最後にキャッシュの中で一番数が多いのが正解
max = 0
maxVal = 0
for k,i in Memory.items():
  if max < i:
    max = i
    maxVal = k

print(maxVal)

Submission status: Wrong Answer

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

b = np.bincount(a)
ans = 0
for i, j, k in zip(b[1:], b[2:], b[3:]):
    ans = max(ans, i + j + k)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
num = list(map(int, input().split(" ")))
num_sort = sorted(num)

#print(num_sort)

num_set = set(num)
num_set_l = list(num_set)
#print(num_set)

num_set_l = sorted(num_set_l)
#print(num_set_l)
counts = []
start = 0
reset_i = 0

for i in range(len(num_set_l)-1):
  if num_set_l[i+1] - num_set_l[i] > 1 or (i - reset_i) % 3 == 2:
    reset_i = i + 1 
    end = num_sort.index(num_set_l[i+1])
    counts.append(end - start)
    start = end
    
  if i == len(num_set_l) - 2 and (num_set_l[i+1] - num_set_l[i]) == 1:
    end = len(num_sort)
    counts.append(len(num_sort) - num_sort.index(num_set_l[i]))
    #print(len(num_sort), num_sort.index(num_set_l[reset_i]))
    #print(start, end)
  
  if num_set_l[-1] == num_sort[-1] and i == (len(num_set_l)-2):
    counts.append(len(num_sort) - num_sort.index(num_set_l[-1]))

if start == 0:
  print(len(num_sort))
else:
  print(max(counts))

Submission status: Wrong Answer

Solution code:
N = int(input())
num = list(map(int, input().split(" ")))
num_sort = sorted(num)

#print(num_sort)

num_set = set(num)
num_set_l = list(num_set)
#print(num_set)

num_set_l = sorted(num_set_l)
#print(num_set_l)
counts = []
start = 0
reset_i = 0

for i in range(len(num_set_l)-1):
  if num_set_l[i+1] - num_set_l[i] > 1 or (i - reset_i) % 3 == 2:
    reset_i = i + 1 
    end = num_sort.index(num_set_l[i+1])
    counts.append(end - start)
    start = end
    
  if i == len(num_set_l) - 2 and (num_set_l[i+1] - num_set_l[i]) == 1:
    end = len(num_sort)
    counts.append(len(num_sort) - num_sort.index(num_set_l[reset_i]))
    #print(len(num_sort), num_sort.index(num_set_l[reset_i]))
    #print(start, end)
  
  if num_set_l[-1] == num_sort[-1] and i == (len(num_set_l)-2):
    counts.append(len(num_sort) - num_sort.index(num_set_l[-1]))

if start == 0:
  print(len(num_sort))
else:
  print(max(counts))

Submission status: Wrong Answer

Solution code:
N = int(input())
num = list(map(int, input().split(" ")))
num_sort = sorted(num)

#print(num_sort)

num_set = set(num)
num_set_l = list(num_set)
#print(num_set)

num_set_l = sorted(num_set_l)
#print(num_set_l)
counts = []
start = 0
reset_i = 0

for i in range(len(num_set_l)-1):
  if num_set_l[i+1] - num_set_l[i] > 1 or (i - reset_i) % 3 == 2:
    reset_i = i + 1 
    end = num_sort.index(num_set_l[i+1])
    counts.append(end - start)
    start = end
    
  if i == len(num_set_l) - 2 and (num_set_l[i+1] - num_set_l[i]) == 1:
    end = len(num_sort)
    counts.append(len(num_sort) - num_sort.index(num_set_l[reset_i]))
    #print(len(num_sort), num_sort.index(num_set_l[reset_i]))
    #print(start, end)

if start == 0:
  print(len(num_sort))
else:
  print(max(counts))

Submission status: Wrong Answer

Solution code:
N = int(input())
num = list(map(int, input().split(" ")))
num_sort = sorted(num)

#print(num_sort)

num_set = set(num)
num_set_l = list(num_set)
#print(num_set)

num_set_l = sorted(num_set_l)
counts = []
start = 0
reset_i = 0

for i in range(len(num_set_l)-1):
  if num_set_l[i+1] - num_set_l[i] > 1 or (i - reset_i) % 3 == 2:
    reset_i = i + 1 
    end = num_sort.index(num_set_l[i+1])
    counts.append(end - start)
    start = end
    
  if i == len(num_set_l) - 2 and (num_set_l[i+1] - num_set_l[i]) == 1:
    end = len(num_sort)
    counts.append(len(num_sort) - num_sort.index(num_set_l[reset_i]))
    print(len(num_sort), num_sort.index(num_set_l[reset_i]))
    #print(start, end)

if start == 0:
  print(len(num_sort))
else:
  print(max(counts))

Submission status: Wrong Answer

Solution code:
N = int(input())
num = list(map(int, input().split(" ")))
num_sort = sorted(num)

#print(num_sort)

num_set = set(num)
num_set_l = list(num_set)
#print(num_set)

counts = []
start = 0
reset_i = 0

for i in range(len(num_set_l)-1):
  if num_set_l[i+1] - num_set_l[i] > 1 or (i - reset_i) % 3 == 2:
    reset_i = i + 1 
    end = num_sort.index(num_set_l[i+1])
    counts.append(end - start)
    #print(start, end)
    start = end
  if i == len(num_set_l) - 2 and (num_set_l[i+1] - num_set_l[i]) == 1:
    end = len(num_sort)
    counts.append(len(num_sort) - num_sort.index(num_set_l[reset_i]))
    #print(start, end)

if start == 0:
  print(len(num_sort))
else:
  print(max(counts))

Submission status: Wrong Answer

Solution code:
N = int(input())
num = list(map(int, input().split(" ")))
num_sort = sorted(num)

#print(num_sort)

num_set = set(num)
num_set_l = list(num_set)
#print(num_set)

counts = []
start = 0
reset_i = 0

for i in range(len(num_set_l)-1):
  if num_set_l[i+1] - num_set_l[i] > 1 or (i - reset_i) % 3 == 2:
    reset_i = i + 1 
    end = num_sort.index(num_set_l[i+1])
    counts.append(end - start)
    #print(start, end)
    start = end
  if i == len(num_set_l) - 2 and (num_set_l[i+1] - num_set_l[i]) == 1:
    end = len(num_sort)
    counts.append(end - start)
    #print(start, end)

if start == 0:
  print(len(num_sort))
else:
  print(max(counts))

Submission status: Wrong Answer

Solution code:
N = int(input())
num = list(map(int, input().split(" ")))
num_sort = sorted(num)

#print(num_sort)

num_set = set(num)
num_set_l = list(num_set)
#print(num_set)

counts = []
start = 0
reset_i = 0

for i in range(len(num_set_l)-1):
  if num_set_l[i+1] - num_set_l[i] > 1 or (i - reset_i) % 3 == 2:
    reset_i = i % 3 + 1
    end = num_sort.index(num_set_l[i+1])
    counts.append(end - start)
    #print(start, end)
    start = end

if start == 0:
  print(len(num_sort))
else:
  print(max(counts))

Submission status: Wrong Answer

Solution code:
N = int(input())
num = list(map(int, input().split(" ")))
num_sort = sorted(num)

#print(num_sort)

num_set = set(num)
num_set_l = list(num_set)
#print(num_set)

counts = []
start = 0
reset_i = 0

for i in range(len(num_set_l)-1):
  if num_set_l[i+1] - num_set_l[i] > 1 or (i - reset_i) % 3 == 2:
    reset_i = i % 3 
    end = num_sort.index(num_set_l[i+1])
    counts.append(end - start)
    #print(start, end)
    start = end

if start == 0:
  print(len(num_sort))
else:
  print(max(counts))

Submission status: Wrong Answer

Solution code:
N = int(input())
num = list(map(int, input().split(" ")))
num_sort = sorted(num)

#print(num_sort)

num_set = set(num)
num_set_l = list(num_set)
#print(num_set)

counts = []
start = 0

for i in range(len(num_set_l)-1):
  if num_set_l[i+1] - num_set_l[i] > 1 or i % 3 == 2:
    end = num_sort.index(num_set_l[i+1])
    counts.append(end - start)
    start = end

if start == 0:
  print(len(num_sort))
else:
  print(max(counts))

Submission status: Wrong Answer

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

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


for i in range(n-1):
    if a[i + 1] - a[i] <= 2:
        cur = a[i]
        for j in range(i, n-1):
            if a[j+1] - cur <= 2:
                ans1 += 1
            else:
                if ans < ans1:
                    ans = ans1
                ans1 = 0
                break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#072C Together
import sys
n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
maxA = max(A)
L = [0 for _ in range(maxA+2)]

for a in A:
    L[a]+=1
#print(L)
ans = 0
for i in range(1, maxA+1):
    tmp = sum(L[i-1:i+2])
    ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
#072C Together
import sys
n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
maxA = max(A)
L = [0 for _ in range(maxA+1)]

for a in A:
    L[a]+=1
#print(L)
ans = 0
for i in range(1, maxA):
    tmp = sum(L[i-1:i+2])
    ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter



def main()->None:
    # a_iに１を足すか、１引くか、何もしないかの操作を行って、ある整数個数最大化をする
    # x を決めるとgreedyに決まる。
    # 最後の一つのサンプルがTLEになる。jit の使い方もよくわからん
    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 = a_dict[key]
        for i in keys:
            if key + 1 == i or key - 1 == i:
                tmp_count += a_dict[i]
        if tmp_count > max_count:
            max_count = tmp_count
    print(max_count)

if __name__ == "__main__":
    import time
    start = time.time()
    main()
    print(time.time() - start)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main()->None:
    # a_iに１を足すか、１引くか、何もしないかの操作を行って、ある整数個数最大化をする
    # x を決めるとgreedyに決まる。
    # どうやってxを決めるのか。
    N = int(input())
    a = list(map(int, input().split()))
    set_a = set(a)
    max_count = 0
    for a_compo in set_a:
        X = a_compo
        tmp_count = 0
        for i in a:
            if abs(X - i) <= 1:
                tmp_count += 1
        if tmp_count > max_count:
            max_count = tmp_count
    print(max_count)

if __name__ == "__main__":
    import time
    start = time.time()
    main()
    print("time:{}".format(time.time() - start))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
p = 1
q = 0
r = 0
ans = 1
for i in range(N-1):
    if a[i+1] == a[i]+1:
        r = q
        q = p
        p = 1
    elif a[i+1] == a[i]:
        p += 1
    elif a[i+1] == a[i] + 2:
        r = p
        q = 0
        p = 1
    if p+q+r > ans:
        ans = p+q+r
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
p = 1
q = 0
r = 0
ans = 1
for i in range(N-1):
    if a[i+1] != a[i]:
        r = q
        q = p
        p = 1
    else:
        p += 1
    if p+q+r > ans:
        ans = p+q+r
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
p = 1
q = 0
r = 0
ans = 1
p = a[0]
for i in range(N-1):
    if a[i+1] != a[i]:
        r = q
        q = p
        p = 1
    else:
        p += 1
    if p+q+r > ans:
        ans = p+q+r
print(ans)

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

from collections import defaultdict
dicts = defaultdict(int)

N=one_int()
X=many_int()

sorted_X = sorted(X)

for i in sorted_X:
    if i in dicts:
        dicts[i] += 1
    else:
        dicts[i] = 1

max_num = 1
for j in range(sorted_X[0],sorted_X[-1]):
    temp_sum = dicts[j-1] + dicts[j] + dicts[j+1]
    
    if max_num < temp_sum:
        max_num = temp_sum

print(max_num)

Submission status: Wrong Answer

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

al = sorted(al)

import bisect

ans = 0
for i in range(max(al)):
    a = bisect.bisect_right(al,i+2) -  bisect.bisect_left(al,i)
    ans = max(ans, a)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
amin = min(a)
amax = max(a)
ans = 0
for x in range(amin,amax+1,3):
	    p = 0
	    p += a.count(x)
	    p += a.count(x+2)
	    p += a.count(x+1)
	    ans = max(ans,p)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
c = dict(collections.Counter(a))
c = dict(sorted(c.items(),key = lambda x:x[0]))

ans = 0
for i in range(2,10**5):
  cnt = 0
  try:
    cnt += c[i-1]
  except KeyError:
    pass
  
  try:
    cnt += c[i]
  except KeyError:
    pass
    
  try:
    cnt += c[i+1]
  except KeyError:
    pass
    
  ans = max(ans,cnt)  
  
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    X[a+1] += 1
maxx = 0
print(max(X))
# maxx_idx = 0
# for idx,x in enumerate(X):
#     if maxx <= x:
#         maxx = x
#         maxx_idx = idx
# print(maxx)

Submission status: Wrong Answer

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

    X[a+1] += 1
maxx = 0
maxx_idx = 0
for idx,x in enumerate(X):
    if maxx <= x:
        maxx = x
        maxx_idx = idx
print(maxx)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict

cnt = defaultdict(int)

def main():
    n, *a = map(int, sys.stdin.read().split())
    a.sort()
    l = a[0]
    r = a[-1]

    for val in a:
        cnt[val] += 1
    
    ans = 0
    for i in range(l, r):
        ans = max(ans, cnt[i-1] + cnt[i] + cnt[i+1])

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect
from math import factorial

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

point = 0

for i in range(n-1):
    if li[i]-1 == i:
        li[i],li[i+1] = li[i+1],li[i]
        point += 1
if li[-1] == n:
    point += 1

print(point)

Submission status: Wrong Answer

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.values())
b.sort()
cnt=b[0]
for i in range(len(b)-2):
  cnt=max(cnt,b[i]+b[i+1]+b[i+2])  
print(cnt)