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:
# 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 count_and_del(xs):
    cnt = 0
    fst = xs[-1]
    for x in reversed(xs):
        if x != fst:
            break
        cnt += 1
    del xs[-cnt:]
    return cnt   


def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    xs.sort(reverse=True)
    ys = defaultdict(int)
    while xs:
        key = xs[0]
        cnt = count_and_del(xs)
        ys[key] += cnt
        ys[key-1] += cnt
        ys[key+1] += cnt

    print(max(ys.values()))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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(0, 10002):
        temp = ys.get(i-1, 0) + ys.get(i, 0) + ys.get(i+1, 0)
        if m < temp:
            m = temp
    print(m)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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) + ys.get(i, 0) + ys.get(i+1, 0)
        if m < temp:
            m = temp
    print(m)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())

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

count = 0

while True:
    if A[count] < lenA:
        A[count] += 1

    elif A[count] > lenA:
        A[count] -= 1

    count += 1
    if count == N:
        break

Acounter = Counter(A)

x = Acounter.most_common()[0]
X = x[1]
print(X)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())

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

count = 0

while True:
    if A[count] < lenA:
        A[count] += 1

    elif A[count] > lenA:
        A[count] -= 1

    count += 1
    if count == N:
        break

Acounter = Counter(A)

x = Acounter.most_common()[0]
X = x[0]
print(X)

Submission status: Wrong Answer

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

print(max(a))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())

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

count = 0

while True:
    if A[count] < lenA:
        A[count] += 1

    elif A[count] > lenA:
        A[count] -= 1

    count += 1
    if count == N:
        break

Acounter = Counter(A)

print(str(Acounter.most_common()[0])[1])

Submission status: Wrong Answer

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 i<len(a) and k<len(a): 
    j+=1
    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
print(x)

Submission status: Wrong Answer

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]
    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 (_, x) in zs:
        temp = ys.get(x-1, 0) + ys.get(x, 0) + ys.get(x+1, 0)
        if m < temp:
            m = temp
        else:
            break
    print(m)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
X = input().split()

counter = Counter(X)

Keys = [int(key) for key in counter]
max = max(Keys)
min = min(Keys)

S_max = 1
for i in range(min, max):
  S = counter[str(i-1)] + counter[str(i)] + counter[str(i+1)]
  if S > S_max:
    S_max = S

    
print(S_max)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
X = input().split()

counter = Counter(X)

Keys = [int(key) for key in counter]
max = max(Keys)
min = min(Keys)

S_max = 1
for i in range(min+1, max):
  S = counter[str(i-1)] + counter[str(i)] + counter[str(i+1)]
  if S > S_max:
    S_max = S

    
print(S_max)

Submission status: Wrong Answer

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)
    else:
        tmp = len(countQ)
        if maxAns < tmp:
            maxAns = tmp
        countQ.append(a)
        first = countQ[0]
        while first in countQ:
            countQ.pop(0)
print(maxAns)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
X = input().split()

counter = Counter(X)

Keys = [int(key) for key in counter]
max = max(Keys)
min = min(Keys)

S_max = 0
for i in range(min+1, max):
  S = counter[str(i-1)] + counter[str(i)] + counter[str(i+1)]
  if S > S_max:
    S_max = S

    
print(S_max)

Submission status: Wrong Answer

Solution code:
def C_Together(N, a):
    lst = [0] * (max(a) + 2) #配列0スタートを考慮、番兵も入れる
    for i in a:
        lst[i] += 1

    ans = 0
    for i in range(1, len(lst) - 1):
        tmp = lst[i - 1] + lst[i] + lst[i + 1]
        ans = max(ans,tmp)
    return ans

N = int(input())
a = [int(i) for i in input().split()]
print(C_Together(N, a))

Submission status: Wrong Answer

Solution code:
a = input()
i = list(map(int, input().split()))
X = 0

i = [s + 2 for s in i]
for w in range(3):
  i = [s - 1 for s in i]
  for s in i:
    x = i.count(s)
    if(x > X):
      X = x

print(X)

Submission status: Wrong Answer

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

s = [int(i) for i in sorted(set(a))]

ans = 0

if len(a) == 1:
    ans = 1
elif len(a) == 2:
    if a[1] - a[0] <= 2:
        ans = 2
    else:
        ans = 1
else:
    
    temp_single = temp_two_sum = temp_three_sum = 0
    for i in range(len(s)):
        temp_single = a.count(s[i])
        
        if i < len(s)-1:
            if s[i+1]-s[i] == 1:
                temp_two_sum = a.count(s[i]) + a.count(s[i+1])
                
        if i < len(s)-2:
            if s[i+2] - s[i] == 2:
                temp_three_sum = a.count(s[i]) + a.count(s[i+1]) + a.count(s[i+2])
        
        if ans < temp_three_sum:
            ans = temp_three_sum
        
        if ans < temp_two_sum:
            ans = temp_two_sum
        if ans < temp_single:
            ans = temp_single
print(ans)

Submission status: Wrong Answer

Solution code:
i = list(map(int, input().split()))
X = 0

i = [s + 2 for s in i]
for w in range(3):
  i = [s - 1 for s in i]
  for s in i:
    x = i.count(s)
    if(x > X):
      X = x

print(X)

Submission status: Wrong Answer

Solution code:
i = list(map(int, input().split()))
X = 0

i = [s + 1 for s in i]
for w in range(2):
  i = [s + 1 for s in i]
  for s in i:
    x = i.count(s)
    if(x > X):
      X = x

print(X)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
 
set_a = set(a)
cnt = [0] * (max(a)+1)
ans = 0
 
for i in a:
    cnt[i] += 1
 
if N >=3:
    for i in range(max(a)):
        ans = max(ans, cnt[i-1]+cnt[i]+cnt[i+1])
    print(ans)
elif N == 2:
    if abs(a[0] - a[1]) <= 2:
        print(2)
    else:
        print(1)
 
else:
    print(1)

Submission status: Wrong Answer

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

s = [int(i) for i in sorted(set(a))]

ans = 0

if len(a) == 1:
    ans = 1
elif len(a) == 2:
    if a[1] - a[0] <= 2:
        ans = 2
    else:
        ans = 1
else:
    
    temp_single = temp_sum = 0
    for i in range(len(s)):
        temp_single = a.count(s[i])
        if i < len(s)-2:
            if s[i+2] - s[i] == 2:
                temp_sum = a.count(s[i]) + a.count(s[i+1]) + a.count(s[i+2])
          
        if ans < temp_sum:
            ans = temp_sum
            
        if ans < temp_single:
            ans = temp_single
print(ans)

Submission status: Wrong Answer

Solution code:
def C_Together(N, a):
    lst = [0] * (max(a) + 1)
    for i in a:
        lst[i] += 1
    ans = 0
    for i in range(1, len(lst) - 1):
        tmp = lst[i - 1] + lst[i] + lst[i + 1]
        if tmp >= ans:
            ans = tmp
    return ans

N = int(input())
a = [int(i) for i in input().split()]
print(C_Together(N, a))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
 
set_a = set(a)
cnt = [0] * (max(a)+1)
ans = 0
 
for i in a:
    cnt[i] += 1
 
if N >=3:
    for i in range(1, max(a)):
        ans = max(ans, cnt[i-1]+cnt[i]+cnt[i+1])
    print(ans)
elif N == 2:
    if abs(a[0] - a[1]) <= 2:
        print(2)
    else:
        print(1)
 
else:
    print(1)

Submission status: Wrong Answer

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

s = [int(i) for i in sorted(set(a))]

ans = 0

if len(a) == 1:
    ans = 1
elif len(a) == 2:
    if a[1] - a[0] <= 2:
        ans = 2
    else:
        ans = 1
else:
    
    for i in range(len(s)-2):
        if s[i+2] - s[i] == 2:
            temp = a.count(s[i]) + a.count(s[i+1]) + a.count(s[i+2])
            if ans < temp:
                ans = temp

print(ans)

Submission status: Wrong Answer

Solution code:
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)

abc = a + b + c
count = [0] * (max(abc) + 1)

for x in abc:
    count[x] += 1

print(max(count))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
temp = input()
a = np.array([int(i) for i in temp.split()])

num_X = 0

for max_new in range(max(a)+2):
    X_new = 0
    X_new += len(np.where(a == max_new))
    X_new += len(np.where(a+1 == max_new))
    X_new += len(np.where(a-1 == max_new))
    num_X = max(num_X, X_new)

print(num_X)

Submission status: Wrong Answer

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

a_2 = 0
a_1 = 0

ans = 0

for i in range(1, max(A)+3):
    a = A.count(i)
    if i > 2:
        tmp = a + a_1 + a_2
        if ans < tmp:
            ans = tmp
            
    a_2 = a_1
    a_1 = a
            
print(ans)

Submission status: Wrong Answer

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

set_a = set(a)
cnt = [0] * (max(a)+1)
ans = 0

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

if N >=3:
    for i in range(1, max(a)):
        if cnt[i] and cnt[i-1] and cnt[i+1]:
            ans = max(ans, cnt[i-1]+cnt[i]+cnt[i+1])
    print(ans)
elif N == 2:
    if abs(a[0] - a[1]) <= 2:
        print(2)
    else:
        print(1)

else:
    print(1)

Submission status: Wrong Answer

Solution code:
N = int(input())						# 5
a = [int(i) for i in input().split()]	# 1 2 3 4 5 ...


a_max = max(a)
a_min = min(a)

# print(a_max)
# print(a_min)


l = [0] * (a_max+2) # *を用いた初期化 ← こっちの方が高速

for i in range(N):
	x = a[i]
#	print(x, l[x])

	l[x]   = l[x]   + 1
	l[x-1] = l[x-1] + 1
	l[x+1] = l[x+1] + 1

#print(l)
l[0] = 0
l[len(l)-1] = 0
print(max(l))

Submission status: Wrong Answer

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]
    print(ans)
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: Wrong Answer

Solution code:
def solve():
    N = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i in range(1,10):
        check = a.count(i)
        check2 = a.count(i-1)
        check3 = a.count(i+1)
        if ans < check+check2+check3:
            ans = check+check2+check3

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())						# 5
a = [int(i) for i in input().split()]	# 1 2 3 4 5 ...


a_max = max(a)
a_min = min(a)

# print(a_max)
# print(a_min)


l = [0] * (a_max+2) # *を用いた初期化 ← こっちの方が高速

for i in range(N):
	x = a[i]
#	print(x, l[x])

	l[x]   = l[x]   + 1
	l[x-1] = l[x-1] + 1
	l[x+1] = l[x+1] + 1

#print(l)
print(max(l))

Submission status: Wrong Answer

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

cnt = []
ans = 0

for i in range(1, max(A)+1):
    cnt.append(A.count(i))
    if i > 2:
        tmp = sum(cnt[i-3:i])
        if ans < tmp:
            ans = tmp
            
print(ans)

Submission status: Wrong Answer

Solution code:
#!usr/bim/python
#! -*- coding: utf-8 -*-

import copy

n = raw_input()
n = int(n)

al = raw_input()
al = al.split()
al = map(int,al)

al.sort()

x = 0
y = 0
z = 0

mae = 0
saidai = 0

for i in range(n):
    a = al[i]
    if a == mae:
        x += 1
        if not y == 0:
            y += 1
        if not z == 0:
            z += 1
    elif a == mae + 1:
        if z > saidai:
            saidai = copy.copy(z)
        z = copy.copy(y) + 1
        y = copy.copy(x) + 1
        x = 1
    elif a == mae + 2:
        if z > saidai:
            saidai = copy.copy(z)
        z = 0
        y = copy.copy(x) + 1
        x = 1
    else:
        if z > saidai:
            saidai = copy.copy(z)
        z = 0
        y = 0
        x = 1
    mae = a

if x > saidai:
    saidai = x
if y > saidai:
    saidai = y

print saidai

Submission status: Wrong Answer

Solution code:
#!usr/bim/python
#! -*- coding: utf-8 -*-

import copy

n = raw_input()
n = int(n)

al = raw_input()
al = al.split()
al = map(int,al)

al.sort()

x = 0
y = 0
z = 0

mae = 0
saidai = 0

for i in range(n):
    a = al[i]
    if a == mae:
        x += 1
        y += 1
        z += 1
    elif a == mae + 1:
        if z > saidai:
            saidai = copy.copy(z)
        z = copy.copy(y) + 1
        y = copy.copy(x) + 1
        x = 1
    elif a == mae + 2:
        if z > saidai:
            saidai = copy.copy(z)
        z = 0
        y = copy.copy(x) + 1
        x = 1
    else:
        if z > saidai:
            saidai = copy.copy(z)
        z = 0
        y = 0
        x = 1
    mae = a

if x > saidai:
    saidai = x
if y > saidai:
    saidai = y

print saidai

Submission status: Wrong Answer

Solution code:
num=raw_input()
tmp=map(int, raw_input().split(" "))
arr=[]
for i in range(1,10):
    arr.append(tmp.count(i))


#print arr
out=[]
for n,i in enumerate(arr):
    if n==0:
        out.append(arr[n]+arr[n+1])
    elif n==8:
        out.append(arr[n]+arr[n-1])
    else:
        out.append(arr[n]+arr[n-1]+arr[n+1])

print max(out)

Submission status: Wrong Answer

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

L = [0 for i in range(max(A)+2)]


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


print(max(L))

Submission status: Wrong Answer

Solution code:
#!usr/bim/python
#! -*- coding: utf-8 -*-

import copy

n = raw_input()
n = int(n)

al = raw_input()
al = al.split()
al = map(int,al)

al.sort()

x = 0
y = 0
z = 0

mae = 0
saidai = 0

for i in range(n):
    a = al[i]
    if a == mae:
        x += 1
        y += 1
        z += 1
    elif a == mae + 1:
        if z > saidai:
            saidai = copy.copy(z)
        z = copy.copy(y) + 1
        y = copy.copy(x) + 1
        x = 1
    elif a == mae + 2:
        if z > saidai:
            saidai = copy.copy(z)
        z = 0
        y = copy.copy(y) + 1
        x = 1
    else:
        if z > saidai:
            saidai = copy.copy(z)
        z = 0
        y = 0
        x = 1
    mae = a

if x > saidai:
    saidai = x
if y > saidai:
    saidai = y

print saidai

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N = int(line)
        a = map(lambda x: int(x), sys.stdin.readline().split(" "))

        histogram = [0 for i in xrange(100000 + 1)]
        for i in a:
            histogram[i - 1] += 1
            histogram[i] += 1
            histogram[i + 1] += 1
        print(max(histogram[1:]))
            
        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Submission status: Wrong Answer

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

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

for n in a:
    t[n-1]+=1
    t[n]+=1
    t[n+1]+=1

print max(t)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int, input().split()))
MaxA = max(As) + 1
numbers = [0] * (MaxA+1)
for i in range(N):
    A = As[i]
    numbers[A-1] += 1
    numbers[A] += 1
    numbers[A+1] += 1
print(max(numbers))

Submission status: Wrong Answer

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

cnt = []

for i in range(1, max(A)+1):
    cnt.append(A.count(i))

ans = 0
for i in range(max(A)-2):
    if ans < sum(cnt[i:i+3]):
        ans = sum(cnt[i:i+3])
print(ans)

Submission status: Wrong Answer

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

for j in range(m):
    x = a.count(j-1)
    y = a.count(j)
    z = a.count(j+1)
    w = x+y+z
    if w > ans:
        ans = w

print(ans)

Submission status: Wrong Answer

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

b = []

for i in range(N):
    b.append(a.count(i-1) + a.count(i) + a.count(i+1))

print(max(b))

Submission status: Wrong Answer

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

L = [A.count(i) for i in range(max(A)+1)]

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


print(res)

Submission status: Wrong Answer

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
for i in di:
 if di[i] > di.get(ans,0):
  ans = i
print ans

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a_i = [int(s) for s in input().split()]

def match_count(X, a_i):
    num = 0
    for a in a_i:
        if a+1 == X or a == X or a-1 == X:
            num += 1
    return num

a_i.sort()
X = 0
x = 0
max_num = 0
for a in a_i:
    for i in range(3):
        x = a-1+i
        num = match_count(x, a_i)
        if max_num < num:
            max_num = num
            X = x

print(max_num)

Submission status: Time Limit Exceeded

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

for i in range(100000):
  B = [j for j in A if i-1 <= j <= i+1]
  if ans < len(B):
    ans = len(B)
    
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for X in range(1, 10 ** 5 + 2):
  cnt = 0
  for i in range(N):
    if X - 1 <= A[i] <= X + 1:
      cnt += 1
  ans = max(ans, cnt)
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(c) for c in input().split()]
#ループしてX候補を求める
ma = 0
tmp = 0
for i in range(N):
    tmp = a.count(a[i]-1)+a.count(a[i])+a.count(a[i]+1)
    if ma < tmp:
        ma = tmp
print(ma)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

lower_a = list(map(lambda x: x - 1, a))
upper_a = list(map(lambda x: x + 1, a))
set_a = set(a + lower_a + upper_a)

temp_max = 0
for x in set_a:
    temp_max = max(temp_max, a.count(x) + lower_a.count(x) + upper_a.count(x))
print(temp_max)

Submission status: Time Limit Exceeded

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

lower_a = list(map(lambda x: x - 1, a))
upper_a = list(map(lambda x: x + 1, a))

temp_max = 0
for k in range(min(a) -1, max(a) + 2):
    cnt = 0
    for lower, upper in zip(lower_a, upper_a):
        if lower <= k <= upper:
            cnt += 1
    temp_max = max(temp_max, cnt)
print(temp_max)

Submission status: Time Limit Exceeded

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

cnt = 0
tmp = []
for i in range(N):
    for j in range(N):
        if P[i] - 1 <= P[j] <= P[i] + 1:
            cnt += 1
    tmp.append(cnt)
    cnt = 0

print(max(tmp))

Submission status: Time Limit Exceeded

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

a_max = max(A)
a_min = min(A)
dummy = -float("inf")

for x in range(a_min, a_max+1):
    cnt = 0
    A_replace = [l for l in A if l -1 <= x and l + 1 >= x]
    if dummy < len(A_replace):
        dummy = len(A_replace)
        ans = dummy
print(ans)

Submission status: Time Limit Exceeded

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

a_max = max(A)
a_min = min(A)
dummy = -float("inf")

for x in range(a_min, a_max+1):
    cnt = 0
    for i in range(len(A)):
        if A[i] -1 <= x and A[i] + 1 >= x:
            cnt += 1
            if dummy < cnt:
                dummy = cnt
print(dummy)

Submission status: Time Limit Exceeded

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

a_max = max(A)
a_min = min(A)
dummy = -float("inf")

for x in range(a_min-1, a_max+1+1):
    cnt = 0
    for i in range(len(A)):
        if A[i] -1 <= x and A[i] + 1 >= x:
            cnt += 1
            if dummy < cnt:
                dummy = cnt
print(dummy)

Submission status: Time Limit Exceeded

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

if min(a) == max(a):
    print(len(a))
    exit()

list = []
for i in range(N):
    list += [a[i]-1,a[i],a[i]+1]
num = []
for i in range(min(a),max(a)):
    num.append(list.count(i))
print(max(num))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
a_list = sorted(a_list)
a_set = list(set(a_list))
max_cnt = 0

for i in range(0, len(a_set)):
    cnt = a_list.count(a_set[i]) + a_list.count(a_set[i] - 1) + a_list.count(a_set[i] + 1)
    
    if cnt > max_cnt :
        max_cnt = cnt

print(max_cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
a_set = list(set(a_list))
max_cnt = 0

for i in range(0, len(a_set)):
    cnt = a_list.count(a_set[i]) + a_list.count(a_set[i] - 1) + a_list.count(a_set[i] + 1)
    
    if cnt > max_cnt :
        max_cnt = cnt

print(max_cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
aa =set(a)
ans = 0
num = 0
for k in aa:
  num = a.count(k)+a.count(k-1)+a.count(k+1)
  ans = max(ans,num)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
aa = collections.Counter(a)
ans = 0
num = 0
for k in aa.keys():
  num = a.count(k)+a.count(k-1)+a.count(k+1)
  ans = max(ans,num)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
aa = collections.Counter(a)
ans = 0
num = 0
for k,v in aa.items():
  num = a.count(k)+a.count(k-1)+a.count(k+1)
  ans = max(ans,num)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
a = [int(x) for x in input().split()]
a.sort()
ans = 1
for i in range(len(a)):
  cnt = 1
  b = copy.deepcopy(a)
  rm = a[i]
  b.remove(rm)
  cnt += b.count(rm-1)+b.count(rm+1)
  ans = max(ans, cnt)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    a_min = min(a_lst)
    a_max = max(a_lst)

    count_lst = []
    for num in range(a_min, a_max + 1):
        count = 0
        count += a_lst.count(num - 1)
        count += a_lst.count(num)
        count += a_lst.count(num + 1)
        count_lst.append(count)

    maximum = max(count_lst)
    print(maximum)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N, *A = map(int, open(0).read().split())

A.sort()

ans = 0
for i in range(N):
    count = 1
    p = 0
    j = i + 1
    while j < N:
        if A[j] != A[i] + p:
            if p == 2:
                break
            p += 1
            continue
        count += 1
        j += 1
    ans = max(ans, count)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, *A = map(int, open(0).read().split())

A.sort()

ans = 0
for i in range(N):
    count = 1
    for j in range(i+1, N):
        if A[j] <= A[i] + 2:
            count += 1
        else:
            break
    ans = max(ans, count)

print(ans)

Submission status: Time Limit Exceeded

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

l = [0]*n
ans = 0

for i in range(n):
    for j in range(n):
        if abs(c[i]-c[j]) <= 1:
            ans += 1
    l[i] = ans
    ans = 0
print(max(l))

Submission status: Time Limit Exceeded

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

ans = 0
numcnt = [0]*100001

for i in a:
    numcnt[i]+=1
    
for x in range(max(a)+1):
    dx = [-1,0,1]
    subans = 0
    for i in dx:
        if x+i<0 or x+i>max(a):
            continue
        subans += numcnt[x+i]
        
    ans = max(ans,subans)
    
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
numcnt = [0]*100001

for i in range(max(a)+1):
    numcnt[i]=a.count(i)
    
for x in range(max(a)+1):
    dx = [-1,0,1]
    subans = 0
    for i in dx:
        if x+i<0 or x+i>max(a):
            continue
        subans += numcnt[x+i]
        
    ans = max(ans,subans)
    
print(ans)

Submission status: Time Limit Exceeded

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

nin=min(a)
nax=max(a)
ans=0
for x in range(nin,nax+1):
    temp=[]
    for i in range(N):
        tt=abs(a[i]-x)
        if -1<=tt and tt<=1:
            temp.append(1)
    ans=max(ans,sum(temp))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
candidates=set()
for i in range(len(A)):
  candidates.add(A[i])
  candidates.add(A[i]-1)
  candidates.add(A[i]+1)

# 渡された配列内に，±1で数xに出来る数がいくつあるか判定
def neigh(array, x):
  cnt = 0
  for a in array:
    if a == x:
      cnt+=1
    elif a-1 == x:
      cnt+=1
    elif a+1 == x:
      cnt+=1
  return cnt

res=[]
for c in candidates:
  res.append(neigh(A,c))
  
print(max(res))

Submission status: Time Limit Exceeded

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

candidates=set(A)

# 配列に渡された配列内に，±1で数xに出来る数がいくつあるか判定
def neigh(array, x):
  cnt = 0
  for a in array:
    if a == x:
      cnt+=1
    elif a-1 == x:
      cnt+=1
    elif a+1 == x:
      cnt+=1
  return cnt

res=[]
for c in candidates:
  res.append(neigh(A,c))
  
print(max(res))