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: Accepted

Solution code:
#arc082c
from collections import Counter

n=int(raw_input())
a=map(int,raw_input().split())
a.insert(0,-float('inf'))
for i in xrange(1,n+1):
 a.append(a[i]-1)
 a.append(a[i]+1)
print Counter(a).most_common(1)[0][1]

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    a = list(map(int, input().split(" ")))
    ans_dict = {}
    for i in range(n):
        for j in [a[i]-1, a[i], a[i]+1]:
            if j in ans_dict.keys():
                ans_dict[j] += 1
            else:
                ans_dict[j] = 1
    
    print(max(ans_dict.values()))

solve()

Submission status: Accepted

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

N = int(input())

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

V = []
for a in As:
    V.append(a)
    V.append(a+1)
    V.append(a-1)

cnter = Counter(V)

#print(cnter.most_common(1))
key, ans = cnter.most_common(1)[0]

print(ans)

Submission status: Accepted

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

"""
b = [i + 1 for i in a]
c = [i - 1 for i in a]
use_set = set(a) | set(b) | set(c)
ans = 0
for i in use_set:
    ans = max(ans, a.count(i) + b.count(i) + c.count(i))
print(ans)
"""
#これだと最後でTLE
#inの段階でhash?

ans = {}
for i in a:
    for j in range(3):
        if i + j - 1 not in ans:
            ans[i + j - 1] = 1
        else:
            ans[i + j - 1] += 1

print(max(ans.values()))

Submission status: Accepted

Solution code:
#C問題 together
 
N = int(input())
a = list(map(int,input().split(" ")))
 

 
minval = min(a)
maxval = max(a)
l = (maxval - minval +1)
 
num = [0]*(l+2)

for i in a:
	num[i-minval] += 1

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

print(ans)

Submission status: Accepted

Solution code:
#C
from collections import Counter

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict

def C_Together():

    try:
        LOCAL_FLAG
        N = 3
        a = [6, 2, 6]
        # N = 4
        # numbers = [2, 5, 5, 2]
        N = 6
        a = [12, 22, 16, 22, 13, 12]

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

    counter = defaultdict(lambda: 0)
    for i in range(N):
        counter[a[i]] += 1

    results = 0
    key = -1

    for k, v in counter.items():
        temp = v + counter.get(k-1, 0) + counter.get(k+1, 0)
        if(temp > results):
            results = temp
            key = k

    print(results)
    

C_Together()

Submission status: Accepted

Solution code:
cnt = []
for _ in range(10**5+2):
	cnt.append(0)

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

for x in a:
	cnt[x] += 1
	if x > 0 : cnt[x-1] += 1
	cnt[x+1] += 1
	
answer = 0
for n in cnt:
	answer = max(answer, n)

print(answer)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
a = [int(i) for i in input().split(" ")]
dic_num=defaultdict(int)

for i in a:
    dic_num[i] += 1
ans = -1
for X in range(min(a),max(a)+1):
    tmp = (dic_num[X-1] + dic_num[X] + dic_num[X+1])
    if ans < tmp:
        ans = tmp
print(ans)

Submission status: Accepted

Solution code:
n = int(raw_input())
nums = map(int, raw_input().split())

pos = {}
for i in nums:
    if not i-1 in pos:
        pos[i-1] = 0
    if not i in pos:
        pos[i] = 0
    if not i+1 in pos:
        pos[i+1] = 0

    pos[i-1] += 1
    pos[i] += 1
    pos[i+1] += 1

print max(pos.values())

Submission status: Accepted

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

c_list = {}
for i in a:
	if i in c_list:
		c_list[i] += 1
	else:
		c_list[i] = 1

ans = 0
for k, v in c_list.items():
	_sum = c_list[k]
	if (k-1) in c_list:
		_sum += c_list[k-1]
	if (k+1) in c_list:
		_sum += c_list[k+1]
	if _sum > ans:
		ans = _sum
print(ans)

Submission status: Accepted

Solution code:
import sys
N = int(sys.stdin.readline())
data = [0] * 100000
for i in map(int,sys.stdin.readline().split()):
	data[i] += 1
print(max(map(sum,zip(data,data[1:],data[2:]))))

Submission status: Accepted

Solution code:
def main():
    N =  int(input())
    a = [int(i) for i in input().split()]
    #print(N)
    #print(a)
    
    count_ = [0] * ( max(a)+2 )
    #print(len(count_))
    #a_plus  = [ i+1 for i in a ]
    #a_sub = [ i-1 for i in a ]
    #print( [ i+1 for i in a ] )
    
    for num in a:
        if(num > 0):
            count_[num-1] += 1
            count_[num] += 1
            count_[num+1] += 1
        else:
            count_[num] += 1
            count_[num+1] += 1
    
    #print(count_)
    print(max(count_))
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

rs = max(c[x-1] + c[x] + c[x+1] for x in range(0, 10**5 + 1))

print(rs)

Submission status: Accepted

Solution code:
import sys
import copy
import numpy as np

from math import *
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func()
    input_str = input_raw.strip().split()
    value_dic = {}
    for i in range(N):
        val = int(input_str[i])
        if val in value_dic:
            value_dic[val] += 1
        else:
            value_dic[val] = 1

        if val - 1 in value_dic:
            value_dic[val - 1] += 1
        else:
            value_dic[val - 1] = 1

        if val + 1 in value_dic:
            value_dic[val + 1] += 1
        else:
            value_dic[val + 1] = 1

    print max(value_dic.values())

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

N=input()
nums=map(int,raw_input().split(' '))
num = np.zeros(100000,dtype='int')
for i in nums:
    num[i] = num[i] + 1
max=0
for i in range(100000-2):
    if max < num[i] + num[i+1] + num[i+2]:
        max = num[i] + num[i+1] + num[i+2]
print max

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
N = int(input())
A = tuple(map(int, input().split()))

c0 = Counter()
c1 = Counter()
c2 = Counter()
for a in A:
    c0[(a+0)//3] += 1
    c1[(a+1)//3] += 1
    c2[(a+2)//3] += 1
    
print(max(max(c0.values()),
          max(c1.values()),
          max(c2.values())))

Submission status: Accepted

Solution code:
import collections
n = input()
a = list(map(int, input().split()))
s = collections.Counter(a);
res = 0
for i in range(10 ** 5 + 1):
    b = 0
    if i in s:
        b += s[i]
    if i - 1 in s:
        b += s[i - 1]
    if i + 1 in s:
        b += s[i + 1]
    res = max(res, b)
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=input()
s=raw_input().split()
a=[0 for i in range(n)]
b=[0 for i in range(100005)]
mini=1000005
maxi=-1
for i in range(n):
    a[i]=int(s[i])
    b[a[i]]+=1
maxi=-1
for i in range(100001):
    maxi=max(maxi,b[i]+b[i+1]+b[i+2])
print maxi

Submission status: Accepted

Solution code:
n=input()
a=[int(x) for x in input().split()]
num=a+[i+1 for i in a]+[i-1 for i in a]
from collections import Counter
c=Counter(num)
print(c.most_common(1)[0][1])

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    a = input()
    a = a.split(' ')
    a = list(map(int, a))

    min_a = min(a)
    max_a = max(a)

    num = []

    for i in range(max_a+1):
        num.append(0)

    for i in a:
        if i-2 >= 0:
            num[i-2] += 1
        if i-1 >= 0:
            num[i-1] += 1
        num[i] += 1

    c = max(num)
    print(c)

Submission status: Accepted

Solution code:
N = int(input())

M = 10**5

L = [0]*M


for i in map(int,input().split()):
  L[i] += 1

c = sum(L[:3])
b = c

for i,j in zip(range(3,M),range(M-3)):
  c += L[i]
  c -= L[j]
  b = max(b,c)

print(b)

Submission status: Accepted

Solution code:
import sys 

N = int(sys.stdin.readline())
alist = map(int, sys.stdin.readline().strip().split())
summary = {}
for a in alist:
    summary[a] = summary.get(a, 0) + 1                                                                                                                                                                                                
    summary[a - 1] = summary.get(a -1, 0) + 1 
    summary[a + 1] = summary.get(a +1, 0) + 1 
print max(summary.values())

Submission status: Accepted

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

l1=[0]*(100002)

for i in range(n):
	l1[l[i]]+=1
	l1[l[i]+1]+=1
	l1[l[i]-1]+=1

print(max(l1))

Submission status: Accepted

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

count = {}
ans = 1
def INC(x):
    global count
    if x in count:
        count[x] += 1
    else:
        count[x] = 1

for x in A:
    INC(x-1)
    INC(x)
    INC(x+1)

for a, b in count.items():
    ans = max(ans, b)
print ans

Submission status: Accepted

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

freqs = [0 for i in range(100003)]

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

res = 0
for i in range(1,100002):
  res = max(res, freqs[i-1] + freqs[i] + freqs[i+1])

print(res)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))

    result_counter = [0 for i in range(100001)]
    for number in a:
        if number == 0:
            result_counter[0] += 1
            result_counter[1] += 1
        else:
            result_counter[number - 1] += 1
            result_counter[number] += 1
            result_counter[number + 1] += 1

    print(max(result_counter))

Submission status: Accepted

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

B = []
for i in A:
    B.append(i - 1)
    B.append(i)
    B.append(i + 1)
B.sort()

C = []
count = 0
for i in range(len(B)):
    if B[i] == B[i - 1]:
        count += 1
    else:
        C.append(count + 1)
        count = 0

print(max(C))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
ap = [e + 1 for e in a]
am = [e - 1 for e in a]

table = [0 for _ in range(10**5 + 2)]
for e in a:
    table[e + 1] += 1
    table[(e+1) + 1] += 1
    table[(e-1) + 1] += 1
print(max(table))

Submission status: Accepted

Solution code:
n=int(raw_input())
N=map(int,raw_input().split())
a=[0]*(10**5+10)
for i in N:
    if i==0:
        a[i]+=1
        a[i+1]+=1
    else:
        a[i-1]+=1
        a[i]+=1
        a[i+1]+=1
print max(a)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
a_list = list(map(int, input().split()))
am_list = list(map(lambda x: x - 1, a_list))
ap_list = list(map(lambda x: x + 1, a_list))
data = a_list + am_list + ap_list
c = Counter(data)
print(c.most_common(1)[0][1])

Submission status: Accepted

Solution code:
input()
k = [0] * 100000
for a in map(int, input().split()):
    k[a] += 1
print(max(map(sum, zip(k, k[1:], k[2:]))))

Submission status: Accepted

Solution code:
n=int(raw_input())
a=[int(i) for i in raw_input().split(' ')]
res={}
for i in a:
    for p in (i,i-1,i+1):
            res[p]=res.get(p,0)+1
if len(res)>0:
    print  max(res.values())

Submission status: Accepted

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

counts = [0] * (10**5 + 2)
for a_i in a:
    counts[a_i + 1] += 1

counts_all = [0] * (10**5)
for i in range(10**5):
    counts_all[i] += (counts[i] + counts[i + 1] + counts[i + 2])

print(max(counts_all))

Submission status: Accepted

Solution code:
n = int(raw_input())
nums = map(int, raw_input().split())
from collections import Counter
c = Counter(nums)
ans = 0
for k in c:
    ans = max(ans, c[k] + c[k-1] + c[k+1])
print ans

Submission status: Accepted

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

cnt = {}
for x in ar:
        def add(x):
                if x in cnt:
                        cnt[x] += 1
                else:
                        cnt[x] = 1
        add(x-1)
        add(x)
        add(x+1)

counts = map(lambda x: x[1], cnt.items())
ans = max(counts)

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
N = int(input())
A = tuple(map(int, input().split()))

c0 = Counter()
c1 = Counter()
c2 = Counter()
for a in A:
    c0[(a+0)//3] += 1
    c1[(a+1)//3] += 1
    c2[(a+2)//3] += 1
    
print(max(sorted(c0.values(), reverse = True)[0],
          sorted(c1.values(), reverse = True)[0],
          sorted(c2.values(), reverse = True)[0]))

Submission status: Accepted

Solution code:
import collections


M = 10 ** 5 + 10


def solve(n, xs):
    ctr = collections.Counter(xs)
    freqs = [ctr[i] for i in range(0, M)]
    res = max(sum(freqs[i: i + 3]) for i in range(M - 3))
    return res


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    print(solve(n, xs))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
xs = [int(x) for x in input().split()]
xmap = {}
for x in xs:
    if x in xmap:
        xmap[x] += 1
    else:
        xmap[x] = 1
    if x+1 in xmap:
        xmap[x+1] += 1
    else:
        xmap[x+1] = 1
    if x-1 in xmap:
        xmap[x-1] += 1
    else:
        xmap[x-1] = 1
ret = 0
for x in xmap.keys():
    if xmap[x] > ret:
        ret = xmap[x]
print(ret)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
sys.setrecursionlimit(10**6)
n=int(input())
a=[int(i) for i in input().split()]
b=[]
for i in range(n):
 b.append(a[i])
 b.append(a[i]+1)
 b.append(a[i]-1)
c = Counter(b).most_common(1)
print(c[0][1])

Submission status: Accepted

Solution code:
#Together

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

b = []

for ai in a:
    b.append(ai-1)
    b.append(ai)
    b.append(ai+1)
#print(b)

import collections
cnt = collections.Counter(b)
#print(cnt)
print(max(cnt.values()))

Submission status: Accepted

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

a.sort()
count = []
for i in range(100001 + 1):
    count.append(0)

for num in a:
    count[num] += 1

max = 0
for i in range(1, 100001):
    res = count[i - 1] + count[i] + count[i + 1]
    if (res > max):
        max = res

print(max)

Submission status: Accepted

Solution code:
N=input()
a=map(int,raw_input().split())
d={}
for i in a:
        d[i]=1+d.get(i,0)
        d[i-1]=1+d.get(i-1,0)
        d[i+1]=1+d.get(i+1,0)
print max(d.values())

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    c = defaultdict(int)
    for i in A:
        c[i] += 1
        c[i - 1] += 1
        c[i + 1] += 1
    print(sorted(c.items(), key=lambda x: x[1], reverse=True)[0][1])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def spaceinput():
    return list(map(int,input().split(" ")))


N=int(input())
a=spaceinput()

#a=sorted(a)

H=[0]*(10**5+1)
for sa in a:
    H[sa]+=1

maxsum=0
for i in range(1,len(H)-1):
    sum=H[i-1]+H[i]+H[i+1]
    if maxsum<sum:
        maxsum=sum

print(maxsum)

Submission status: Accepted

Solution code:
N = int(raw_input())
arr = map(int, raw_input().split(" "))

d = {}
for a in arr:
  d[a-1] = d.get(a-1, 0) + 1
  d[a] = d.get(a, 0) + 1
  d[a+1] = d.get(a+1, 0) + 1

answer = 0
for v in d.itervalues():
  if v > answer: answer = v

print answer

Submission status: Accepted

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

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

    for a in A:
        D[a] += 1
        D[a+1] += 1
        if a-1 >= 0:
            D[a-1] += 1

    print(max(D))

        
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# encoding:utf-8
def main():
	n = int(input())
	nums = list(map(int, input().split()))
	counter = [0 for _ in range(max(nums) + 3)]

	for x in nums:
		counter[x] += 1
		counter[x + 1] += 1
		counter[x + 2] += 1

	print(max(counter))

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    al = [int(i) + 1 for i in input().split()]
    amax = max(al) + 3
    ans = [0] * amax
    for i in al:
        ans[i] += 1
        ans[i-1] += 1
        ans[i+1] += 1
    print(max(ans))



if __name__=="__main__":
    solve()

Submission status: Accepted

Solution code:
N=int(raw_input())
A=map(int, raw_input().split())
B = [0 for i in range (100000+3)]
for a in A:
    B[a+2]+=1
    B[a+1]+=1
    B[a]+=1
print max(B)

Submission status: Accepted

Solution code:
# C
N = int(input())
a_list = list(map(int, input().split()))
cnt_dict = dict()

for a in a_list:
    if a not in cnt_dict.keys():
        cnt_dict[a] = 0
    cnt_dict[a] += 1
    if a+1 not in cnt_dict.keys():
        cnt_dict[a+1] = 0
    cnt_dict[a+1] += 1
    if a-1 not in cnt_dict.keys():
        cnt_dict[a-1] = 0
    cnt_dict[a-1] += 1

print(max(list(cnt_dict.values())))

Submission status: Accepted

Solution code:
from collections import Counter

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

value_counter = Counter()
for value in idx___value:
    value_counter[value] += 1
    value_counter[value + 1] += 1
    value_counter[value - 1] += 1

print(max(value_counter.values()))

Submission status: Accepted

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

cnt = {}
for ai in a:
    if ai in cnt:
        cnt[ai] += 1
    else:
        cnt[ai] = 1

ans = 0
for ai in cnt.keys():
    tmp = cnt[ai]
    tmp += cnt[ai - 1] if (ai - 1) in cnt else 0
    tmp += cnt[ai + 1] if (ai + 1) in cnt else 0
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N = int(input())
As = list(map(int, input().split()))
c = Counter(As)

ans = 0
for i in range(100000):
    ans = max(ans, c[i-1] + c[i] + c[i+1])
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
from collections import defaultdict

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


def read():
    N = II()
    a = ILI()
    return N, a


def solve(N, a):
    count = defaultdict(int)
    for _a in a:
        count[_a - 1] += 1
        count[_a] += 1
        count[_a + 1] += 1
    l_count = list(count.items())
    l_count.sort(key = lambda x: -x[1])
    ans = l_count[0][1]
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

cnt =[0 for i in range(10**5+2)]
for i in range(n):
    cnt[a[i]] += 1
    cnt[a[i]+1] += 1
    cnt[a[i]+2] += 1
print(max(cnt))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = []
for a in map(int, input().split()):
    A.append(a)
    A.append(a + 1)
    A.append(a - 1)
print(Counter(A).most_common(1)[0][1])

Submission status: Accepted

Solution code:
# coding: utf-8

import collections

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

    c = collections.Counter()
    for i in a:
        c[i] += 1
        c[i-1] += 1
        c[i+1] += 1
    return c.most_common(1)[0][1]


print(main())

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
f = [0 for i in range(100005)]
for x in a:
    f[x + 1] += 1
maks = 0
for i in range(1, 100002):
    maks = max(maks, f[i - 1] + f[i] + f[i + 1])
print(maks)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    a = LI()
    d = collections.defaultdict(int)
    for c in a:
        d[c-1] += 1
        d[c] += 1
        d[c+1] += 1

    return max(d.values())


print(main())

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
C = Counter(map(int, input().split()))
opt = -1
for x in C:
    opt = max(opt, C[x-1]+C[x]+C[x+1])
print(opt)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
L = [0 for i in range(max(A)+1)]
for i in range(N):
  L[A[i]] += 1
mL = []
for j in range(len(L)-2):
  mL.append(L[j] + L[j+1] + L[j+2])

print(max(mL))

Submission status: Runtime Error

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

if len(set(a)) == 1:
    print(n)
    exit()
elif len(set(a)) == n:
    print(3)

c = Counter(a)
mc = c.most_common()[0][0]
# if mc == 0:
#     mc = c.most_common()[1][0]

# if 10**5 - 1 > mc > 1:
#     ans = c.most_common()[0][1] + a.count(mc-1) + a.count(mc+1)
# elif mc == 1:
#     ans = a.count(1) + a.count(2) + a.count(3)

if mc-1 in a and mc+1 in a:
    ans = a.count(mc-1) + a.count(mc) + a.count(mc+1)
elif (mc-1 not in a) and (mc+1 in a):
    ans = a.count(mc) + a.count(mc+1) + a.count(mc+2)
elif (mc-1 in a) and (mc+1 not in a):
    ans = a.count(mc) + a.count(mc-1) + a.count(mc-2)

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
A=sorted(list(map(int,input().split())))
L={}
if n==1:
        print(1)
elif n==2:
    if abs(A[0]-A[1])==1:
        print(2)
    else:
        print(1)
else:
    for i in A:
        if i not in L:
            L[i]=1
        else:
            L[i]+=1
    print(L)
    ans=[]
    for j in range(A[0],A[-1]+1):
        if (j in L) and (j-1 in L) and (j+1 in L):
            ans.append(L[j]+L[j+1]+L[j-1])
        elif (j in L) and (j-1 in L):
            ans.append(L[j-1]+L[j])
        elif (j in L) and (j+1 in L):
            ans.append(L[j+1]+L[j])
        elif (j-1 in L) and (j+1 in L):
            ans.append(L[j+1]+L[j-1])
        elif (j in L):
            ans.append(L[j])
print(max(ans))

Submission status: Runtime Error

Solution code:
n=int(input())
A=sorted(list(map(int,input().split())))
L={}
for i in A:
    if i not in L:
        L[i]=1
    else:
        L[i]+=1
ans=[]
for j in range(A[0],A[-1]+1):
    if j in L:
        if j-1 in L:
            if j+1 in L:
                ans.append(L[j]+L[j+1]+L[j-1])
if len(A)>=3:
    print(max(ans))
else:
    if len(A)==1:
        print(1)
    else:
        if abs(A[0]-A[1])==1:
            print(2)
        else:
            print(1)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
#ARC082C
import copy
import sys
import math

n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

hoge.sort()
hoge.append(-1)
a=0
b=0
c=1
maxhoge=0
for i in range(0,n):
	if(hoge[i]!=hoge[i+1]):
		if(i!=n-1):
			if(hoge[i+1]-hoge[i]==1):
				a=b
				b=c
				c=1
			elif(hoge[i+1]-hoge[i]==2):
				a=c
				b=0
				c=1
			else:
				a,b=0
				c=1
	else:
		c+=1
#	print("i:{} | {} {} {}".format(i,a,b,c))

	maxhoge=max(maxhoge,a+b+c)



#print(hoge)
print(maxhoge)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    ll n ;
    cin >> n ;
    vl v;
    ll cnt[100005];
    ms(cnt) ;
    forn(i ,  1  , n ) {
       ll x;
       cin >> x;
       v.pb(x);
       cnt[x]++;
    }
    ll ans = 0;
    ll sum = cnt[0] + cnt[1] + cnt[2] ;
    ans = max(ans ,sum) ;
    forn(i , 3 , 100000){
       ll res = sum + cnt[i] - cnt[i-3];
       sum = res ;
       ans = max(ans, sum ) ;
    }
    cout << ans << el ;
}

Submission status: Runtime Error

Solution code:
n = int(input())

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

b ={i:0 for i in range(min(a)-1,max(a)+10)}

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

c = 0
for i in range(1,len(b)-3):
    c = max(c,b[i]+b[i+1]+b[i+2])
print(c)

Submission status: Runtime Error

Solution code:
N = int(input())
a = [0 for i in range(N)]
st = input().split()
for i in range(N):
  a[i] = int(st[i])
m = min(a); M = max(a)
b = [0 for i in range(M - m + 1)]
for i in range(N):
  b[a[i]-m] += 1
c = [0 for i in range(M - m + 1)]
c[0] = b[0] + b[1]
c[M - m] = b[M - m] + b[M - m - 1]
for i in range(1, M - m):
  c[i] = b[i-1] + b[i] + b[i+1]
print(max(c))

Submission status: Runtime Error

Solution code:
rt numpy as np
N = int(input())
a = [int(i) for i in input().split(" ")]
a = np.array(a,dtype='int')
def count(a):
    return [1 if i==1 or i== 0 or i == -1 else 0 for i in a]
if N == 1:
    print(1)
else:
    min_ = min(a)-1
    max_ = max(a)+1
    ans = -1
    for K in range(min_,max_):
        b = a - K
        tmp = sum(count(b))
        if ans < tmp:
            ans = tmp
    print(ans)

Submission status: Runtime Error

Solution code:
import sys
N = int(sys.stdin.readline())
data = [0] * 10000
for i in map(int,sys.stdin.readline().split()):
	data[i] += 1
print(max(map(sum,zip(data,data[1:],data[2:]))))

Submission status: Runtime Error

Solution code:
# 23:30~0:30

import pandas as pd
import re
import statistics as st
import numpy as np

ELEM_MAX = 10**5
counter = np.zeros(ELEM_MAX+1)

def count(x):
    counter[x] += 1

# 入力部
N = input()
a = input()

# 前処理部
# 文字列リストに変換
a = re.split(' ', a)

# intに変換
N = int(N)
a = list(map(int, a))

# Series->DataFrameに変換
a = pd.Series(a)
# df = pd.DataFrame([a-1, a, a+1])

for x, y, z in zip(a-1, a, a+1):
    count(x)
    count(y)
    count(z)
    
# 出力部
print(int(counter.max()))

# 最頻値を求めるライブラリを探したり、
# data frame のイテレーション操作で時間がかかった

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    N = int(input())
    a = input()
    a = a.split(' ')
    a = list(map(int, a))

    min_a = min(a)
    max_a = max(a)

    num = []

    for i in range(max_a+1):
        num.append(0)

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

    c = max(num)
    print(c)

Submission status: Runtime Error

Solution code:
X = int(raw_input())
K = int(raw_input())
rs = map(int, raw_input().split(" "))
Q = int(raw_input())
qs = []

for q in xrange(Q):
  qs.append(map(int, raw_input().split(" ")))

memo = {}

l = len(qs)
for i in xrange(l):
  t = 0
  start = qs[i][1]
  s = start
  end = qs[i][0]
  pre = 0
  k = 0
  if start in memo:
    j = 0
    lm = len(memo) - 1
    while True:
      if j == lm or end < rs[j+1]: break
      j += 1
    k = j+1
    pre = rs[j]
    s = memo[start][j]
  while k < K:
    r = rs[k]
    if r >= end: break
    if k % 2 == 0:
      s = max(0, s - (r - pre))
    else:
      s = min(X, s + (r - pre))
    if start not in memo: memo[start] = {}
    memo[start][k] = s
    k += 1
    pre = r

  if k % 2 == 0:
    s = max(0, s - (end - pre))
  else:
    s = min(X, s + (end - pre))
  print s

Submission status: Runtime Error

Solution code:
x=int(raw_input())
k=int(raw_input())
R=[int(i) for i in raw_input().split(' ')]
Q=int(raw_input())
RES=[]
for q in range(Q):
    RES.append((int(i) for i in raw_input().split(' ')))
tintervals=[[0,R[0],R[0]]]
if k>1:
    for ts in range(1,len(R)):
        tintervals.append([R[ts-1],R[ts],R[ts]-R[ts-1]])
for t, a in RES:
    for i,r in enumerate(tintervals):
        j=i%2+1
        if t>=r[0]:
            if t<=r[1]:
                a=max(a+((-1)**j)*(t-r[0]),0)
                a=min(a,x)
                print a
                break
            else:
                a=max(a+((-1)**j)*r[2],0)
                a=min(a,x)
    if t > tintervals[-1][1]:
        j=(i+1)%2+1
        a=max(a+((-1)**j)*(t-tintervals[-1][1]),0)
        a=min(a,x)
        print a