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:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()
    num_list = i_list()

    tmp_list = [0] * 10 ** 5

    for i in range(n):
        tmp_list[num_list[i]-1] += 1

    count = 0

    for i in range(10**5-2):
        tmp = tmp_list[i] + tmp_list[i+1] + tmp_list[i+2]
        count = max(count, tmp)

    print(count)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

for x in a:
    count[x - 1] += 1
    count[x] += 1
    count[x + 1] += 1
print(max(count))

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
al = list(map(int, input().split()))
al.sort()

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

ans = 0
for i in range(n):
    idx = bisect.bisect_right(al, al[i] + 2)
    tmp = idx - i
    ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
al = list(map(int,input().split()))
al.sort()

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


ans = 0
for i in range(n):
    idx = bisect.bisect_right(al,al[i]+2)
    if idx > n-1:
        idx = n-1
    tmp = idx - i
    ans = max(ans,tmp)


print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
al = list(map(int,input().split()))
al.sort()

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


ans = 0
for i in range(n):
    idx = bisect.bisect_right(al,al[i]+2)
    if idx == n:
        idx -= 1
    tmp = idx - i
    ans = max(ans,tmp)


print(ans)

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
al = list(map(int,input().split()))
al.sort()

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


ans = 0
for i in range(n-2):
    idx = bisect.bisect_right(al,al[i]+2)
    tmp = idx - i
    ans = max(ans,tmp)
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    n, *a = map(int, read().split())
    ac = Counter(a)
    acs = sorted(ac.items())
    r = ac.most_common()[0][1]
    for i1 in range(1, len(acs) - 1):
        if abs(acs[i1 - 1][0] - acs[i1+1][0]) <= 2:
            r = max(r, acs[i1-1][1] + acs[i1][1] + acs[i1+1][1])
        elif abs(acs[i1 - 1][0] - acs[i1][0]) <= 1:
            r = max(r, acs[i1-1][1] + acs[i1][1])
        elif abs(acs[i1 + 1][0] - acs[i1][0]) <= 1:
            r = max(r, acs[i1+1][1] + acs[i1][1])
    print(r)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    n, *a = map(int, read().split())
    ac = Counter(a)
    acs = sorted(ac.items())
    r = 0
    for i1 in range(1, len(acs) - 1):
        if abs(acs[i1 - 1][0] - acs[i1+1][0]) <= 2:
            r = max(r, acs[i1-1][1] + acs[i1][1] + acs[i1+1][1])
        elif abs(acs[i1 - 1][0] - acs[i1][0]) <= 1:
            r = max(r, acs[i1-1][1] + acs[i1][1])
        elif abs(acs[i1 + 1][0] - acs[i1][0]) <= 1:
            r = max(r, acs[i1+1][1] + acs[i1][1])
    print(r)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import Counter
def main():
    n, *a = map(int, read().split())
    ac = Counter(a)
    acs = sorted(ac.items())
    r = 0
    for i1 in range(1, len(acs) - 1):
        if abs(acs[i1 - 1][0] - acs[i1+1][0]) <= 2:
            r = max(r, acs[i1-1][1] + acs[i1][1] + acs[i1+1][1])
        elif abs(acs[i1 - 1][1] - acs[i1][1]) <= 1:
            r = max(r, acs[i1-1][1] + acs[i1][1])
        elif abs(acs[i1 + 1][1] - acs[i1][1]) <= 1:
            r = max(r, acs[i1+1][1] + acs[i1][1])
    print(r)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
a = [int(i) for i in input().split()]
check = []
dict = collections.Counter(a)
for a, b in dict.items():
    if b >= 2:
        check.append(a)

if len(check) >=2:
    check.sort()
    if dict[check[-1]] >= 4:
        print(check[-1] ** 2)
    else:
        print(check[-1] * check[-2])
elif len(check) == 1:
    if dict[check[-1]] >= 4:
        print(check[-1] ** 2)
    else:
        print(0)
else:
    print(0)

Submission status: Wrong Answer

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

mmax = max(a)
mmin = min(a)
mcount = 0
for i in range(mmin, mmax):
    count = 0
    count += a.count(i)
    count += a.count(i + 1)
    count += a.count(i - 1)
    if mcount < count:
        mcount = count

print(mcount)

Submission status: Wrong Answer

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

while i<n:
    if p[i]==i+1:
        ans += 1
        i+=1
    if not (i==n-2 and p[i+1]==i+2):
        i += 1
print(ans)

Submission status: Wrong Answer

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

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

n_dict = {}
min_n = 10**9
max_n = 0
for i in range(n):
    t = a[i]
    if t in n_dict:
        n_dict[t] += 1
    else:
        n_dict[t] = 1
    
    max_n = max(t, max_n)
    min_n = min(t, min_n)

ans = 0
for x in range(min_n+1, max_n+1):
    tmp = 0
    if x-1 in n_dict: tmp += n_dict[x-1]
    if x in n_dict: tmp += n_dict[x]
    if x+1 in n_dict: tmp += n_dict[x+1]
    
    ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    As = list(map(int, input().split()))
    As_sort = sorted(As)
    As_sort.insert(0, As_sort[0])
    Count = 0
    ans_temp = 0
    ans = -float("inf")
    for i in range(1, n+1):
        if As_sort[i] - As_sort[i-1] != 0:
            Count += 1
        if Count >= 3:
            ans_temp = 0
            Count = 0
        ans_temp += 1
        ans = max(ans, ans_temp)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    As = list(map(int, input().split()))
    As_sort = sorted(As)
    diff_As = [0] * n
    for i in range(1, n):
        diff_As[i] = As_sort[i] - As_sort[i-1]
    Count = 0
    ans_temp = 0
    ans = -float("inf")
    for i in range(n):
        if diff_As[i] != 0:
            Count += 1
        if Count >= 3:
            ans_temp = 0
            Count = 0
        ans_temp += 1
        ans = max(ans, ans_temp)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
arr = [0] * 100001

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

print(max(arr))

Submission status: Wrong Answer

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

i = 0
ans = 1
while True:
    cnt1 = 0
    cnt2 = 0
    while a[i + cnt1] == a[i]:
        cnt1 += 1
        cnt2 += 1
        if i + cnt1 == n:
            break
    if i + cnt1 == n:
        break
    while a[i + cnt2] <= a[i] + 2:
        cnt2 += 1
        if i + cnt2 == n:
            break
    ans = max(ans, cnt2)
    i += cnt1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
sa = sorted(a)
r, ans = 0, 0
if n == 1:
    print(1)
else:
    for l in range(n):
        cnt = 1
        for r in range(l + 1, n):
            if abs(sa[r] - sa[l]) <= 2:
                cnt += 1

        ans = max(ans, cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
sa = sorted(a)
r, ans = 0, 0
for l in range(n):
    cnt = 0
    while r < n and abs(sa[r] - sa[l]) <= 2:
        cnt += 1
        r += 1

    ans = max(ans, cnt)
    if l == r:
        r += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
sa = sorted(a)
r, ans = 0, 0
for l in range(n):
    cnt = 0
    while r < n and abs(sa[r] - sa[l]) <= 2:
        cnt += 1
        r += 1

    ans = max(ans, cnt)
    if l == r:
        r += 1

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

res = max(x)
print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
a = list(map(int,input().split()))
count_list = [0]*(max(a)+1)
ans = 0
for i in a:
    count_list[i]+=1
for i in range(1,max(a)):
    ans = max(ans,count_list[i-1]+count_list[i]+count_list[i+1])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(k) for k in input().split()]
cnt = [0]*(10**5+1)
for i in a:
  cnt[i] += 1
s = cnt[0] + cnt[1] + cnt[2]
ans = 1
for i in range(3,n-2):
  s -= cnt[i-3]
  s += cnt[i]
  #print(s)
  ans = max(s,ans)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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)+1):
    res = a.count(i) + a.count(i+1) + a.count(i-1)
    ans = max(ans, res)
    
  print(ans)

Submission status: Wrong Answer

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

if n == 1:
  print(1)
else:
  res = []
  for i in a:
    res.append(i-1)
    res.append(i)
    res.append(i+1)
  
  res.sort()
  ans = 0
  for j in range(1, max(a)+1):
    c = res.count(j)
    ans = max(ans, c)
  
  print(ans)

Submission status: Wrong Answer

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

if n == 1:
  print(1)
else:
  a1 = max(a) - min(a) + 1
  res = []
  for i in a:
    res.append(i-1)
    res.append(i)
    res.append(i+1)
  
  res.sort()
  ans = 0
  for j in range(1,a1):
    c = res.count(j)
    ans = max(ans, c)
  
  print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ans = 0
amin = min(a)
amax = max(a)
for x in range(amin, amax+1):
   if x == 0:
      continue
   ans = max(ans, c[x-1]+c[x]+c[x+1])

print(ans)

Submission status: Wrong Answer

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

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

ans = 0
for i in range(1,max(a)):
  if ans < nums[i-1] + nums[i] + nums[i+1]:
    ans = nums[i-1] + nums[i] + nums[i+1]

print(ans)

Submission status: Wrong Answer

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

m = max(a)
b = [0 for _ in range(m + 2)]

for x in a:
    b[x] += 1
ans = 0
for i in range(1, m + 1):
    ans = max(ans, b[i - 1] + b[i] + b[i + 1])
print(ans)

Submission status: Wrong Answer

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]


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

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]

ans=1
if l[N//2]>sum(l)//N:
    l=sorted(a,reverse=True)


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

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]


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 c-t<=2:
                continue
            else:
                _ans=j
                if _ans>ans:
                    ans=_ans
                else:
                    pass
                break
print(ans)

Submission status: Wrong Answer

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

l=sorted(a)

# N=7
# l=[1, 1, 2, 3, 4, 5, 9]

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 c-t<=2:
                pass
            else:
                _ans=j
                if _ans>ans:
                    ans=_ans
                    break
                else:
                    pass
print(ans)

Submission status: Wrong Answer

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

l=sorted(a)

ans=1

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

Submission status: Wrong Answer

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

l=sorted(a)

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 c-t<=2:
                continue
            else:
                if j>ans:
                    ans=j
                else:
                    pass
print(ans)

Submission status: Wrong Answer

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

l=sorted(a)

ans=1

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

Submission status: Wrong Answer

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

l=sorted(a)

ans=1

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

Submission status: Wrong Answer

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

l=sorted(a)

ans=1

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

Submission status: Wrong Answer

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

l=sorted(a)

ans=1

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

Submission status: Wrong Answer

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

l=sorted(a)

ans=1

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

Submission status: Wrong Answer

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

l=sorted(a)

ans=1

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

Submission status: Wrong Answer

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

l=sorted(a)

ans=1

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

Submission status: Wrong Answer

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

l=sorted(a)

ans=1

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

Submission status: Wrong Answer

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

l=sorted(a)

ans=1

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

Submission status: Wrong Answer

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
        break
if _ans>ans:
    ans=_ans
    targetindex=targetindex+i
    t=[targetindex]
else:
    pass
print(ans)

Submission status: Wrong Answer

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

l=sorted(a)

ans=0

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

Submission status: Wrong Answer

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

l=sorted(a)

ans=0

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
am=max(a)
num=[0]*(am+1)
for i in a:
  num[i]+=1
#print(num)
mx=0
for i in range(1,am):
  #print(num[i-1:i+2])
  m=sum(num[i-1:i+2])
  if m>mx:
    mx=m
print(mx)

Submission status: Wrong Answer

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

num=[0]*(max(a)+1)
for i in a:
  num[i]+=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
if len(a)==1:
  mx=1
print(mx)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

print(mx)

Submission status: Wrong Answer

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

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

print(mx)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-06-26 15:12:37 +0900
# LastModified: 2020-06-26 15:29:35 +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, a_max+1):
        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: Wrong Answer

Solution code:
from collections import defaultdict
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a_max = max(a)
A = defaultdict(int)
for i in range(n):
    A[a[i]] += 1
ans = 0
for i in range(a_max):
    ans = max(ans,A[i]+A[i+1]+A[i+2])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a_max = max(a)
a = Counter(a)
ans = 0
for i in range(a_max):
    try:
        ans = max(ans,a[i]+a[i+1]+a[i+2])
    except IndexError:
        pass
print(ans)

Submission status: Wrong Answer

Solution code:
print(2)

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
if n == 1:
    print(1)
elif n == 2:
    if abs(a[0] - a[1]) <= 2:
        print(2)
    else:
        print(1)
else:
    d = {}
    for i in range(max(a) + 3):
        d[i] = 0
    for i in a:
        d[i] += 1
    ans = 1
    pre = 0
    for i in range(max(a)):
        pre = d[i] + d[i + 1] + d[i + 2]
        if ans < pre:
            ans = pre
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
if n == 1:
    print(1)
elif n == 2:
    if abs(a[0] - a[1]) <= 2:
        print(2)
    else:
        print(1)
else:
    d = {}
    for i in range(max(a) + 1):
        d[i] = 0
    for i in a:
        d[i] += 1
    ans = 1
    pre = 0
    for i in range(max(a) - 1):
        pre = d[i] + d[i + 1] + d[i + 2]
        if ans < pre:
            ans = pre
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, *a = map(int, read().split())
cnt = [0] * (10 ** 5 + 1)

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

print(max(cnt))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a_n = []

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

print(a_n)
counter=Counter(a_n)

print(a_n.count(counter.most_common()[0][0]))

Submission status: Wrong Answer

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
if n>3:
  for i in range(0,n-2):
    tmp=sum(count[i:i+3])
    if tmp>answer:
      answer=tmp
else:
  answer=sum(count)
print(answer)

Submission status: Wrong Answer

Solution code:
from math import*
from bisect import*
import copy

n=int(input())
arr=list(map(int,input().split()))
arr.sort()
brr=copy.deepcopy(arr)
brr=list(set(brr))
brr.sort()
#print(arr)
ans=0
#print(bisect_right(arr,6))
for i in range(len(brr)):
	d=bisect_left(arr,brr[i])
	c=bisect_right(arr,brr[i]+2)
	if ans<c-d:
		ans=c
print(ans)

Submission status: Wrong Answer

Solution code:
from math import*
from bisect import*
import copy

n=int(input())
arr=list(map(int,input().split()))
arr.sort()
brr=copy.deepcopy(arr)
brr=list(set(brr))
#print(arr)
ans=0
#print(bisect_right(arr,6))
for i in range(len(brr)):
	d=bisect_left(arr,brr[i])
	c=bisect_right(arr,brr[i]+2)
	if ans<c-d:
		ans=c
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = 100001*[0]

for a in map(int,input().split()):
  A[a-1]+=1
  A[a]+=1
  A[a+1]+=1

print(max(A))

Submission status: Wrong Answer

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

import collections
c = collections.Counter(a)
_max = 0
for i in range(max(a)):
  _sum = c[i-1] + c[i] + c[i+1]
  if _max < _sum:
    _max = _sum
print(_max)

Submission status: Wrong Answer

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

import collections

ans = 0

if N == 1:
  ans = 1
elif N == 2:
  if max(a)-min(a) <= 2:
    ans = 2
  else:
    ans = 1
else:
  for x in range(min(a),max(a)-1):
    c = collections.Counter(a)
    ans_candidate = c[x] + c[x+1] + c[x+2]

    if ans < ans_candidate:
      ans = ans_candidate
print(ans)

Submission status: Wrong Answer

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

ans = 0

if N == 1:
  ans = 1
elif N == 2:
  if max(a)-min(a) <= 2:
    ans = 2
  else:
    ans = 1
else:
  for x in range(min(a),max(a)-1):
    ans_candidate = a.count(x)+a.count(x+1)+a.count(x+2)
    if ans < ans_candidate:
      ans = ans_candidate
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(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: 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 = [0]*(max(a)+1)
for i in a:
    al[i] += 1
index = al.index(max(al))

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int, input().split()))
A.sort()
x=A[0] #after -1
cnt=0
ans=1
for a in A:
    if x<=a<=x+2:
        cnt+=1
    else:
        ans=max(ans, cnt)
        cnt=1
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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