Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, *A = map(int, open(0).read().split())
B = np.cumsum(A)
j = 1
a = A[0]
b = A[1]
c = A[2]
d = B[-1]-B[2]
j = 0
h = 2
while h<N:
  if abs(d-c)>abs(d-c-2*A[h+1]):
    h += 1
    c += A[h]
    d -= A[h]
    continue
  break
x = max(a,b,c,d)
y = min(a,b,c,d)
ans = x-y
for i in range(2,N-2):
  b += A[i]
  c -= A[i]
  while j<i:
    if abs(b-a)>abs(b-a-2*A[j+1]):
      j += 1
      a += A[j]
      b -= A[j]
      continue
    break
  while h<N:
    if abs(d-c)>abs(d-c-2*A[h+1]):
      h += 1
      c += A[h]
      d -= A[h]
      continue
    break
  x = max(a,b,c,d)
  y = min(a,b,c,d)
  ans = min(ans,x-y)
print(ans)

Fixed submission:
N, *A = map(int, open(0).read().split())
B = [A[0]]
for i in range(1,N):
  B += [B[-1]+A[i]]
j = 1
a = A[0]
b = A[1]
c = A[2]
d = B[-1]-B[2]
j = 0
h = 2
while h<N:
  if abs(d-c)>abs(d-c-2*A[h+1]):
    h += 1
    c += A[h]
    d -= A[h]
    continue
  break
x = max(a,b,c,d)
y = min(a,b,c,d)
ans = x-y
for i in range(2,N-2):
  b += A[i]
  c -= A[i]
  while j<i:
    if abs(b-a)>abs(b-a-2*A[j+1]):
      j += 1
      a += A[j]
      b -= A[j]
      continue
    break
  while h<N:
    if abs(d-c)>abs(d-c-2*A[h+1]):
      h += 1
      c += A[h]
      d -= A[h]
      continue
    break
  x = max(a,b,c,d)
  y = min(a,b,c,d)
  ans = min(ans,x-y)
print(ans)

Buggy python submission (verdict: Runtime Error):
N, *A = map(int, open(0).read().split())
B = np.cumsum(A)
j = 1
a = A[0]
b = A[1]
c = A[2]
d = B[-1]-B[2]
j = 0
h = 2
while h<N:
  if abs(d-c)>abs(d-c-2*A[h+1]):
    h += 1
    c += A[h]
    d -= A[h]
    continue
  break
x = max(a,b,c,d)
y = min(a,b,c,d)
ans = x-y
for i in range(2,N-2):
  b += A[i]
  c -= A[i]
  while j<i:
    if abs(b-a)>abs(b-a-2*A[j+1]):
      j += 1
      a += A[j]
      b -= A[j]
      continue
    break
  while h<N:
    if abs(d-c)>abs(d-c-2*A[h+1]):
      h += 1
      c += A[h]
      d -= A[h]
      continue
    break
  x = max(a,b,c,d)
  y = min(a,b,c,d)
  ans = min(ans,x-y)
print(ans)

Fixed submission:
N, *A = map(int, open(0).read().split())
B = [A[0]]
for i in range(1,N):
  B += [B[-1]+A[i]]
j = 1
a = A[0]
b = A[1]
c = A[2]
d = B[-1]-B[2]
j = 0
h = 2
while h<N:
  if abs(d-c)>abs(d-c-2*A[h+1]):
    h += 1
    c += A[h]
    d -= A[h]
    continue
  break
x = max(a,b,c,d)
y = min(a,b,c,d)
ans = x-y
for i in range(2,N-2):
  b += A[i]
  c -= A[i]
  while j<i:
    if abs(b-a)>abs(b-a-2*A[j+1]):
      j += 1
      a += A[j]
      b -= A[j]
      continue
    break
  while h<N:
    if abs(d-c)>abs(d-c-2*A[h+1]):
      h += 1
      c += A[h]
      d -= A[h]
      continue
    break
  x = max(a,b,c,d)
  y = min(a,b,c,d)
  ans = min(ans,x-y)
print(ans)
Buggy python submission (verdict: Runtime Error):
N,*A = map(int, open(0).read().split())
a = A[0]
b = A[1]
c = A[2]
d = sum(A[3:])
x = 0
m = c
n = d
df2 = max(m,n)-min(m,n)
for i in range(3,N-1):
  m += A[i]
  n -= A[i]
  if df2>max(m,n)-min(m,n):
    df2 = max(m,n)-min(m,n)
    c,d = m,n
    y = i
ans = max(a,b,c,d)-min(a,b,c,d)
for i in range(2,N-2):
  b += A[i]
  c -= A[i]
  df1 = max(a,b)-min(a,b)
  df2 = max(c,d)-min(c,d)
  while True:
    na = a+A[x+1]
    nb = b-A[x+1]
    if df1<max(na,nb)-min(na,nb):
      break
    df1 = max(na,nb)-min(na,nb)
    a,b = na,nb
    x += 1
  while True:
    nc = c+A[y+1]
    nd = d-A[y+1]
    if df2<max(nc,nd)-min(nc,nd):
      break
    df2 = max(nc,nd)-min(nc,nd)
    c,d = nc,nd
    y += 1
  ans = min(ans,max(a,b,c,d)-min(a,b,c,d))
print(ans)

Fixed submission:
N,*A = map(int, open(0).read().split())
a = A[0]
b = A[1]
c = A[2]
d = sum(A[3:])
x = 0
m = c
n = d
df2 = max(m,n)-min(m,n)
y = 2
for i in range(3,N-1):
  m += A[i]
  n -= A[i]
  if df2>max(m,n)-min(m,n):
    df2 = max(m,n)-min(m,n)
    c,d = m,n
    y = i
ans = max(a,b,c,d)-min(a,b,c,d)
for i in range(2,N-2):
  b += A[i]
  c -= A[i]
  df1 = max(a,b)-min(a,b)
  df2 = max(c,d)-min(c,d)
  while True:
    na = a+A[x+1]
    nb = b-A[x+1]
    if df1<max(na,nb)-min(na,nb):
      break
    df1 = max(na,nb)-min(na,nb)
    a,b = na,nb
    x += 1
  while True:
    nc = c+A[y+1]
    nd = d-A[y+1]
    if df2<max(nc,nd)-min(nc,nd):
      break
    df2 = max(nc,nd)-min(nc,nd)
    c,d = nc,nd
    y += 1
  ans = min(ans,max(a,b,c,d)-min(a,b,c,d))
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M, *L = map(int, open('0').read().split())
L = [np.array(m) for m in zip(*[iter(L)]*3)]
ans = 0
for i in range(8):
  X = []
  c = []
  for j in range(3):
    if i%2==1:
      c.append(-1)
    else:
      c.append(1)
    i >>= 1
  c = np.array(c)
  X = list(map(lambda x:sum(x*c), L))
  X.sort(reverse=True)
  ans = max(ans, sum(X[:M]))
print(ans)

Fixed submission:
from collections import defaultdict
from heapq import heappush, heappop
N, M = map(int, input().split())
dic = defaultdict(list)
for i in range(N):
  x, y, z = map(int, input().split())
  ls = (x,y,z)
  for j in range(8):
    m = 0
    n = j
    for h in range(3):
      a = ls[h]
      if n%2==1:
        a = -a
      m += a
      n >>= 1
    heappush(dic[j], -m)
#print(dic)
ans = 0
for i in range(8):
  m = 0
  for j in range(M):
    m -= heappop(dic[i])
  if m>ans:
    ans = m
print(ans)
Buggy python submission (verdict: Runtime Error):
N, *A = map(int, open('0').read().split())
l = 0
r = 0
s = A[l]
x = A[l]
ans = 0
flag = True
for l in range(N):
  while s==x and flag:
    r += 1
    if r==N:
      flag = False
      break
    s += A[r]
    x ^= A[r]
  ans += r-l
  s -= A[l]
  x ^= A[l]
print(ans)

Fixed submission:
N = int(input())
INF = 1<<22
a = [int(c) for c in input().split()]+[INF]
l = 0
r = 1
s = a[l]
x = a[l]
ans = 0
for l in range(N):
  if l==r:
    r += 1
  while r<=N:
    if s!=x:
      break
#    print(a[r])
    s += a[r]
    x ^= a[r]
    r += 1
  s -= a[l]
  x ^= a[l]
  ans += r-l-1
#  print(l,r)
print(ans)
Buggy python submission (verdict: Runtime Error):
class UnionFind:
  def __init__(self, n):
    self.par = [i for i in range(n)]
    self.rank = [0]*n
  def find(self, x):
    if self.par[x]==x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
  def unit(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x==y:
      return
    elif self.rank[x]<self.rank[y]:
      self.par[x] = y
      return
    elif self.rank[y]<self.rank[x]:
      self.par[y] = x
    else:
      self.par[y] = x
      self.rank[x] += 1
      
  def same(self, x, y):
    return self.find(x)==self.find(y)
  

N, M, *L = map(int, open('0').read().split())
p = L[:N]
ls = L[N:]
u = UnionFind(N+1)
for x,y in zip(*[iter(ls)]*2):
  u.unit(x,y)
ans = sum(1 if u.same(p,i+1) else 0 for i,p in enumerate(p))
print(ans)

Fixed submission:
from collections import defaultdict
class UnionFind:
  
  def __init__(self, n):
    self.par = [i for i in range(n)]
    self.rank = [0]*n
  
  def find(self, x):
    if self.par[x]==x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
  
  def unite(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x==y:
      return
    if self.rank[x]<self.rank[y]:
      self.par[x] = y
    else:
      self.par[y] = x
      if self.rank[x]==self.rank[y]:
        self.rank[x] += 1
  
  def same(self, x, y):
    return self.find(x)==self.find(y)
  
N, M = map(int, input().split())
h = [int(i)-1 for i in input().split()]
dic1 = defaultdict(list)
dic2 = defaultdict(list)
u = UnionFind(N)
for i in range(M):
  a, b = map(int, input().split())
  u.unite(a-1,b-1)

for c in range(N):
  p = u.find(c)
  dic1[p] += [c]
  dic2[p] += [h[c]]
ans = 0
for p in dic1.keys():
  dic1[p].sort()
  dic2[p].sort()
  i = 0
  j = 0
  while i<len(dic1[p]) and j<len(dic2[p]):
    if dic1[p][i]==dic2[p][j]:
      i += 1
      j += 1
      ans += 1
    elif dic1[p][i]<dic2[p][j]:
      i += 1
    else:
      j += 1
    
print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
from collections import Counter
N,*A = map(int, open('0').read().split())
B = accumulate(A)
c = Counter(B)
ans = c[0]+sum(v*(v-1)//2 for v in c.values())
print(ans)

Fixed submission:
from itertools import accumulate
from collections import Counter
N,*A = map(int, open(0).read().split())
B = accumulate(A)
c = Counter(B)
ans = c[0]+sum(v*(v-1)//2 for v in c.values())
print(ans)
Buggy python submission (verdict: Runtime Error):
N, *S = open('0').read().split()
N = int(N)
ans = 0
for p in range(N):
  flag = False
  for i in range(N):
    for j in range(N):
     x = i
     y = (j-p)%N
     a,b = y, (x+p)%N
     if S[i][j] != S[a][b]:
       flag = True
       break
    if flag:
      break
  else:
    ans+= N
print(ans)

Fixed submission:
N, *S = open(0).read().split()
N = int(N)
ans = 0
for p in range(N):
  flag = False
  for i in range(N):
    for j in range(N):
     x = i
     y = (j-p)%N
     a,b = y, (x+p)%N
     if S[i][j] != S[a][b]:
       flag = True
       break
    if flag:
      break
  else:
    ans+= N
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, *S = open(0).read().split()
N = int(N)
ans = 0
for p in range(N):
  flag = False
  for i in range(N):
    for j in range(N):
     x = i
     y = (j-p)%N
     a,b = y, (x+p)%N
     if S[i][j] != S[a][b]:
       flag = True
       break
    if flag:
      break
  else:
    ans+= N
print(ans)

Fixed submission:
N, *S = open(0).read().split()
N = int(N)
ans = 0
for p in range(N):
  flag = False
  for i in range(N):
    for j in range(N):
     x = i
     y = (j-p)%N
     a,b = y, (x+p)%N
     if S[i][j] != S[a][b]:
       flag = True
       break
    if flag:
      break
  else:
    ans+= N
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
a = set([int(c) for c in input().split()])
a = sorted(list(a))
X = a[-1]//2
i = bisect_left(a, X)
j = i-1 if i>0 else 0
h = i+1 if i<N-1 else N-1
I = a[i]
J = a[j]
H = a[h]
ci = cmb(a[-1],I)
cj = cmb(a[-1],J)
ch = cmb(a[-1],H)
if max(ci,cj,ch)==ci and i!= N-1:
  print(a[-1],a[i])
elif max(ci,cj,ch)==ch and h!=N-1:
  print(a[-1],a[h])
else:
  print(a[-1],a[j])

Fixed submission:
N = int(input())
a = set([int(c) for c in input().split()])
a = sorted(list(a))
X = a[-1]//2+1 if a[-1]%2==1 else a[-1]//2
m = 10**9
x = 0
for i in range(N-1):
  if abs(a[i]-X)<m:
    m = abs(a[i]-X)
    x = i
print(a[-1],a[x])

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
a = set([int(c) for c in input().split()])
a = sorted(list(a))
X = a[-1]//2
i = bisect_left(a, X)
j = i-1 if i>0 else 0
h = i+1 if i<N-1 else N-1
I = a[i]
J = a[j]
H = a[h]
ci = cmb(a[-1],I)
cj = cmb(a[-1],J)
ch = cmb(a[-1],H)
if max(ci,cj,ch)==ci and i!= N-1:
  print(a[-1],a[i])
elif max(ci,cj,ch)==ch and h!=N-1:
  print(a[-1],a[h])
else:
  print(a[-1],a[j])

Fixed submission:
N = int(input())
a = set([int(c) for c in input().split()])
a = sorted(list(a))
X = a[-1]//2+1 if a[-1]%2==1 else a[-1]//2
m = 10**9
x = 0
for i in range(N-1):
  if abs(a[i]-X)<m:
    m = abs(a[i]-X)
    x = i
print(a[-1],a[x])
Buggy python submission (verdict: Runtime Error):
N = int(input())

P2 = list(range(2,30001,2))
P3 = list(range(3,30001,6))
for i in range(1,N+1):
  if (N-i*3)%2==0 and 3*i<=15000 and 0<(N-3*i)<=5000:
    x = 3*i
    y = (N-i*3)
    break
if N==5 or N>6:
  ans = P2[:x]+P3[:y]
elif N==3:
  ans = [2,5,63]
elif N==4:
  ans = [2,5,20,63]
elif N==6:
  ans = [2,3,4,185,7,9]
print(*ans)

Fixed submission:
N = int(input())

P2 = list(range(2,30001,2))
P3 = list(range(3,30001,6))
for i in range(1,5002):
  if (N-i*3)%2==0 and 0<(N-3*i)<=5000:
    x = 3*i
    y = (N-i*3)
    break
if N==5 or N>6:
  ans = P2[:x]+P3[:y]
elif N==3:
  ans = [2,5,63]
elif N==4:
  ans = [2,5,20,63]
elif N==6:
  ans = [2,3,4,185,7,9]
if N==19999:
  ans = P2[:14997]+P3[:5000]+[19,425]
print(*ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())

P2 = list(range(2,30001,2))
P3 = list(range(3,30001,6))
for i in range(1,N+1):
  if (N-i*3)%2==0 and 3*i<=15000 and (N-3*i)<=5000:
    x = 3*i
    y = (N-i*3)
    break
if N==5 or N>6:
  ans = P2[:x]+P3[:y]
elif N==3:
  ans = [2,5,63]
elif N==4:
  ans = [2,5,20,63]
elif N==6:
  ans = [2,3,4,185,7,9]
print(*ans)

Fixed submission:
N = int(input())

P2 = list(range(2,30001,2))
P3 = list(range(3,30001,6))
for i in range(1,5002):
  if (N-i*3)%2==0 and 0<(N-3*i)<=5000:
    x = 3*i
    y = (N-i*3)
    break
if N==5 or N>6:
  ans = P2[:x]+P3[:y]
elif N==3:
  ans = [2,5,63]
elif N==4:
  ans = [2,5,20,63]
elif N==6:
  ans = [2,3,4,185,7,9]
if N==19999:
  ans = P2[:14997]+P3[:5000]+[19,425]
print(*ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())

P2 = list(range(2,30001,2))
P3 = list(range(3,30001,6))
for i in range(1,N+1):
  if (N-i*3)%2==0 and 3*i<=15000 and (N-3*i)<=5000:
    x = 3*i
    y = (N-i*3)
    break
if N==5 or N>6:
  ans = P2[:x]+P3[:y]
elif N==3:
  ans = [2,5,63]
elif N==4:
  ans = [2,5,20,63]
elif N==6:
  ans = [2,3,4,65,7,9]
print(*ans)

Fixed submission:
N = int(input())

P2 = list(range(2,30001,2))
P3 = list(range(3,30001,6))
for i in range(1,5002):
  if (N-i*3)%2==0 and 0<(N-3*i)<=5000:
    x = 3*i
    y = (N-i*3)
    break
if N==5 or N>6:
  ans = P2[:x]+P3[:y]
elif N==3:
  ans = [2,5,63]
elif N==4:
  ans = [2,5,20,63]
elif N==6:
  ans = [2,3,4,185,7,9]
if N==19999:
  ans = P2[:14997]+P3[:5000]+[19,425]
print(*ans)
Buggy python submission (verdict: Runtime Error):
N, H = map(int, input().split())
ls = []
for i in range(N):
  a, b = map(int, input().split())
  ls += [(a,-b)]
ls.sort(key=lambda x:x[0])
a = ls[-1][0]
ls.sort(key=lambda x:x[1])
ans = 0
for i in range(N-1):
  if ls[i][1]>=-a:
    break
  H += ls[i][1]
  ans += 1
  if H<=0:
    print(ans)
    break
else:
  n = H//a[0] if H%a[0]==0 else H//a[0]+1
  ans += n
  print(ans)

Fixed submission:
N, H = map(int, input().split())
ls = []
for i in range(N):
  a, b = map(int, input().split())
  ls += [(a,-b)]
ls.sort(key=lambda x:x[0])
a = ls[-1][0]
ls.sort(key=lambda x:x[1])
ans = 0
for i in range(N):
  if ls[i][1]>=-a:
    break
  H += ls[i][1]
  ans += 1
  if H<=0:
    print(ans)
    break
if H>0:
  n = H//a if H%a==0 else H//a+1
  ans += n
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
U = 10**5+10
T = np.zeros(U, np.bool)
T[1] = 1
T[2] = 1
T[3::2] = 1
for i in range(3,U,2):
  if i*i>U:
    break
  if T[i]:
    T[i*i::i+i] = 0
A = np.zeros(U, np.bool)
for i in range(U):
  if T[i]==1 and T[(i+1)//2]==1:
     A[i] = 1
A[1] = 0
A[2] = 0
A = A.cumsum()
    
Q = int(input())
for i in range(Q):
  l, r = map(int, input().split())
  print(A[r]-A[l-1])
  

Fixed submission:
import numpy as np
U = 10**5+10
T = np.zeros(U, np.bool)
T[1] = 1
T[2] = 1
T[3::2] = 1
for i in range(3,U,2):
  if i*i>U:
    break
  if T[i]:
    T[i*i::i+i] = 0
A = np.zeros(U, np.bool)
for i in range(3,U,2):
  if T[i]==1 and T[(i+1)//2]==1:
     A[i] = 1
A[1] = 0
A[2] = 0
A = A.cumsum()
    
Q = int(input())
for i in range(Q):
  l, r = map(int, input().split())
  print(A[r]-A[l-1])
Buggy python submission (verdict: Runtime Error):
N, *A = map(int, open('0').read().split())
a = max(A)
j = str(A.index(a)+1)
ans = []
if a>0:
  for i,c in enumerate(A):
    if c<0:
      ans.append(j+' '+str(i+1))
  for i in range(1,N):
    ans.append(str(i)+' '+str(i+1))
else:
  for i in range(N,1,-1):
    ans.append(str(i)+' '+str(i-1))
print(len(ans))
print('\n'.join(ans))


Fixed submission:
N = int(input())
a = [int(c) for c in input().split()]
M = max(a)
Mi = a.index(M)
m = min(a)
mi = a.index(m)
ans = []
if 0<=m:
  for i in range(N-1):
    ans += [(i+1, i+2)]
elif M<=0:
  for i in range(N-1, 0, -1):
    ans += [(i+1, i)]
else:
  if abs(m)<abs(M):
    for i in range(N):
      if a[i]<0:
        ans += [(Mi+1, i+1)]
    for i in range(N-1):
      ans += [(i+1, i+2)]
  else:
    for i in range(N):
      if a[i]>0:
        ans += [(mi+1, i+1)]
    for i in range(N-1, 0, -1):
      ans += [(i+1, i)]

print(len(ans))
for c in ans:
  print(*c)
Buggy python submission (verdict: Runtime Error):
N, *D = map(int, open('0').read().split())
D.append(0)
used = [0]*(N+1)
cnt = N
while True:
  ls = []
  for i in range(N+1):
    for j in range(N+1):
      if i==j:
        continue
      a,b = min(D[i],D[j]),max(D[i],D[j])
      d = b-a
      ls.append((min(d,24-d),i,j))
  ls.sort(key=lambda x:x[0])
  d,a,b = ls[0]
  if used[a]==0 and used[b]==0:
    used[a] = 1
    used[b] = 1
    da = (24-D[a])%24
    ma = 100
    for i in range(N+1):
      if i==a:
        continue
      x = abs(da-D[i])
      ma = min(ma,x,24-x)
    db = (24-D[b])%24
    mb = 100
    for i in range(N+1):
      if i==b:
        continue
      x = abs(db-D[i])
      mb = min(mb,x,24-x)
    if ma<mb:
      if d>=mb:
        print(d)
        break
      D[b] = db
    else:
      if d>=ma:
        print(d)
        break
      D[a] = da
  elif used[a]==0:
    used[a] = 1
    da = (24-D[a])%24
    ma = 100
    for i in range(N+1):
      if i==a:
        continue
      x = abs(da-D[i])
      ma = min(ma,x,24-x)
    if d>=ma:
      print(d)
      break
    else:
      D[a] = da
  elif used[b]==0:
    used[b] = 1
    db = (24-D[b])%24
    mb = 100
    for i in range(N+1):
      if i==b:
        continue
      x = abs(db-D[i])
      mb = min(mb,x,24-x)
    if d>=mb:
      print(d)
      break
    else:
      D[b] = mb
  else:
    print(d)
    break

Fixed submission:
N, *D = map(int, open(0).read().split())
D.append(0)
used = [0]*(N+1)
cnt = N
while True:
  ls = []
  for i in range(N+1):
    for j in range(N+1):
      if i==j:
        continue
      a,b = min(D[i],D[j]),max(D[i],D[j])
      d = b-a
      ls.append((min(d,24-d),i,j))
  ls.sort(key=lambda x:x[0])
  d,a,b = ls[0]
  if used[a]==0 and used[b]==0:
    da = (24-D[a])%24
    ma = 100
    for i in range(N+1):
      if i==a:
        continue
      x = abs(da-D[i])
      ma = min(ma,x,24-x)
    db = (24-D[b])%24
    mb = 100
    for i in range(N+1):
      if i==b:
        continue
      x = abs(db-D[i])
      mb = min(mb,x,24-x)
    if ma<mb:
      if d>=mb:
        print(d)
        break
      D[b] = db
      used[b] = 1
    else:
      if d>=ma:
        print(d)
        break
      D[a] = da
      used[a] = 1
  elif used[a]==0:
    used[a] = 1
    da = (24-D[a])%24
    ma = 100
    for i in range(N+1):
      if i==a:
        continue
      x = abs(da-D[i])
      ma = min(ma,x,24-x)
    if d>=ma:
      print(d)
      break
    D[a] = da
  elif used[b]==0:
    used[b] = 1
    db = (24-D[b])%24
    mb = 100
    for i in range(N+1):
      if i==b:
        continue
      x = abs(db-D[i])
      mb = min(mb,x,24-x)
    if d>=mb:
      print(d)
      break
    D[b] = mb
  else:
    print(d)
    break
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, *L = map(int, open('0').read().split())
A = np.array(L[:N])
B = np.array(L[N:2*N])
C = np.array(L[2*N:])
A.sort()
B.sort()
C.sort()
binf = np.zeros(N)
j = 0
binf = np.searchsorted(A,B)
bs = np.cumsum(binf)
bs = np.concatenate([[0],bs])
cinf = np.searchsorted(B,C)
ans = np.sum(bs[cinf])
print(ans)

Fixed submission:
import numpy as np
N, *L = map(int, open(0).read().split())
A = np.array(L[:N])
B = np.array(L[N:2*N])
C = np.array(L[2*N:])
A.sort()
B.sort()
C.sort()
binf = np.zeros(N)
j = 0
binf = np.searchsorted(A,B)
bs = np.cumsum(binf)
bs = np.concatenate([[0],bs])
cinf = np.searchsorted(B,C)
ans = np.sum(bs[cinf])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
N, K, *L = map(int, open(0).read().split())
L = [(x,y) for x,y in zip(*[iter(L)]*2)]
ans = float('inf')
for m in combinations(L,2):
  for n in combinations(L,2):
    mx = min(m,key=lambda x:x[0])[0]
    Mx = max(m,key=lambda x:x[0])[0]
    my = min(n,key=lambda x:x[1])[1]
    My = max(n,key=lambda x:x[1])[1]
    cnt = 0
    for x,y in L:
      if mx<=x<=Mx and my<=y<=My:
        cnt += 1
    if cnt>=K:
      ans = min(ans, (Mx-mx)*(My-my))
print(ans)

Fixed submission:
N, K = map(int, input().split())
ls = []
for i in range(N):
  x, y = map(int, input().split())
  ls += [(x,y)]
m = -1
for i in range(N):
  for j in range(i+1,N):
    for p in range(N):
      for q in range(p+1,N):
        
        x1, y1 = ls[i]
        x2, y2 = ls[j]
        x3, y3 = ls[p]
        x4, y4 = ls[q]
        cnt = 0
        flag = False
        X1 = min(x1, x2)
        X2 = max(x1, x2)
        Y1 = min(y3, y4)
        Y2 = max(y3, y4)
        for a in range(N):
          x, y = ls[a]
          """
          print('"""""""')
          print(cnt)
          print(X1,X2,x)
          print(Y1,Y2,y)
          """
          if X1<=x<=X2 and Y1<=y<=Y2:
            cnt += 1
          if cnt>=K:
            n = (X2-X1)*(Y2-Y1)
            if m==-1 or n<m:
              m = n
            break
print(m)
Buggy python submission (verdict: Runtime Error):
N, M, *L = map(int, open(0).read().split())
dic = [[] for i in range(N+1)]
for a,b in zip(*[iter(L)]*2):
  dic[a].append(b)
  dic[b].append(a)
color = [0]*(N+1)
def dfs(v,c):
  color[v] = c
  for u in dic[v]:
    if color[u]==c:
      return False
    if color[u]==0 and not dfs(u,-c):
      return False
  return True
for i in range(1,N+1):
  if color[i]==0:
    if not dfs(i,1):
      print(N*(N-1)//2-M)
      break
else:
  w = sum(c==1 for c in color)
  b = N-w
  print(w*b-M)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
N, M, *L = map(int, open(0).read().split())
dic = [[] for i in range(N+1)]
for a,b in zip(*[iter(L)]*2):
  dic[a].append(b)
  dic[b].append(a)
color = [0]*(N+1)
def dfs(v,c):
  color[v] = c
  for u in dic[v]:
    if color[u]==c:
      return False
    if color[u]==0 and not dfs(u,-c):
      return False
  return True
for i in range(1,N+1):
  if color[i]==0:
    if not dfs(i,1):
      print(N*(N-1)//2-M)
      break
else:
  w = sum(c==1 for c in color)
  b = N-w
  print(w*b-M)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
for i in range(1,3501):
  for j in range(1,3501):
    over = N*i*j
    under = 4*i*j-i*N-j*N
    if under>0 and over%under==0:
      w = over//under
      h = i
      n = j
      break
print(h,n,w)

Fixed submission:
N = int(input())
for i in range(1,3501):
  for j in range(1,3501):
    over = N*i*j
    under = 4*i*j-i*N-j*N
    if under>0 and over%under==0:
      w = over//under
      h = i
      n = j
      break
print(h,n,w)