Problem p03611 (python)

Fixed submission:
from collections import Counter

N = int(input())
a_s = input().split()
a_s = [int(a_s[i]) for i in range(N)]

c = Counter(a_s)
c = sorted(c.items(), key=lambda x:x[0])
a_unique, a_counts = zip(*c)

ans = 0
for i,a in enumerate(a_unique):
    val = a_counts[i]
    if (i>0):
        if (a_unique[i-1]+1==a):
            val += a_counts[i-1]
            
    if (i<len(a_unique)-1):
        if (a_unique[i+1]-1==a):
            val += a_counts[i+1]
    
    if val > ans:
        ans = val
        
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
a_s = input().split()
for i in range(N):
    a_s[i] = int(a_s[i])
a_s = np.array(a_s)

a_unique = np.unique(a_s)

ans = 0
i = 1
for a in a_unique[1:-1]:
    val = np.sum(a_s==a)
    if (a_unique[i-1]+1==a):
        val += np.sum(a_s==a_unique[i-1])
            
    if (a_unique[i+1]-1==a):
        val += np.sum(a_s==a_unique[i+1])
    
    if val > ans:
        ans = val
    
    i += 1

#i=0
val = np.sum(a_s==a_unique[0])
val += np.sum(a_s==a_unique[1])
if val > ans:
    ans = val   

#i=len(a_unique)-1
val = np.sum(a_s==a_unique[-1])
val += np.sum(a_s==a_unique[-2])
if val > ans:
    ans = val   

#     if ans >= sum(a_counts[i:]):
#         break
        
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
a_s = input().split()
for i in range(N):
    a_s[i] = int(a_s[i])
a_s = np.array(a_s)

a_unique = np.unique(a_s)

ans = 0
for i,a in enumerate(a_s):
    val = np.sum(a_s==a)
    if (i>0):
        if (a_unique[i-1]+1==a):
            val += np.sum(a_s==a_unique[i-1])
            
    if (i<len(a_unique)-1):
        if (a_unique[i+1]-1==a):
            val += np.sum(a_s==a_unique[i+1])
    
    if val > ans:
        ans = val
        
#     if ans >= sum(a_counts[i:]):
#         break
        
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
a_s = input().split()
for i in range(N):
    a_s[i] = int(a_s[i])
a_s = np.array(a_s)

a_unique = np.unique(a_s)
# a_counts = []
# for i,a in enumerate(a_unique):
#     a_counts.append(np.sum(a_s==a))
# a_counts = np.array(a_counts)

ans = 0
for i in range(len(a_unique)):
    val = np.sum(a_s==a_unique[i] #a_counts[i]
    if (i>0):
        if (a_unique[i-1]+1==a_unique[i]):
            val += np.sum(a_s==a_unique[i-1]) #a_counts[i-1]
            
    if (i<len(a_unique)-1):
        if (a_unique[i+1]-1==a_unique[i]):
            val += np.sum(a_s==a_unique[i+1]) #a_counts[i+1]
    
    if val > ans:
        ans = val
        
#     if ans >= sum(a_counts[i:]):
#         break
        
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
a_s = input().split()
for i in range(N):
    a_s[i] = int(a_s[i])
a_s = np.array(a_s)

a_unique = np.unique(a_s)
# a_counts = []
# for i,a in enumerate(a_unique):
#     a_counts.append(np.sum(a_s==a))
# a_counts = np.array(a_counts)

ans = 0
for i in range(len(a_unique)):
    val = a_counts[i]
    if (i>0):
        if (a_unique[i-1]+1==a_unique[i]):
            val += np.sum(a_s==a_unique[i-1]) #a_counts[i-1]
            
    if (i<len(a_unique)-1):
        if (a_unique[i+1]-1==a_unique[i]):
            val += np.sum(a_s==a_unique[i+1]) #a_counts[i+1]
    
    if val > ans:
        ans = val
        
#     if ans >= sum(a_counts[i:]):
#         break
        
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
a_s = input().split()
for i in range(N):
    a_s[i] = int(a_s[i])
a_s = np.array(a_s)

a_unique = np.unique(a_s)
a_counts = []
for i,a in enumerate(a_unique):
    a_counts.append(np.sum(a_s==a))
a_counts = np.array(a_counts)

ans = 0
for i in range(len(a_unique)):
    val = a_counts[i]
    if (i>0)&(a_unique[i-1]+1==a_unique[i]):
        val += a_counts[i-1]
            
    if (i<len(a_unique)-1)&(a_unique[i+1]-1==a_unique[i]):
        val += a_counts[i+1]
    
    if val > ans:
        ans = val
        
    if ans >= sum(a_counts[i:]):
        break
        
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
a_s = input().split()
for i in range(N):
    a_s[i] = int(a_s[i])
a_s = np.array(a_s)

a_unique, a_counts = np.unique(a_s, return_counts=True)

ans = 0
for i in range(len(a_unique)):
    val = a_counts[i]
    if i>0:
        if a_unique[i-1]+1==a_unique[i]:
            val += a_counts[i-1]
            
    if i<len(a_unique)-1:
        if a_unique[i+1]-1==a_unique[i]:
            val += a_counts[i+1]
            
    if val > ans:
        ans = val
        
print(ans)