Problem p03611 (python)

Fixed submission:
import collections
import sys
n=int(input())
a=list(map(int,input().split()))
b=list(collections.Counter(a).items())
b.sort(key=lambda x:int(x[0]))
if len(b)==1:
  print(n)
  sys.exit()
lst=[]
num=b[0][1]
if int(b[1][0])-int(b[0][0])==1:
  num+=b[1][1]
lst.append(num)
for i in range(1,len(b)-1):
  num=b[i][1]
  if int(b[i+1][0])-int(b[i][0])==1:
    num+=b[i+1][1]
  if int(b[i][0])-int(b[i-1][0])==1:
    num+=b[i-1][1]
  lst.append(num)
num=b[len(b)-1][1]
if int(b[len(b)-1][0])-int(b[len(b)-2][0])==1:
  num+=b[len(b)-2][1]
lst.append(num)
print(max(lst))

Buggy submission (verdict: Runtime Error):
import collections
import sys
n=int(input())
a=list(map(int,input().split()))
A=collections.Counter(a)
b=list(A.items())
b.sort()
cnt=0
if len(b)==1:
  print(b[0][1])
  sys.exit()
if len(b)==2:
  if int(b[1][0])-int(b[0][0])==1:
    print(b[1][1]+b[0][1])
    sys.exit()
  else:
    print(max(b[1][1],b[0][1]))
    sys.exit()
for i in range(len(b)-2):
  if int(b[i+2][0])-int(b[i+1][0])==1 and int(b[i+1][0])-int(b[i][0])==1:
    cnt=max(cnt,b[i][1]+b[i+1][1]+b[i+2][1]) 
  elif int(b[i+1][0])-int(b[i][0])==1:
    cnt=max(cnt,b[i+1][1]+b[i][1])
  else:
    cnt=max(cnt,b[i])
    
if int(b[len(b)-1][0])-int(b[len(b)-2][0])==1 and int(b[len(b)-2][0])-int(b[len(b)-3][0])!=1:
  cnt=cnt
elif int(b[len(b)-1][0])-int(b[len(b)-2][0])==1:
  cnt=max(cnt,b[len(b)-1][1]-b[len(b)-2][1])
else:
  cnt=max(cnt,max(b[len(b)-1][1],b[len(b)-2][1]))
print(cnt)

Buggy submission (verdict: Runtime Error):
import collections
import sys
n=int(input())
a=list(map(int,input().split()))
if n==1:
  print(1)
  sys.exit()
if n==2:
  if abs(a[1]-a[0])<2:
    print(2)
    sys.exit()
  else:
    print(1)
    sys.exit()    
A=collections.Counter(a)
b=list(A.items())
b.sort()
cnt=0
for i in range(len(b)-2):
  if int(b[i+2][0])-int(b[i+1][0])==1 and int(b[i+1][0])-int(b[i][0])==1:
    cnt=max(cnt,b[i][1]+b[i+1][1]+b[i+2][1]) 
  elif int(b[i+1][0])-int(b[i][0])==1:
    cnt=max(cnt,b[i+1][1]+b[i][1])
  else:
    cnt=max(cnt,b[i])
    
if int(b[len(b)-1][0])-int(b[len(b)-2][0])==1 and int(b[len(b)-2][0])-int(b[len(b)-3][0])!=1:
  cnt=cnt
elif int(b[len(b)-1][0])-int(b[len(b)-2][0])==1:
  cnt=max(cnt,b[len(b)-1][1]-b[len(b)-2][1])
else:
  cnt=max(cnt,max(b[len(b)-1][1],b[len(b)-2][1]))
print(cnt)

Buggy submission (verdict: Runtime Error):
import collections
import sys
n=int(input())
a=list(map(int,input().split()))
if n==1:
  print(1)
  sys.exit()
if n==2:
  if abs(a[1]-a[0])<2:
    print(2)
    sys.exit()
  else:
    print(1)
    sys.exit()    
A=collections.Counter(a)
b=list(A.items())
b.sort()
cnt=0
for i in range(len(b)-2):
  if int(b[i+2][0])-int(b[i+1][0])==1 and int(b[i+1][0])-int(b[i][0])==1:
    cnt=max(cnt,b[i][1]+b[i+1][1]+b[i+2][1]) 
  elif int(b[i+1][0])-int(b[i][0])==1:
    cnt=max(cnt,b[i+1][1]+b[i][1])
  else:
    cnt=max(cnt,b[i])
if int(b[len(b)-1][0])-int(b[len(b)-2][0])==1:
  cnt=max(cnt,b[len(b)-1][1]-b[len(b)-2][1])
else:
  cnt=max(cnt,max(b[len(b)-1][1],b[len(b)-2][1]))
print(cnt)

Buggy submission (verdict: Runtime Error):
import collections
n=int(input())
a=list(map(int,input().split()))
A=collections.Counter(a)
b=list(A.values())
b.sort()
lst=[]
for i in range(len(b)-1):
  lst.append(b[i]+b[i+1])
print(max(lst))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort()
CNT=[]
cnt=0
for i in range(n-1):
  for j in range(n-i):
    if a[i+j]-a[i]<2:
      cnt+=1
    else:
      CNT.append(cnt)
      cnt-=cnt
      break
print(max(CNT))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort()
CNT=[]
cnt=0
for i in range(n-1):
  cnt=0
  for j in range(n-i):
    if a[i+j]-a[i]<2:
      cnt+=1
    else:
      CNT.append(cnt)
      break
print(max(CNT))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort()
CNT=[]
for i in range(n-1):
  cnt=0
  for j in range(n-i):
    if abs(a[i+j]-a[i])<2:
      cnt+=1
    else:
      CNT.append(cnt)
      break
print(max(CNT))