Problem:


Score : 300 points

Problem Statement

You are given an integer sequence of length N, a_1,a_2,...,a_N.

For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing.

After these operations, you select an integer X and count the number of i such that a_i=X.

Maximize this count by making optimal choices.

Constraints

1≤N≤10^5

0≤a_i<10^5 (1≤i≤N)

a_i is an integer.

Input

The input is given from Standard Input in the following format:

N
a_1 a_2 .. a_N

Output

Print the maximum possible number of i such that a_i=X.

Sample Input 1

7
3 1 4 1 5 9 2

Sample Output 1

4

For example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4, the maximum possible count.

Sample Input 2

10
0 1 2 3 4 5 6 7 8 9

Sample Output 2

3

Sample Input 3

1
99999

Sample Output 3

1



Sample input:
7
3 1 4 1 5 9 2


Sample output:
4

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n = ini()
a = sorted(inl())
ans = 1
diff = 3
count = 1
prev = -2
seen = True
for i in a:
    # print(count)
    if i == prev:
        count += 1
    elif i-1 == prev:
        count += 1
        diff -= 1
        if diff >= 0:
            pass
            # ans = max(ans, count)
        else:
            count = 1
            diff = 2
    else:
        count = 1
        diff = 2
    prev = i
    ans = max(ans, count)
# ans = max(ans, count)
# print(diff, count)
# count = count if diff else 0
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n = ini()
a = sorted(inl())
ans = 1
diff = 3
count = 1
prev = -2
seen = True
for i in a:
    # print(count)
    if i == prev:
        count += 1
    elif i-1 == prev:
        count += 1
        diff -= 1
        if diff >= 0:
            ans = max(ans, count)
        else:
            count = 1
            diff = 2
    else:
        count = 1
        diff = 2
    prev = i
ans = max(ans, count)
# print(diff, count)
# count = count if diff else 0
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))

n = ini()
a = sorted(inl())
ans = 1
diff = 3
count = 0
prev = -1
for i in a:
    if i == prev:
        count += 1
    elif i-1 == prev:
        count += 1
        diff -= 1
        if diff >= 0:
            ans = max(ans, count)
    else:
        count = 0
        diff = 3
    prev = i
print(ans)

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = ni()
A = lma()
l = max(A)
cnts = [0 for i in range(l+2)]
for a in A:
    cnts[a]+=1
    cnts[a-1] +=1
    cnts[a+1] +=1
print(max(cnts))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
now = A[0]
start_idx = 0
while now <= A[-1] + 1:
    tmp_max = 0
    flag = True
    for i in range(start_idx, N):
        if flag and now - 1 == A[i]:
            flag = False
            start_idx = i
        if now - 1 <= A[i] <= now + 1:
            tmp_max += 1
        else:
            break
    ans = max(tmp_max, ans)
    now += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
n, *a = map(int, sys.stdin.read().split())
lr=[[i - 1,i + 1] for i in a]
lr.sort(key=lambda x: x[1])
prep = lr[0][1]
res = tmp = 1
for l,r in lr[1:]:
  if l > prep:
    res = max(res, tmp)
    tmp = 1
    prep = r
  else:
    tmp += 1
res = max(res, tmp)
print(res)

Submission status: Wrong Answer

Solution code:
import sys
n, *a = map(int, sys.stdin.read().split())
lr=[[i - 1,i + 1] for i in a]
lr.sort(key=lambda x: x[0])
prep = lr[0][1]
res = tmp = 1
for l,r in lr[1:]:
  if l > prep:
    res = max(res, tmp)
    tmp = 1
    prep = r
  else:
    tmp += 1
res = max(res, tmp)
print(res)

Submission status: Wrong Answer

Solution code:
import sys
n, *a = map(int, sys.stdin.read().split())
lr=[[i - 1,i + 1] for i in a]
lr.sort(key=lambda x: x[0])
prep = lr[0][1]
res = tmp = 1
for l,r in lr[1:]:
  if l > prep:
    res = max(res, tmp)
    tmp = 1
    prep = r
  else:
    tmp += 1
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A=int(input())
n_l=list(map(int,input().split()))
n_l.sort()
n_l_s=[]
for i in range(A-1):
   n_l_s.append(n_l[i+1]-n_l[i])
ans=1
n=0
c=0
for i in range(A-1):
   n+=n_l_s[i]
   c+=1
   if n > 2:
      ans=max(ans,c)
      c=0
ans=max(ans,c)
print(ans)

Submission status: Wrong Answer

Solution code:
#!python3

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


def main():
    n = max(A)
    d = {i: 0 for i in range(n + 1)}
    for a in A:
        d[a] += 1

    ans = 0
    for i in range(1, n):
        s = d[i - 1] + d[i] + d[i + 1]
        ans = max(ans, s)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

cnt = []
tmp = a[0]
count = 1
for i in range(1, N):
    if(abs(tmp-a[i]) <= 2):
        count += 1
    else:
        cnt.append(count)
        count = 1
        tmp = a[i]
if(len(cnt) > 0):
    print(max(count, max(cnt)))
else:
    print(count)

Submission status: Wrong Answer

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

for i in range(n):
    Acount[A[i]] = Acount[A[i]] + 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = list(map(int,input().split()))
B = collections.Counter(A).most_common()

a = B[0][0]
b = a + 1
c = a - 1

L = [a,b,c]
C = [0,0,0]

for i in range(N):
  for j in range(3):
    d = abs(A[i] - L[j])
    if d <= 1:
      C[j] += 1
    
print(max(C))

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))
    C = defaultdict(int)
    for a in A:
        C[a] += 1

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def f(mc):
    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)
    else:
        ans = a.count(mc)
    return ans

from collections import Counter

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

# setA = list(set(a))

c = Counter(a)
mc = c.most_common()

ans = -1
for _mc in mc:
    if _mc[0]-1 in a and _mc[0]+1 in a:
        ans = c[_mc[0]-1] + c[_mc[0]] + c[_mc[0]+1]
    elif (_mc[0]-1 not in a) and (_mc[0]+1 in a):
        ans = c[_mc[0]] + c[_mc[0]+1] + c[_mc[0]+2]
    elif (_mc[0]-1 in a) and (_mc[0]+1 not in a):
        ans = c[_mc[0]] + c[_mc[0]-1] + c[_mc[0]-2]
    else:
        ans = c[_mc[0]]

# print(max(ans))
print(ans)

Submission status: Wrong Answer

Solution code:
def f(mc):
    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)
    else:
        ans = a.count(mc)
    return ans

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

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

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)
# else:
#     ans = a.count(mc)

ans = []
i = 1
for _c in c.most_common():
    ans.append(f(_c[0]))
    i += 1
    if i == 100:
        break

print(max(ans))

Submission status: Wrong Answer

Solution code:
def f(mc):
    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)
    else:
        ans = a.count(mc)
    return ans

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

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

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)
# else:
#     ans = a.count(mc)

ans1 = f(mc)
ans2 = f(c.most_common()[1][0])

print(max(ans1, ans2))

Submission status: Wrong Answer

Solution code:
def f(mc):
    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)
    else:
        ans = a.count(mc)
    return ans

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

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

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)
# else:
#     ans = a.count(mc)

print(f(mc))

Submission status: Wrong Answer

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)
#     exit()

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)
else:
    ans = a.count(mc)

print(ans)

Submission status: Wrong Answer

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)
    exit()

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)
else:
    ans = a.count(mc)

print(ans)

Submission status: Wrong Answer

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)
else:
    ans = a.count(mc)

print(ans)

Submission status: Wrong Answer

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

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

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)
elif mc == 10**5 - 1:
    ans = a.count(10**5 - 1) + a.count(10**5 - 2) + a.count(10**5 - 3)


# print(c.most_common()[0][1])
# print(a.count(mc-1))
# print(a.count(mc+1))

print(ans)

Submission status: Wrong Answer

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

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

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

if 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)

# print(c.most_common()[0][1])
# print(a.count(mc-1))
# print(a.count(mc+1))

print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(n-1):
    ans = max(ans, bisect.bisect_left(a[i:], a[i]+2))

print(ans+1)

Submission status: Wrong Answer

Solution code:
input()
L = list(map(int, input().split()))
a = [L.count(i) for i in range(min(L),max(L)+1)]
answer = 0
for i in range(1,max(L)-min(L)):
    b = sum(a[i-1:i+2])
    if answer<b:
        answer = b
print(answer)

Submission status: Wrong Answer

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):
			a=b
			b=c
			c=1
	else:
		c+=1
#	print("i:{} | {} {} {}".format(i,a,b,c))

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



#print(hoge)
print(maxhoge)

Submission status: Wrong Answer

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):
			a=b
			b=c
			c=1
	else:
		c+=1
	maxhoge=max(maxhoge,a+b+c)

#	print("{} {} {}".format(a,b,c))


#print(hoge)
print(maxhoge)

Submission status: Wrong Answer

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(0)
a=0
b=0
c=1
maxhoge=0
for i in range(0,n):
	maxhoge=max(maxhoge,a+b+c)
	if(hoge[i]!=hoge[i+1]):
		a=b
		b=c
		c=1
	else:
		c+=1
#	print("{} {} {}".format(a,b,c))


#print(hoge)
print(maxhoge)

Submission status: Wrong Answer

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]):
		a=b
		b=c
		c=1
	else:
		c+=1
	maxhoge=max(maxhoge,a+b+c)
#	print("{} {} {}".format(a,b,c))


#print(hoge)
print(maxhoge)

Submission status: Wrong Answer

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]):
		maxhoge=max(maxhoge,a+b+c)
		a=b
		b=c
		c=1
	else:
		c+=1
	if(i==n-1):
		maxhoge=max(maxhoge,a+b+c)
#	print("{} {} {}".format(a,b,c))


#print(hoge)
print(maxhoge)

Submission status: Wrong Answer

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]):
		maxhoge=max(maxhoge,a+b+c)
		a=b
		b=c
		c=1
	else:
		c+=1
#	print("{} {} {}".format(a,b,c))


#print(hoge)
print(maxhoge)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
num = [0 for i in range(100001)]
for i in range(N):
    num[A[i]-1] += 1
    num[A[i]] += 1
    num[A[i]+1] += 1
print(str(max(num)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 10 10:05:08 2019

@author: shinjisu
"""


# ARC 076 C
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def dmp(x):
    global debug
    if debug:
        print(x)
    return x


def probC():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    hist = {}
    for i in range(N):
        if A[i] in hist:
            hist[A[i]] += 1
        else:
            hist[A[i]] = 1
    dmp(hist)
    mxCnt = 1
    keylist = list(hist.keys())
    mxKey = max(keylist)
    dmp(mxKey)
    for i in range(mxKey-1):
        cnt = 0
        if i in keylist:
            cnt += hist[i]
        if i+1 in keylist:
            cnt += hist[i+1]
        if i+2 in keylist:
            cnt += hist[i+2]
        mxCnt = max(mxCnt, cnt)
        dmp(('max',mxCnt))
    return mxCnt


debug = False  # True False
print(probC())

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 10 10:05:08 2019

@author: shinjisu
"""


# ARC 076 C
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def dmp(x):
    global debug
    if debug:
        print(x)
    return x


def probC():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    hist = {}
    for i in range(N):
        if A[i] in hist:
            hist[A[i]] += 1
        else:
            hist[A[i]] = 1
    dmp(hist)
    mxKey = max(hist.keys())
    dmp(mxKey)
    mxCnt = 1
    for i in range(mxKey-1):
        cnt = 0
        if i in list(hist.keys()):
            cnt += hist[i]
        if i+1 in list(hist.keys()):
            cnt += hist[i+1]
        if i+2 in list(hist.keys()):
            cnt += hist[i+2]
        mxCnt = max(mxCnt, cnt)
        dmp(('max',mxCnt))
    return mxCnt


debug = False  # True False
print(probC())

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 10 10:05:08 2019

@author: shinjisu
"""


# ARC 076 C
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def dmp(x):
    global debug
    if debug:
        print(x)
    return x


def probC():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    hist = {}
    for i in range(N):
        if A[i] in hist:
            hist[A[i]] += 1
        else:
            hist[A[i]] = 1
    dmp(hist)
    mxKey = max(hist.keys())
    dmp(mxKey)
    mxCnt = 1
    for i in range(mxKey-2):
        cnt = 0
        if i in list(hist.keys()):
            cnt += hist[i]
        if i+1 in list(hist.keys()):
            cnt += hist[i+1]
        if i+2 in list(hist.keys()):
            cnt += hist[i+2]
        if cnt > mxCnt:
            mxCnt = cnt
            dmp(('max',mxCnt))
    return mxCnt


debug = False  # True False
print(probC())

Submission status: Wrong Answer

Solution code:
lis=[0]*((10**5)+1)
N=int(input().strip())
a=list(map(int, input().split()))
for i in range(N):
    lis[a[i]-1]+=1
    lis[a[i]]+=1
    lis[a[i]+1]+=1
lis.sort(reverse=True)
print(lis[0])

Submission status: Wrong Answer

Solution code:
n = int(input())

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

b ={i:0 for i in range(min(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: Wrong Answer

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

for idx, pi in enumerate(p):
    if (idx+1) == pi:
        if idx+1 < n:
            p[idx], p[idx+1] = p[idx+1], p[idx]
        else:
            p[idx], p[idx-1] = p[idx-1], p[idx]
        cnt += 1

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
num = [0 for i in range(max(a)+3)]
for i in a:
    num[i] += 1
temp = 0
ans = 0
for i in range(max(a)):
    temp = num[i] + num[i+1] + num[i+2]
    if ans < temp:
        ans = temp
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=1
i=0
while i<n-1:
    cnt,j=1,i+1
    while j<n and abs(a[i]-a[j])<=2 :
        j+=1
        cnt+=1
    i=j+1
    ans=max(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
a = input()
print(a[0]+str(len(a)-2)+a[-1])

Submission status: Wrong Answer

Solution code:
#C問題 together

import numpy as np

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

a.sort()
a2 = np.array(a)

minval = a[0]
maxval = a[-1]
l = (maxval - minval +1)

num = [0]*l
num_ans = []


num[0] = len(np.where(a2==a[0]))

for i in a:
	if num[i-minval] == 0:
		num[i-minval] = len(np.where(a2==i))

if l == 1:
	print(num[0])
	exit(0)

num_ans.append(num[0]+num[1]) 

if l == 2:
	print(num_ans[0])
	exit(0)

for i in range(1,l-1):
	num_ans.append(num[i-1]+num[i]+num[i+1])
num_ans.append(num[-2]+num[-1])

print(max(num_ans))

Submission status: Wrong Answer

Solution code:
import 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)
    max_ = max(a)
    ans = -1
    for K in range(min_,max_):
        b = a - K
        tmp = sum(count(b))
        if ans < tmp:
            ans = tmp
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

def func(nums):
    a = nums[0]
    tots = a[1]
    i = 1
    while i < len(nums):
        if nums[i][0] - a[0] < 3:
            tots += nums[i][1]
            yield tots
        else:
            a = nums[i]
            yield tots
            tots = a[1]
        i += 1

if len(l) == 1:
    print(1)
elif len(l) == 2:
    if l[1] - l[0] < 3:
        print(2)
    else:
        print(1)
else:
    counts = Counter(l)
    nums = sorted(list(counts.items()))
    
    xd = 0
    for x in func(nums):
        if x > xd:
            xd = x
    print(xd)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

def func(nums):
    a = nums[0]
    tots = a[1]
    i = 1
    while i < len(nums):
        if nums[i][0] - a[0] < 3:
            tots += nums[i][1]
        else:
            a = nums[i]
            yield tots
            tots = a[1]
        i += 1
    yield tots

if len(l) == 1:
    print(1)
elif len(l) == 2:
    if l[1] - l[0] < 3:
        print(2)
    else:
        print(1)
else:
    counts = Counter(l)
    nums = sorted(list(counts.items()))
    
    xd = 0
    for x in func(nums):
        if x > xd:
            xd = x
    print(xd)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

def func(nums):
    a = nums[0]
    tots = a[1]
    i = 1
    while i < len(nums):
        if nums[i][0] - a[0] < 3:
            tots += nums[i][1]
        else:
            a = nums[i]
            yield tots
            tots = a[1]
        i += 1

if len(l) == 1:
    print(1)
elif len(l) == 2:
    if l[1] - l[0] < 3:
        print(2)
    else:
        print(1)
else:
    counts = Counter(l)
    nums = sorted(list(counts.items()))
    
    xd = 0
    for x in func(nums):
        if x > xd:
            xd = x
    print(xd)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

def func(nums):
    a = nums[0]
    tots = a[1]
    i = 1
    while i < len(nums):
        if nums[i][0] - a[0] < 3:
            tots += nums[i][1]
        else:
            a = nums[i]
            yield tots
            tots = a[1]
        i += 1

if len(l) == 1:
    print(1)
elif len(l) == 2:
    if l[1] - l[0] < 3:
        print(2)
    else:
        print(1)
else:
    counts = Counter(l)
    nums = list(counts.items())

    xd = 0
    for x in func(nums):
        if x > xd:
            xd = x
    print(xd)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

def func(nums):
    a = nums[0]
    tots = a[1]
    i = 1
    while i < len(nums):
        if nums[i][0] - a[0] < 3:
            tots += nums[i][1]
        else:
            a = nums[i]
            yield tots
            tots = a[1]
        i += 1

if len(l) == 1:
    print(1)
else:
    counts = Counter(l)
    nums = list(counts.items())

    xd = 0
    for x in func(nums):
        if x > xd:
            xd = x
    print(xd)

Submission status: Wrong Answer

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

    a.sort()

    min = a[0]
    max = a[-1]

    i = min
    j = 0
    k = 0
    num = 0
    max_num = 0

    while i <= max + 1:
        if i - 1 <= a[j] and a[j] <= i + 1:
            num += 1
        else:
            if max_num < num:
                max_num = num
            num = 0
            # j = k
            i += 1
            j = 0
            continue
        j += 1
        if j == len(a):
            if max_num < num:
                max_num = num
            num = 0
            # j = k
            i += 1
            j = 0
            continue
            
    print(max_num)

Submission status: Wrong Answer

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

    a.sort()

    min = a[0]
    max = a[-1]

    i = min
    j = 0
    k = 0
    num = 0
    max_num = 0

    while i <= max + 1:
        if i - 1 <= a[j] and a[j] <= i + 1:
            num += 1
            if a[j-1] == i - 1 and a[j] == i:
                k = j
        else:
            if max_num < num:
                max_num = num
            num = 0
            j = k
            i += 1
            continue
        j += 1
        if j == len(a):
            if max_num < num:
                max_num = num
            num = 0
            j = k
            i += 1
            continue
            
    print(max_num)

Submission status: Wrong Answer

Solution code:
import sys 
def same(eptuple):
    return eptuple[0] +1 == eptuple[1]
N = int(sys.stdin.readline())
plist = map(int, sys.stdin.readline().strip().split())
eplist = list(enumerate(plist))

if same(eplist[0]):
    flag =True
else:
    flag =False
count = 0
for i in xrange(1, N):
    if same(eplist[i]):
        if flag:
            count += 1
            flag = False
        else:
            flag =True
    else:
        if flag:
            count += 1
            flag = False                                                                                                                                                                                                              
        else:
            flag = False
if flag:
    count += 1
print count

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
a=[int(i) for i in raw_input().split(' ')]
b=[ 1 if a[i]==i+1 else 0 for i in range(len(a)) ]
res=0
f=0
while f<len(b):
    if b[f]==1:
        if b[f]==b[f+1]:
            res=res+1
            f=f+2
            if f>len(b)-1:
                break
        else:
            res=res+1
            f=f+1
    else:
        f=f+1
print res

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
N=map(int,raw_input().split())
N=[0]+N
count=0
for i in range(1,n+1):
    if i==N[i]:
        if i!=n:
            N[i],N[i+1]=N[i+1],N[i]
            count+=1
print count

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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)
max(cnt.values())