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 numpy as np
from scipy.stats import mode

n = int(input())
a = np.array(input().split(), dtype=np.int64)

mode_3, count_3 = mode([a-1, a, a+1], axis=None)
print(*count_3)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
ac = Counter(A)
ans = 0
for i in range(2,max(A)):
    if i-1 in ac and i in ac and i+1 in ac:
        ans = max(ans,ac[i-1]+ac[i]+ac[i+1])
print(ans)

Submission status: Wrong Answer

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

numbers = [0] * (max(a)+1)
ans = 0
for i in range(N):
    numbers[a[i]] += 1

for i in range(len(numbers)-2):
    ans = max(ans,sum(numbers[i:i+3]))

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

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


a.sort()

diff_a = []

for i in range(1,n):
    diff_a.append(a[i]-a[i-1])


c = 0
l = 0
max_l = 0
streak = False

for i in diff_a:
    if i <= 1:
        streak = True
        c += i
        l += 1
        if c == 2:
            l += 1
            max_l = max(l, max_l)
            streak = False
            c = 0
            l = 0
    
    elif streak and i == 2:
        l += 1
        streak = False
        max_l = max(l, max_l)
        l = 0
        c = 0
    
    elif not streak and i == 2:
        max_l = max(max_l, 2)
    
    elif streak and i > 2:
        l += 1
        streak = False
        max_l = max(l, max_l)
        l = 0
        c = 0
    
    elif not streak and i > 2:
        max_l = max(max_l, 1)
    
l += 1
max_l = max(max_l, l)

print(max_l)

Submission status: Wrong Answer

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

g = [0]*10
 
for i in range(10):
    g[i] = a.count(i)
    
ans = 1
    
for i in range(10):
    if i == 0:
        tmp = g[i] + g[i+1]
    elif i == 9:
        tmp = g[i-1] + g[i]
    else:
        tmp = g[i-1] + g[i] + g[i+1]
        
    ans = max(ans,tmp)
    
print(ans)

Submission status: Wrong Answer

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

g = [0]*10

for i in range(10):
    g[i] = a.count(i)
    
ans = 1

for i in range(8):
    ans = max(ans,g[i] + g[i+1] + g[i+2])
    
print(ans)

Submission status: Wrong Answer

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

g = [0]*10

for i in range(10):
    g[i] = a.count(i)
    
ans = 0

for i in range(8):
    ans = max(ans,g[i] + g[i+1] + g[i+2])
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt = [0] * (max(a) + 1)
for i in range(n):
         cnt[a[i]] += 1
sumcnt = [0]
for i in range(len(cnt)):
         sumcnt.append(sumcnt[i]+cnt[i])
ans = 0
for i in range(len(sumcnt) - 3):
         if ans < sumcnt[i+3] - sumcnt[i]:
                  ans = sumcnt[i+3] - sumcnt[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ary = list(map(int,input().split()))
counter = [0]*100000

for i in ary:
  counter[i-1] += 1
  
sum = 0
max = 0
for i in range(100000):
  if i == 0:
    sum = counter[i] + counter[i+1]
  elif i == 1:
    sum += counter[i+1]
  elif i == 99999:
    sum += -counter[i-2] 
  else:
    sum += counter[i+1] - counter[i-2]
  if sum > max:
    max = sum
print(max)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = {}
for i in a:
    if i in b.keys():
        b[i] += 1
    else:
        b[i] = 1
c = sorted(b.items())
m = len(c)
if m == 1:
    print(c[0][1])
elif m == 2:
    if c[1][0] - c[0][0] < 3:
        print(c[0][1] + c[1][0])
    else:
        print(max(c[0][1],c[1][0]))
else:
    s = 0
    for i in range(m-2):
        t = c[i][1]
        if c[i+2][0] - c[i][0] < 3:
            t += (c[i+1][1] + c[i+2][1])
        elif  c[i+1][0] - c[i][0] < 3:
            t += c[i+1][1]
        if t > s:
            s = t
    print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
nmax=10**5+1
n=int(input())
a=list(map(int,input().split()))

if n<=1:
    print(n)
else:
    c=[0]*nmax

    for i in range(n):
        c[a[i]-1]=c[a[i]-1]+1
        
    sum3=c[0]+c[1]+c[2]
    sum3max=sum3
    for i in range(1,nmax-2):
        sum3=c[i]+c[i+1]+c[i+2]
        sum3max=max(sum3max,sum3)
    print(sum3max)

Submission status: Wrong Answer

Solution code:
nmax=10**5+1
n=int(input())
a=list(map(int,input().split()))

if n<=3:
    print(n)
else:
    c=[0]*nmax

    for i in range(n):
        c[a[i]-1]=c[a[i]-1]+1
        
    sum3=c[0]+c[1]+c[2]
    sum3max=sum3
    for i in range(2,nmax-1):
        sum3=sum3-c[i-2]+c[i+1]
        sum3max=max(sum3max,sum3)
    print(sum3max)

Submission status: Wrong Answer

Solution code:
nmax=10**5+1
n=int(input())
a=list(map(int,input().split()))

if n<=3:
    print(n)
else:
    c=[0]*nmax

    for i in range(n):
        c[a[i]]=c[a[i]]+1
        
    sum3=c[0]+c[1]+c[2]
    sum3max=sum3
    for i in range(2,nmax-1):
        sum3=sum3-c[i-2]+c[i+1]
        sum3max=max(sum3max,sum3)
    print(sum3max)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array(input().split(), dtype = np.int32)

print(A)
counter = np.bincount(A)
B = counter.copy()
B[1:] += counter[:-1]
B[:-1] += counter[1:]

ans = B.max()
print(ans)

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
for i in range(N):
    tmp_ans = 0
    for a in A:
        if a - 1 > i:
            continue
        elif a + 1 < i:
            break
        else:
            tmp_ans += 1
    if tmp_ans > ans:
        ans = tmp_ans
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    v = c.most_common()[0][0]
    ans = 0
    for diff in range(-1, 2):
        cur = 0
        for a in A:
            if abs(a - (v + diff)) <= 1:
                cur += 1
        ans = max(cur, ans)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]
L = [0] * (10**5 + 1)

for i in A:
    L[i]   += 1
    L[i-1] += 1
    L[i+1] += 1

print(max(L))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
n = sum(a) // N - 1

ans = 0
for i in range(N):
  if a[i] == n or a[i] - 1 == n or a[i] + 1 == n:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = max(a)
s = collections.Counter(a)
answer = 0
for i in range(1,b+1):
    result=s[i-1] + s[i] + s[i+1]
    if (answer < result):
        answer = result
print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
step = [0]*(max(a)+2)
for j in range(1,max(a)+1):
    step[j]=a.count(j)
print(step)
answer = 0
for i in range(1,max(a)+1):
    result=step[i-1] + step[i] + step[i+1]
    if (answer < result):
        answer = result
print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
b = Counter(a)
c = list(set(a))
l = len(c)
if l == 1:
    print(n)
    exit()
ans = 0
for i in range(1, l - 1):
    tmp = b[c[i]]
    if c[i - 1] + 1 == c[i]:
        tmp += b[c[i - 1]]
    if c[i] + 1 == c[i + 1]:
        tmp += b[c[i + 1]]
    ans = max(ans, tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
b = Counter(a)
c = list(set(a))
l = len(c)
if l == 1:
    print(b[c[0]])
    exit()
ans = max(b[c[0]] + b[c[1]], b[c[l - 1]] + b[c[l - 2]])
for i in range(1, l - 1):
    ans = max(ans, b[c[i]] + b[c[i - 1]] + b[c[i + 1]])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
b = Counter(a)
c = list(set(a))
ans = 0
if len(c) == 1:
    print(b[c[0]])
    exit()
for i in range(len(c)):
    if 0 < i < len(c) - 1:
        ans = max(ans, b[c[i]] + b[c[i - 1]] + b[c[i + 1]])
    elif i == 0:
        ans = max(ans, b[c[i]] + b[c[i + 1]])
    elif i == len(c) - 1:
        ans = max(ans, b[c[i]] + b[c[i - 1]])
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# from collections import Counter


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

    result = 0
    for x in range(max(A)):
        tmp = 0
        for a in A:
            if a - 1 <= x <= a + 1:
                tmp += 1
        result = max(tmp, result)

    print(result)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A = sorted(A)
from bisect import bisect_left
ans = 0
for i in range(1, A[-1]+1):
  cnt = bisect_left(A, i+2) - bisect_left(A, i-1)
  ans = max(ans, cnt)
  #print(i, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A = sorted(A)
from bisect import bisect_left
ans = 0
for i in range(1, A[-1]):
  cnt = bisect_left(A, i+2) - bisect_left(A, i-1)
  ans = max(ans, cnt)
  #print(i, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A = sorted(A)
from bisect import bisect_left
ans = 0
for i in range(2, A[-1]):
  cnt = bisect_left(A, i+2) - bisect_left(A, i-1)
  ans = max(ans, cnt)
  #print(i, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
def main2():
    r = int(input())

    stick = [int(v) for v in input().split()]
    stick = sorted(stick, reverse=True)

    line = []
    tmp = -1
    for i in range(0, len(stick), 1):
        if tmp == stick[i]:
            line.append(stick[i])
            tmp = -1
        else:
            tmp = stick[i]
        if len(line) == 2:
            print(line[0] * line[1])
            exit()
    print(0)

main2()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in range(s_li[0] - 1, s_li[-1] + 1, 2):
        t_c = 0
        for vv in s_li:
            if v == vv or v - 1 == vv or v + 1 == vv:
                t_c += 1
        if t_c > count:
            count = t_c

    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in range(s_li[0] - 1, s_li[-1] + 1):
        t_c = 0
        for vv in s_li:
            if v == vv or v - 1 == vv or v + 1 == vv:
                t_c += 1
            if vv + 2 > v:
                break
        if t_c > count:
            count = t_c

    print(count)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

a.sort()
set_a = list(set(a))

import collections
count = collections.Counter(a)

ans = 0
for i in range(len(set_a)):
    cnt = count[set_a[i] + 1] + count[set_a[i] - 1] + 1
    ans = max(ans, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:

def main():
    t = input()
    if t == "1":
        print(input())
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in range(s_li[0] - 1, s_li[-1] + 1):
        t_c = 0
        for vv in s_li:
            if v == vv or v - 1 == vv or v + 1 == vv:
                t_c += 1
        if t_c > count:
            count = t_c

    print(count)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    t = input()
    if t == "1":
        print(input())
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in s_li:
        t_c = 0
        for vv in s_li:
            if v == vv or v - 1 == vv or v + 1 == vv:
                t_c += 1
        if t_c > count:
            count = t_c

    print(count)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def main():
    t = input()
    if t == "1":
        print(input())
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in s_li:
        t_c = 0
        for vv in s_li:
            if v == vv or v - 1 == v or v + 1 == vv:
                t_c += 1
        if t_c > count:
            count = t_c

    print(count)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def main():
    t = input()
    if t == "1":
        print(input())
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    for v in s_li:
        list_2 = list(filter(lambda x: x == v - 1 or x == v or x == v + 1, s_li))
        if len(list_2) > count:
            count = len(list_2)

    print(count)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    counter = Counter(A)

    mx = -1
    for i in range(1,10):
        sm = counter[i-1]+counter[i]+counter[i+1]
        mx = max(sm,mx)
        
    print(mx)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

t= 0
m = 0
for X in range(1 , max(A) + 1):
  t = A.count(X) + B.count(X) + C.count(X)
  m = max(m,t)
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
c = (10 ** 5 + 1) * [0]

for i in range(N):
  c[A[i]] += 1
  if A[i] > 0:
    c[A[i] - 1] += 1
  if A[i] < 10 ** 5:
    c[A[i] - 1] += 1

print(max(c))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
c = Counter(map(int, input().split()))
c = sorted(c.items())


ans = max(c[0][1], c[len(c)-1][1])
if len(c) <= 2:
    print(ans)
    exit()

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
c = Counter(map(int, input().split()))
c = sorted(c.items())


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

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
c = Counter(map(int, input().split()))
c = sorted(c.items())


ans = max(c[0][1], c[len(c)-1][1])
for i in range(1, len(c)-1):
    if c[i+1][0] - c[i][0] == 1:
        cnt = c[i+1][1] + c[i][1]
    if c[i][0] - c[i-1][0] == 1:
        cnt += c[i-1][1]
    else:
        cnt = c[i][1]
    ans = max(cnt, ans)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
c = Counter(map(int, input().split()))
c = sorted(c.items())

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

print(ans)

Submission status: Wrong Answer

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

count = 0
for cur in range(min(a), max(a)):
    t_count = 0
    for aa in a:
        if abs(cur - aa) <= 1:
            t_count += 1

    count = max(count, t_count)

print(count)

Submission status: Wrong Answer

Solution code:
#072_C
n = int(input())
a = list(map(int, input().split()))
sa = [0 for _ in range(0, 100001)]
for ai in a:
    sa[ai] += 1
for i in range(1, 100001):
    sa[i] += sa[i-1]

ans = 0
for i in range(3, 100001):
    ans = max(ans, sa[i] - sa[i-3])
    
print(ans)

Submission status: Wrong Answer

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

na = {}
for i in range(n):
    if a[i] in na:
        na[a[i]] += 1
    elif a[i] - 1 in na:
        na[a[i] - 1] += 1
    elif a[i] + 1 in na:
        na[a[i] + 1] += 1
    else:
        na[a[i]] = 1
        na[a[i] - 1] = 1
        na[a[i] + 1] = 1

print(max(na.values()))

Submission status: Wrong Answer

Solution code:
input()
l=sorted(map(int,input().split()))
from bisect import *
a=1
for i in range(l[0],l[-1]):
  a=max(a,bisect(l,i+1)-bisect_left(l,i-1))
print(a)

Submission status: Wrong Answer

Solution code:
input()
l=sorted(map(int,input().split()))
from bisect import *
a=0
for i in range(l[0],l[-1]):
  a=max(a,bisect(l,i+1)-bisect_left(l,i-1))
print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
cnt = [0] * 10**5
for i in map(int, input().split()):
    cnt[i] += 1

res = 0
for i in range(1, len(cnt)-2):
    val = sum(cnt[i:i+3])
    if res < val:
        res = val

print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
L = list(map(int,input().split()))
C = collections.Counter(L)
C = sorted(C.items(), key=lambda x: x[1], reverse=True)
ans = 0
for i in range(min(3,len(C))):
  ans += C[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
L = list(map(int,input().split()))
C = collections.Counter(L)
print(C)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ac = Counter(a)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = sorted(list(map(int,input().split())))
cnt = [0]*(10**5+1)
cur = 1
if N == 1: cnt[a[0]] = 1
for i in range(1,N):
    if a[i] == a[i-1]:
        cur += 1
    else:
        cnt[a[i-1]] = cur
        cur = 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = sorted(list(map(int,input().split())))
cnt = [0]*(10**5+1)
cur = 1
if N == 1: cnt[a[0]] = 1
for i in range(1,N):
    if a[i] == a[i-1]:
        cur += 1
    else:
        cnt[a[i-1]] = cur
        cur = 1

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[0]*(10**5+1)
v=list(map(int,input().split()))
for i in range(n):
  x=v[i]
  if x==0:
    l[0]+=1
    l[1]+=1
  if x==10**5:
    l[x-1]+=1
    l[x]+=1
  else:
    l[x-1]+=1
    l[x]+=1
    l[x+1]+=1
l.sort()
print(l[-1])

Submission status: Wrong Answer

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

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

maxA = max(a)
cntA = [0] * (maxA + 1)
cnt3 = [0] * (maxA + 1)

for _a in a:
    cntA[_a] += 1

for i in range(maxA-1):
    cnt3[i] += cntA[i] + cntA[i+1] + cntA[i+2]


# print(cntA)
# print(cnt3)

ans = max(cnt3)
print(ans)

Submission status: Wrong Answer

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

if n==1 and a==[0]:
    print(1)
    exit()

maxA = max(a)
cntA = [0] * (maxA + 1)
cnt3 = [0] * (maxA + 1)

for _a in a:
    cntA[_a] += 1

for i in range(maxA-1):
    cnt3[i] += cntA[i] + cntA[i+1] + cntA[i+2]


# print(cntA)
# print(cnt3)

ans = max(cnt3)
print(ans)

Submission status: Wrong Answer

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

maxA = max(a)
cntA = [0] * (maxA + 1)
cnt3 = [0] * (maxA + 1)

for _a in a:
    cntA[_a] += 1

for i in range(1,maxA):
    cnt3[i] += cntA[i-1] + cntA[i] + cntA[i+1]

# print(cntA)
# print(cnt3)

ans = max(cnt3)
print(ans)

Submission status: Wrong Answer

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

maxA = max(a)
cntA = [0] * (maxA + 1)
cnt3 = [0] * (maxA + 1)

for _a in a:
    cntA[_a] += 1

for i in range(1,maxA-1):
    cnt3[i] += cntA[i] + cntA[i+1] + cntA[i+2]

# print(cntA)
# print(cnt3)

ans = max(cnt3)
print(ans)

Submission status: Wrong Answer

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

maxA = max(a)
cntA = [0] * (maxA + 1)
cnt3 = [0] * (maxA + 1)

for _a in a:
    cntA[_a] += 1

for i in range(maxA-1):
    cnt3[i] += cntA[i] + cntA[i+1] + cntA[i+2]

# print(cntA)
# print(cnt3)

ans = max(cnt3)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
n = int(input())
a = list(map(int, input().split()))
count_a = list(Counter(a).items())
count_a = sorted(count_a, reverse=True)
result = 1
c = 0
for x, y in count_a:
    if y>=2:
        result *= x
        c += 1
        if y>=4 and c == 1:
            result *= x
            c += 1
        if c == 2:
            print(result)
            sys.exit()
print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
a=list(map(int, input().split()))
a.sort(reverse=True)
piv=a[0]
#print(a)
max=0
c=collections.Counter(a)
value=list(c.values())
key=list(c.keys())
for i in range(1,piv+10):
    #print(c[i],c[i+1],c[i+2])
    if max<c[i]+c[i+1]+c[i+2]:
        max=c[i]+c[i+1]+c[i+2]
print(max)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
a=list(map(int, input().split()))
a.sort(reverse=True)
piv=a[0]
#print(a)
max=0
c=collections.Counter(a)
value=list(c.values())
key=list(c.keys())
for i in range(1,piv-1):
    #print(c[i],c[i+1],c[i+2])
    if max<c[i]+c[i+1]+c[i+2]:
        max=c[i]+c[i+1]+c[i+2]
print(max)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]

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

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

ans = 0

for j in range(1, n-1):
    ans = max(ans, d[j-1] + d[j] + d[j+1])

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *a = map(int, read().split())
A = np.array(a)

counter = np.bincount(A)
print(type(counter))
B = counter.copy()
B[1:] += counter[:-1]
B[:-1] += counter[1:]

print(B.max())

Submission status: Wrong Answer

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

max_count = 0

L = [0]*10**5
for i in range(N):
    L[i] += 1

for i in range(10**5+1):
    count = 0
    for j in range(-1,2):
        if i+j >= 0 and i+j < 10**5:
            count += L[i+j]
    max_count = max(count, max_count)
print(max_count)

Submission status: Wrong Answer

Solution code:
N = int(input())
list_a = [int(x) for x in input().split()]

ans = 0

for X in range(min(list_a),max(list_a)+1) :
    ansX = list_a.count(X) + list_a.count(X+1) + list_a.count(X-1)
    ans = max(ans,ansX)
    print(X,ansX,ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a_list = list(map(int, input().split()))

    vals = []
    for X in range(10):
        vals.append(len([a for a in a_list if abs(X - a) <= 1]))
    print(max(vals))

if __name__ == '__main__':
    main()