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: Runtime Error

Solution code:
import numpy as np

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

A_ = sorted(A_)
A = np.array(A_)

dic = {}
for a in A:
    dic[a] = 0

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


ans = 0

for X in range(A[1],A[-1]):
    tmp = dic[X-1] + dic[X] + dic[X+1]

    ans = max(tmp,ans)
print(ans)

Submission status: Runtime Error

Solution code:
#ABC072C
N=int(input())
A=list(map(int,input().split()))
max_A=max(A)
TGS=[0]*(max_A+1)
ans=0
for i in range(N):
    TGS[A[i]]+=1
for i in range(max_A):
    if ans<TGS[i]+TGS[i+1]+TGS[i+2]:
        ans=TGS[i]+TGS[i+1]+TGS[i+2]
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
al=set(a)
al=list(al)
l=len(al)
a00=al[0]
a01=al[1]
a02=al[2]
a1=a.count(a00)#一個前の合計
if l==1:
    print(a1)
    exit()
a2=a.count(a01)#現在の合計
if l==2:
    if abs(a00-a01)<=2:
        print(a1+a2)
        exit()
    else:
        print(max(a1,a2))
        exit()
a3=a.count(a02)#一つ先の合計
count=0
result=0#最大値
for i in range(1,l-1):
    a3=a.count(al[i+1])
    count=a1+a2+a3
    if count>result:
        result=count
    a1=a2
    a2=a3
print(result)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
if n==1:
    print(1)
    exit()
elif n==2:
    if abs(a[0]-a[1])<=2:
        print(2)
        exit()
    else:
        print(1)
        exit()
al=set(a)
al=list(al)
a1=a.count(al[0])#一個前の合計
a2=a.count(al[1])#現在の合計
a3=a.count(al[2])#一つ先の合計
count=0
result=0#最大値
al.append(" ")
for i in range(1,len(al)-2):
    count=a1+a2+a3
    if count>result:
        result=count
    a1=a2
    a2=a3
    a3=a.count(al[i+2])
print(result)

Submission status: Runtime Error

Solution code:
    def main():
        n = int(input())
        a = list(map(int,input().split()))
     
        ans_lst = [0 for i in range(max(a)+4)]
     
     
        for i in a:
            ans_lst[i] += 1
            ans_lst[i+1] += 1
            ans_lst[i-1] += 1
     
     
        print(max(ans_lst))
     
     
     
    if __name__ == "__main__":
            main()

Submission status: Runtime Error

Solution code:
N=int(input())
p=list(map(int,input().split()))
q=['x' for _ in range(N)]
ans=0
for i in range(N):
    if p[i]!=i+1:
        q[i]='o'
for i in range(N-1):
    if q[i]=='x':
        if i<n-1:
            p[i], p[i+1]=p[i+1], p[i]
        else:
            p[i], p[i-a1]=p[i-1], p[i]
        q[i]='o'
        q[i+1]='o'
        ans+=1

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnts = [0 for i in range(N + 1)]
for a in A:
  cnts[a] += 1
res = 0
for idx in range(1, A - 1):
  tmp = sum(A[idx-1:idx+1])
  if tmp > res:
    res = tmp
print(res)

Submission status: Runtime Error

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

a.sort()

l = list(set(a))
l_co = list()

if n == 1:
    print(1)
elif n == 2:
    if abs(a[0]-a[1]) <= 1:
        print(2)
    else:
        print(1)
else:
    for i in range(len(l)):
        l_co.append(a.count(l[i]))
    #print(l_co)
    res_l = list()
    for i in range(len(l)-2):
        res_l.append(sum(l_co[i:i+3]))
    else:
        print(max(res_l))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())

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

ans=[0]*max(a)

for i in range(N):
    ans[a[i]-1]+=1

ll = [ans[0], ans[0]+ans[1], ans[N-2]+ans[N-1], ans[N-1]]

ans_a=max(ll)

for i in range(N-2):
    aa = ans[i]+ans[i+1]+ans[i+2]
    if aa>ans_a:
        ans_a=aa
    
print(ans_a)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
i = 0
b = []
while i <= 100000:
  n = a.count(i)
  b.append(n)
  i += 1
l = len(b)
j = 1
c = []
while j < l:
  nn = b[j-1]+b[j]+b[j+1]
  c.append(nn)
  j += 1
print(max(c))

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
A = Counter(list(map(int,input().split())))
Ans = 0
B = A.most_common()
for n,c in B:
    Ans = max(Ans,B[n]+B[n-1]+B[n+1])
print(Ans)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
m = max(1, min(a))
M = max(a)
ans=[]
for x in range(m,M):
    ans.append(c[x-1]+c[x]+c[x+1])
if m == M:
    ans.append(n)
print(max(ans))

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
ans=[]
m = max(1, min(a))
M = max(a)+1
for x in range(m,M):
    ans.append(c[x-1]+c[x]+c[x+1])
print(max(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
dics = {}
for i in range(len(n)):
    if a[i] in dics:
        dics[a[i]] = dics[a[i]]  + 1
    else:
        dics.update({a[i]:1})
    
#dics min max
dicsmin = min(list(dics.keys()))
dicsmax = max(list(dics.keys()))

counter = []
for i in range(dicsmin,dicsmax + 1):
    xcount = 0
    x = i
    #beam search x
    for j in range(len(a)):
        if a[j] == x or x-1 or x + 1:
            xcount = xcount + 1
    counter.append(xcount)
    
print(max(xcount))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

maximum = max(A)
count = [0]*(maximum + 1)

for i in range(N):
    if A[i] == 0:
        count[0] += 1
        count[1] += 1
        
    elif A[i] == maximum:
        count[A[i]] += 1
        count[A[i] - 1] += 1
    
    else:
        count[A[i] + 1] += 1
        count[A[i]] += 1
        count[A[i] - 1] += 1

print(max(count))

Submission status: Runtime Error

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

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

for i in range(N):
    if A[i] == 0:
        count[0] += 1
        count[1] += 1
        
    elif A[i] == max(A):
        count[A[i]] += 1
        count[A[i] - 1] += 1
    
    else:
        count[A[i] + 1] += 1
        count[A[i]] += 1
        count[A[i] - 1] += 1

print(max(count))

Submission status: Runtime Error

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

count = [0 for i in range(max(A) + 1)]
for i in range(N):
    if A[i] == 0:
        count[A[i]] += 1
        count[A[i] + 1] += 1
    elif A[i] == max(A):
        count[A[i]] += 1
        count[A[i] - 1] += 1
    else:
        count[A[i] + 1] += 1
        count[A[i]] += 1
        count[A[i] - 1] += 1
print(max(count))

Submission status: Runtime Error

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

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

C = Counter(A)

ans = 0
for i in range(max(A)+1):
    ans = max(C[i] + C[i-1] + C[i+1], ans)

print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

a.sort()
v = list(collections.Counter(a).values())

sum = [v[i] + v[i+1] + v[i+2] for i in range(len(v)-2)]
print(max(sum))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n;
    vector<int> v(100002,0);
    cin>>n;
    for(;n--;){
        int p;
        cin>>p;
        v[p]++;
        v[p+1]++;
        v[p+2]++;
    }
    cout<<v[max_element(v.begin(),v.end())-v.begin()];
    
}

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = [0]*max(A)

if N ==1:
    ans[0] = 1
else:
    for X in range(max(A)):
        for i in range(N):
            if abs(X-A[i])<=1:
                ans[X]+=1

print(max(ans))

Submission status: Runtime Error

Solution code:
input()
d = {}
for i in map(int, input().split()):
    if i in d:
        d[i] = 1
    else:
        d[i] += 1
print(sorted(d.values())[-1])

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
count = 0
target = A[1]
for i in range(N - 1):
    if target == A[i] or target - 1 == A[i] or target + 1 == A[i]:
        count += 1

print(count)

Submission status: Runtime Error

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

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

print(max(count))

Submission status: Runtime Error

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

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

print(max(count))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

N=input()
a=map(int, raw_input().split())
#print a
#print max(a)

dict={}


for i in range(len(a)):
	if a[i] in dict:
		dict[ a[i] ]+=1 
	else:
		dict[ a[i] ]=1
		#print dict


for j in range(max(a)):
	if not j in dict:
		dict[j]=0

#print dict

max_sum=0
for key,value in dict.items():
	if key==0:
		sum=dict[key]+dict[key+1]
	elif key==max(a):
		sum=dict[key-1]+dict[key]
	else:
		sum=dict[key-1]+dict[key]+dict[key+1]
	#print key,sum

	if max_sum<sum:
		max_sum=sum

print max_sum

Submission status: Runtime Error

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

res = [0] * 100000

for i in a:
	list[i] += 1
	
print(max(map(sum,zip(list, list[1:], list[2:]))))

Submission status: Runtime Error

Solution code:
c=[0]*114514;input();for i in map(int,input().split()):;    c[i]+=1;print(max([sum(c[i:i+3]) for i in range(100000)]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

N = int(input())
ls = list(map(int, input().split(' ')))
d = {}
for l in ls:
    if l in d:
        d[l] += 1
    else:
        d[l] = 1

m = 0
for k in range(1, 100002):
    if k in d:
        c += d[k]
    if (k-1) in d:
        c += d[k-1]
    if (k+1) in d:
        c += d[k+1]
    m = max(m,c)
print(m)

Submission status: Runtime Error

Solution code:
N = int(input())
ls = list(map(int, input().split(' ')))
d = {}
for l in ls:
    if l in d:
        d[l] += 1
    else:
        d[l] = 1

m = 0
keys = sorted(d.keys())
for k in keys:
    c = d[k]
    if (k-1) in d:
        c += d[k-1]
    if (k+1) in d:
        c += d[k+1]
    m = max(m,c)
print(m)
N = int(input())
ls = list(map(int, input().split(' ')))
d = {}
for l in ls:
    if l in d:
        d[l] += 1
    else:
        d[l] = 1

m = 0
for k in range(1, 100002):
    if k in d:
        c += d[k]
    if (k-1) in d:
        c += d[k-1]
    if (k+1) in d:
        c += d[k+1]
    m = max(m,c)
print(m)

Submission status: Runtime Error

Solution code:
# encoding: "utf-8"

from collections import defaultdict

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

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


def first_count_and_pop(xs):
    cnt = 0
    fst = xs[0]
    # cnt = xs.count(fst)
    for x in xs:
        if x != fst:
            break
        cnt += 1
    return (cnt, i)    
    

def main():
    _ = input()
    # xs = Stdin.read_line(converter=int)
    xs = [int(x) for x in input().split()]
    xs.sort()
    ys = defaultdict(int)
    i = 0
    j = len(xs)
    while i < j:
        key = xs[i]
        cnt, i = first_count_and_pop(xs[i:])
        ys[key] += cnt
        ys[key-1] += cnt
        ys[key+1] += cnt

    print(max(ys.values()))

# def main_():
#     input()
#     xs = Stdin.read_line(converter=int)
#     xs.sort()
#     counts = list()
#     for i in range(100000):
#         if not xs:
#             counts.extend([0] * (100000 - len(counts)))
#             break     
#         elif i == xs[0]:
#             cnt, xs = first_count_and_pop(xs)
#             counts.append(cnt)
#         else:
#             counts.append(0)
#     m = 0
#     for i in range(0, 100000):
#         if i == 0:
#             temp = counts[i] + counts[i+1]
#         elif i == 100000 - 1:
#             temp = counts[i-1] + counts[i]
#         else:
#             temp = counts[i-1] + counts[i] + counts[i+1]
#         if m < temp:
#             m = temp
#     print(m)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# encoding: "utf-8"

from collections import defaultdict

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

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


def first_count_and_pop(xs):
    cnt = 0
    fst = xs[0]
    # cnt = xs.count(fst)
    for x in xs:
        if x != fst:
            break
        cnt += 1
    return (cnt, i)    
    

def main():
    _ = input()
    # xs = Stdin.read_line(converter=int)
    xs = [int(x) for x in input().split()]
    xs.sort()
    ys = defaultdict(int)
    i = 0
    j = len(xs)
    while i < j:
        key = xs[0]
        cnt, i = first_count_and_pop(xs[i:])
        ys[key] += cnt
        ys[key-1] += cnt
        ys[key+1] += cnt

    print(max(ys.values()))

# def main_():
#     input()
#     xs = Stdin.read_line(converter=int)
#     xs.sort()
#     counts = list()
#     for i in range(100000):
#         if not xs:
#             counts.extend([0] * (100000 - len(counts)))
#             break     
#         elif i == xs[0]:
#             cnt, xs = first_count_and_pop(xs)
#             counts.append(cnt)
#         else:
#             counts.append(0)
#     m = 0
#     for i in range(0, 100000):
#         if i == 0:
#             temp = counts[i] + counts[i+1]
#         elif i == 100000 - 1:
#             temp = counts[i-1] + counts[i]
#         else:
#             temp = counts[i-1] + counts[i] + counts[i+1]
#         if m < temp:
#             m = temp
#     print(m)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# encoding: "utf-8"

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

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


def first_count_and_pop(xs):
    cnt = 0
    fst = xs[0]
    cnt = xs.count(fst)
    # for x in xs:
    #     if x != fst:
    #         break
    #     cnt += 1
    return (cnt, xs[cnt:])    
    

def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    xs.sort()
    ys = dict()
    while xs:
        key = xs[0]
        cnt, xs = first_count_and_pop(xs)
        ys[key] = cnt
    zs = sorted(list(ys.items()), key=(lambda x: x[1]), reverse=True)
    m = 0
    for i in range(1, 10000):
        temp = ys.get(i-1, 0) + x + ys.get(i+1, 0)
        if m < temp:
            m = temp
    print(m)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

count = [0]*100002

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

Submission status: Runtime Error

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

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

maxn = cnt[0] + cnt[1]

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

Submission status: Runtime Error

Solution code:

# your code goes here
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
i=0
x=0
j=0
k=0
while j<len(a) and a[j]-a[i]<1:
    j+=1
k=j+1
while k<len(a):
    while k<len(a) and a[k]-a[j]<1:
        k+=1
    if k<len(a):
        if x<k-i:
            x=k-i
        i=j
        j=k
        k=j
print(x)j

Submission status: Runtime Error

Solution code:
 your code goes here
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
i=0
x=0
j=0
k=0
while j<len(a) and a[j]-a[i]<1:
    j+=1
k=j+1
while k<len(a) and a[k]-a[j]<1:
    k+=1
    if k<len(a):
        if x<k-i:
            x=k-i
        i=j
        j=k
        k=j

print(x)

Submission status: Runtime Error

Solution code:
a=input()
b=map(int,raw_input().split())
c=[]
for i in range(100000):
    c.append(0)

for i in b:
    c[i]+=1
    c[i+1]+=1
    c[i+2]+=1

c.sort()
c.reverse()

print c[0]

Submission status: Runtime Error

Solution code:
def solve():
    N = int(input())
    a = list(map(int, input().split()))
    ans = 0
    n=0
    check = 0
    checkmm = 0
    checkm = 0
    a.sort()
    for i in a:
        if i == i-1:
            break
        if i-2 in a:
            checkmm = checkm
        else:
            checkmm = 0

        if i-1 in a:
            checkm = check
        else :
            checkm = 0
        check = 0
        while a[n] == i:
            check = check + 1
            n = n+1
            if N==n:
                break


        if ans < check+checkm+checkmm:
            ans = check+checkm+checkmm

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
import sys

def main():
    N = int(sys.stdin.readline())
    a = list(map(int, input().split()))
    n = [0 for i in range(0, max(a)+1)]
    for i in a:
        n[i] += 1
    if len(a) < 2:
        print(sum(n))
    else:
        print(max([i+j+k for i, j, k in zip(n[:-2], n[1:-1], n[2:])]))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

N = int(input())
A = list(map(int, input().split(' ')))
A2 = sorted(A)
countQ = [A2.pop(0)]
maxAns = 1
while A2:
    a = A2.pop(0)
    if countQ[0] + 2 >= a:
        countQ.append(a)
        print(countQ)
    else:
        tmp = len(countQ)
        if maxAns < tmp:
            maxAns = tmp
        countQ.append(a)
        first = countQ[0]
        while first in countQ:
            countQ.pop(0)
        print(countQ)
tmp = len(countQ)
if maxAns < tmp:
    maxAns = tmp
print(maxAns)

Submission status: Runtime Error

Solution code:
import sys

def main():
    N = int(sys.stdin.readline())
    a = list(map(int, input().split()))
    n = [0 for i in range(0, max(a)+1)]
    for i in a:
        n[i] += 1
    print(max([i+j+k for i, j, k in zip(n[:-2], n[1:-1], n[2:])]))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

def main():
    N = int(sys.stdin.readline())
    a = list(map(int, input().split()))
    n = [0 for i in range(0, max(a)+1)]
    for i in a:
        n[i] += 1
    print(max([i+j+k for i, j, k in zip(n, n[1:], n[2:])]))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
A = input().split()
ans = 1

A__ = []
for i in A:
    if i not in A__:
        A__.append(i)

A_ = {}
for i in A__:
    A_[int(i)] = A.count(i)



for a in A__:
    a_ = int(a) - 1
    if a_ >= 0:
        est = A_[a_-1] + A_[a_] + A_[a_+1]
        ans = max(ans, est)
    a_ = int(a)
    if a_ >= 0:
        est = A_[a_-1] + A_[a_] + A_[a_+1]
        ans = max(ans, est)
    a_ = int(a) + 1
    if a_ >= 0:
        est = A_[a_-1] + A_[a_] + A_[a_+1]
        ans = max(ans, est)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = input().split()
ans = 1

A_ = {}
for i in range(-1, 10**5+1):
    A_[i] = A.count(str(i))

A__ = []
for i in A:
    if i not in A__:
        A__.append(i)

for a in A__:
    a_ = int(a) - 1
    if a_ >= 0:
        est = A_[a_-1] + A_[a_] + A_[a_+1]
        ans = max(ans, est)
    a_ = int(a)
    if a_ >= 0:
        est = A_[a_-1] + A_[a_] + A_[a_+1]
        ans = max(ans, est)
    a_ = int(a) + 1
    if a_ >= 0:
        est = A_[a_-1] + A_[a_] + A_[a_+1]
        ans = max(ans, est)

print(ans)

Submission status: Runtime Error

Solution code:
import statistics

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

b = []
c = []
for i in range(N):
    b.append(a[i] - 1)
    c.append(a[i] + 1)

x = a + b + c
y = statistics.mode(x)

print(x.count(y))

Submission status: Runtime Error

Solution code:
N = int(input())
s1 = input()
s1 = [int(n) for n in s1.split()]
s1 = s1[:N]
dict = {}
for n in range(max(s1)):
    count = 0
    for val in s1:
    	if val in [n,n+1,n+2]:
    		count += 1
    dict.update({n+1:count})
print (sorted(dict.values())[-1])

Submission status: Runtime Error

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

a.sort()

hist = [0 for x in range(-1,max(a)+3)]
As = []
ans = -1
Aspd = As.append

if len(a) ==1:
    ans = a[0]
else:
    for i in a:
        hist[i] += 1
    
    for i in range(len(hist)-1):
        Aspd(hist[i-1]+hist[i]+hist[i+1])
        

print(max(As))

Submission status: Runtime Error

Solution code:
N = int(input())
s1 = input()[:N]
s1 = [int(n) for n in s1.split()]
dict = {}
for n in range(max(s1)):
    count = 0
    for val in s1:
    	if val in [n,n+1,n+2]:
    		count += 1
    dict.update({n+1:count})
print (sorted(dict.values())[-1])

Submission status: Runtime Error

Solution code:
N = int(input())
s1 = input()[:N]
s1 = [int(n) for n in s1]
dict = {}
for n in range(max(s1)):
    count = 0
    for val in s1:
    	if val in [n,n+1,n+2]:
    		count += 1
    dict.update({n+1:count})
print (sorted(dict.values())[-1])

Submission status: Runtime Error

Solution code:
a = input()
l = a.split()
n = int(l[0])
l.pop(0)

for i in range(n):
	l[i] = int(l[i])

counting = 0
list_i = []
for i in range(100000):
	counting = 0
	for j in range(n):
		if (l[j] == i or l[j] == i-1 or l[j] == i+1):
			counting += 1		
	list_i.append(counting)
			
print(max(list_i))

Submission status: Runtime Error

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