Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03660 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10**9)

def dps(road,dist,node,d):
    for x in road[node]:
        if dist[x]<0:
            dist[x]=d
            dps(road,dist,x,d+1)
    
N=int(input())
road=[[] for _ in range(N)]
f_d=[-1 for _ in range(N)]
s_d=[-1 for _ in range(N)]
f_d[0]=0
s_d[-1]=0

for i in range(N-1):
    a,b=list(map(int,input().split()))
    road[a-1].append(b-1)
    road[b-1].append(a-1)

dps(road,f_d,0,1)
dps(road,s_d,N-1,1)

white=0
black=0

for i in range(N):
    if f_d[i]<=s_d[i]:
        black+=1
    else:
        white+=1

if black>white:
    print('Fennec')
else:
    print('Snuke')

Buggy submission (verdict: Runtime Error):
def dps(road,dist,node,d):
    for x in road[node]:
        if dist[x]<0:
            dist[x]=d
            dps(road,dist,x,d+1)
    
N=int(input())
road=[[] for _ in range(N)]
f_d=[-1 for _ in range(N)]
s_d=[-1 for _ in range(N)]
f_d[0]=0
s_d[-1]=0

for i in range(N-1):
    a,b=list(map(int,input().split()))
    road[a-1].append(b-1)
    road[b-1].append(a-1)

dps(road,f_d,0,1)
dps(road,s_d,N-1,1)

white=0
black=0

for i in range(N-1):
    if f_d[i]<=s_d[i]:
        white+=1
    else:
        black+=1

if white>black:
    print('Fennec')
else:
    print('Snuke')

Buggy submission (verdict: Runtime Error):
def sp(road,used,node,goal,path):
    if node == goal:
        return True
    for x in road[node]:
        if used[x]!=1:
            used[x]=1
            if sp(road,used,x,goal,path):
                used[x]=2
                path.append(x)
                return True

def dps(road,used,node):
    for x in road[node]:
        if used[x]!=2:
            used[x]=2
            return dps(road,used,x)+1
    return 0
    
N=int(input())
road=[[] for _ in range(N)]
used=[0 for _ in range(N)]

for i in range(N-1):
    a,b=list(map(int,input().split()))
    road[a-1].append(b-1)
    road[b-1].append(a-1)

path=[]
sp(road,used,0,N-1,path)

mid=len(path)//2+len(path)%2

f=[0]+path[:mid]
s=[N-1]+path[mid:]

black=mid
for x in f:
    black+=dps(road,used,x)
white=len(path)-mid
for x in s:
    white+=dps(road,used,x)

if black>white:
    print('Fennec')
else:
    print('Snuke')

Buggy submission (verdict: Runtime Error):
road=[[] for _ in range(N)]
used=[0 for _ in range(N)]

for i in range(N-1):
    a,b=list(map(int,input().split()))
    road[a-1].append(b-1)
    road[b-1].append(a-1)

start=0
for i in range(N):
    if len(road[i])==1:
        start=i
        break
used[start]=1

f=0
s=0
for i in range(N):
    if start == 0:
        f=i
    elif start ==N-1:
        s=i
    for x in road[start]:
        if used[x]!=1:
            start=x

mid=(N-1)/2
if abs(mid-f)<abs(mid-s):
    print('Fennec')
elif abs(mid-f)>abs(mid-s):
    print('Snuke')
else:
    if N%2==0:
        print('Snuke')
    else:
        print('Fennec')
Problem p03682 (python)

Fixed submission:
import heapq
import sys

sys.setrecursionlimit(10**5)

def add(i,pj,T):
    if T[i]!=i:
        add(T[i],pj,T)
    T[i]=pj
    
def parent(i,T):
    if T[i]!=i:
        T[i]= parent(T[i],T)
        return T[i]
    else:
        return i

N=int(input())
town=[]
for i in range(N):
    x,y=list(map(int,input().split()))
    town.append([i,x,y])
townX=sorted(town,key=lambda x:x[1])
townY=sorted(town,key=lambda x:x[2])
road=[]
for i in range(1,N):
    heapq.heappush(road,[townX[i][1]-townX[i-1][1],townX[i-1][0],townX[i][0]])
for i in range(1,N):
    heapq.heappush(road,[townY[i][2]-townY[i-1][2],townY[i-1][0],townY[i][0]])

vi=0
ans=0
tree=[i for i in range(N)]
rank=[0 for i in range(N)]
while vi<N-1:
    d,u,v = heapq.heappop(road)
    pu=parent(u,tree)
    pv=parent(v,tree)
    ru=rank[pu]
    rv=rank[pv]
    if pu == pv:
        continue
    elif ru<rv:
        add(u,pv,tree)
    elif ru==rv:
        add(u,pv,tree)
        rank[pu]+=1
    else:
        add(v,pu,tree)
    vi+=1
    ans+=d
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq

def add(i,pj,T):
    if T[i]['p']!=i:
        add(T[i]['p'],pj,T)
    T[i]['p']=pj
    
def parent(i,T):
    if T[i]['p']!=i:
        T[i]['p']= parent(T[i]['p'],T)
        return T[i]['p']
    else:
        return i

N=int(input())
town=[]
for i in range(N):
    x,y=list(map(int,input().split()))
    town.append([i,x,y])
townX=sorted(town,key=lambda x:x[1])
townY=sorted(town,key=lambda x:x[2])
road=[]
for i in range(1,N):
    heapq.heappush(road,[townX[i][1]-townX[i-1][1],townX[i-1][0],townX[i][0]])
for i in range(1,N):
    heapq.heappush(road,[townY[i][2]-townY[i-1][2],townY[i-1][0],townY[i][0]])

vi=0
ans=0
tree={i:{'p':i,'h':0} for i in range(N)}
while vi<N-1:
    d,u,v = heapq.heappop(road)
    pu=parent(u,tree)
    pv=parent(v,tree)
    if pu == pv:
        continue
    elif tree[pu]['h']<tree[pv]['h']:
        add(u,pv,tree)
    elif tree[pu]['h']==tree[pv]['h']:
        add(u,pv,tree)
        tree[pu]['h']+=1
    else:
        add(v,pu,tree)
    vi+=1
    ans+=d
print(ans)
Problem p03855 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10**6)
def bps(gr,p,s,num):
    if gr[s]!=-1:
        return
    gr[s]=num
    for x in p[s]:
        bps(gr,p,x,num)

N,K,L=list(map(int,input().split()))
dic={}
road=[[] for _ in range(N)]
rail=[[] for _ in range(N)]

for i in range(K):
    p,q=list(map(int,input().split()))
    road[p-1].append(q-1)
    road[q-1].append(p-1)

for i in range(L):
    r,s=list(map(int,input().split()))
    rail[r-1].append(s-1)
    rail[s-1].append(r-1)


roadG=[-1 for _ in range(N)]
num=0
for i in range(N):
    if roadG[i]==-1:
        bps(roadG,road,i,num)
        num+=1

railG=[-1 for _ in range(N)]
num=0
for i in range(N):
    if railG[i]==-1:
        bps(railG,rail,i,num)
        num+=1
dic={}
arr=[]
for i in range(N):
    key=roadG[i]*N+railG[i]
    arr.append(key)
    dic[key]=dic.setdefault(key,0)+1
print(dic[arr[0]],end='')
for x in arr[1:]:
    print(' {}'.format(dic[x]),end='')
print('')

Buggy submission (verdict: Runtime Error):
def bps(gr,p,s,num):
    if gr[s]!=-1:
        return
    gr[s]=num
    for x in p[s]:
        bps(gr,p,x,num)

N,K,L=list(map(int,input().split()))
dic={}
road=[[] for _ in range(N)]
rail=[[] for _ in range(N)]

for i in range(K):
    p,q=list(map(int,input().split()))
    road[p-1].append(q-1)
    road[q-1].append(p-1)

for i in range(L):
    r,s=list(map(int,input().split()))
    rail[r-1].append(s-1)
    rail[s-1].append(r-1)


roadG=[-1 for _ in range(N)]
num=0
for i in range(N):
    if roadG[i]==-1:
        bps(roadG,road,i,num)
        num+=1

railG=[-1 for _ in range(N)]
num=0
for i in range(N):
    if railG[i]==-1:
        bps(railG,rail,i,num)
        num+=1
dic={}
arr=[]
for i in range(N):
    key=roadG[i]*N+railG[i]
    arr.append(key)
    dic[key]=dic.setdefault(key,0)+1
print(dic[arr[0]],end='')
for x in arr[1:]:
    print(' {}'.format(dic[x]),end='')
print('')
Problem p03160 (python)

Fixed submission:
N = int(raw_input())
h_str = raw_input()
h = []
for h_i in h_str.split(" "):
    h.append(int(h_i))

dp = [10 ** 9 + 1] * N
dp[0] = 0
for i in range(N):
    for j in (i + 1, i + 2):
        if j < N:
            dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))
print(dp[N-1])

Buggy submission (verdict: Runtime Error):
import math


N = int(input())
# h = list(map(int, input().split(" ")))
h_str = input()
h = []
for h_i in h_str.split(" "):
    h.append(int(h_i))

dp = [math.inf] * N
dp[0] = 0
for i in range(N):
    for j in (i + 1, i + 2):
        if j < N:
            dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))
print(dp[N-1])

Buggy submission (verdict: Runtime Error):
import math


N = int(input())
h = list(map(int, input().split(' ')))

dp = [math.inf] * N
dp[0] = 0
for i in range(N):
    for j in (i + 1, i + 2):
        if j < N:
            dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))
print(dp[N-1])

Buggy submission (verdict: Runtime Error):
import math


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

dp = [math.inf] * N
dp[0] = 0
for i in range(N):
    for j in (i + 1, i + 2):
        if j < N:
            dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))
print(dp[N-1])

Buggy submission (verdict: Runtime Error):
import math


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

dp = [math.inf] * N
dp[0] = 0
for i in range(N):
    for j in (i + 1, i + 2):
        if j < N:
            dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))
print(f"{dp[N-1]}")

Buggy submission (verdict: Runtime Error):
import math


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

dp = [math.inf] * N
dp[0] = 0
for i in range(N):
    for j in (i + 1, i + 2):
        if j < N:
            dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))
print(dp[N-1])
Problem p02817 (python)

Fixed submission:
arr=list(input().split())
res=arr[1]+arr[0]
print(res)

Buggy submission (verdict: Runtime Error):
s,t=map(input().split())
res=t+s
print(res)
Problem p04048 (python)

Fixed submission:
from fractions import gcd
n,x=map(int,input().split())
print(3*(n-gcd(n,x)))

Buggy submission (verdict: Runtime Error):
import math
n,x=map(int,input().split())
print(3*(n-math.gcd(n,x)))

Buggy submission (verdict: Runtime Error):
import math
n,x=map(int,input().split())
print(3*(n-math.gcd(n,x)))
Problem p02601 (python)

Fixed submission:
a,b,c=map(int,input().split())
k=int(input())
cnt=0
while a>=b:
  b*=2
  cnt+=1
while b>=c:
  c*=2
  cnt+=1
if k>=cnt:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
k=int(input())
cnt=0
while a>=b:
  b*=2
  cnt+=1
while b>=c:
  c*=2
  cnt+=1
if k>=cnt:
  print("Yes")
else:
  print("No")
Problem p02602 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n-k):
  if a[k+i]>a[i]:
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(k-1):
  if a[k+i]>a[i]:
    print("Yes")
  else:
    print("No")
Problem p02609 (python)

Fixed submission:
n = int(input())
x = input()
pcnt = x.count("1")
pp = pcnt+1
pn = pcnt-1
ansb = [0,0,0]
def modpcnt(x):
  if x == 0:
    return 0
  b = x.bit_length()
  mod = 0
  for i in range(b):
    if x&1<<i:
      mod += 1
  return 1+modpcnt(x%mod)
for i in range(n):
  if x[i] == "1":
    ansb[1] += pow(2,n-i-1,pcnt)
    ansb[1] %= pcnt
    ansb[0] += pow(2,n-i-1,pp)
    ansb[0] %= pp
    if pn == 0:
      ansb[2] = 0
    else:
      ansb[2] += pow(2,n-i-1,pn)
      ansb[2] %= pn
for i in range(n):
  if x[i] == "0":
    tmp = (ansb[0]+pow(2,n-i-1,pp))%pp
    print(modpcnt(tmp)+1)
  else:
    if pn == 0:
      print(0)
    else:
      tmp = (ansb[2]-pow(2,n-i-1,pn))%pn
      print(modpcnt(tmp)+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()
pcnt = x.count("1")
pp = pcnt+1
pn = pcnt-1
ansb = [0,0,0]
def modpcnt(x):
  if x == 0:
    return 0
  b = x.bit_length()
  mod = 0
  for i in range(b):
    if x&1<<i:
      mod += 1
  return 1+modpcnt(x%mod)
for i in range(n):
  if x[i] == "1":
    ansb[1] += pow(2,n-i-1,pcnt)
    ansb[1] %= pcnt
    ansb[0] += pow(2,n-i-1,pp)
    ansb[0] %= pp
    ansb[2] += pow(2,n-i-1,pn)
    ansb[2] %= pn
for i in range(n):
  if x[i] == "0":
    tmp = (ansb[0]+pow(2,n-i-1,pp))%pp
    print(modpcnt(tmp)+1)
  else:
    tmp = (ansb[2]-pow(2,n-i-1,pn))%pn
    print(modpcnt(tmp)+1)
Problem p02632 (python)

Fixed submission:
mod = 10**9+7
rng = 2000100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0 or n<k:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
k = int(input())
s = input()
n = len(s)
ans = pow(26,n+k,mod)
for i in range(n):
  ans -= pow(25,n+k-i,mod)*cmb(n+k,i)
  ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
mod = 10**9+7
rng = 1000100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0 or n<k:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
k = int(input())
s = input()
n = len(s)
ans = pow(26,n+k,mod)
for i in range(n):
  ans -= pow(25,n+k-i,mod)*cmb(n+k,i)
  ans %= mod
print(ans)
Problem p02644 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque
h,w,k = map(int,input().split())
sx,sy,gx,gy = map(int,input().split())
grid = [input().rstrip() for i in range(h)]
dp = [[10**6 for i in range(w)] for j in range(h)]
dp[sx-1][sy-1] = 0
q = deque()
q.append((sx-1,sy-1))
while q:
  px,py = q.popleft()
  d = dp[px][py]
  for j in range(1,k+1):
    if px+j >= h or grid[px+j][py] == "@" or dp[px+j][py] <= d:
      break
    if dp[px+j][py] == 10**6:
      dp[px+j][py] = d+1
      q.append((px+j,py))
  for j in range(1,k+1):
    if px-j < 0 or grid[px-j][py] == "@" or dp[px-j][py] <= d:
      break
    if dp[px-j][py] == 10**6:
      dp[px-j][py] = d+1
      q.append((px-j,py))
  for j in range(1,k+1):
    if py+j >= w or grid[px][py+j] == "@" or dp[px][py+j] <= d:
      break 
    if dp[px][py+j] == 10**6:
      dp[px][py+j] = d+1
      q.append((px,py+j))
  for j in range(1,k+1):
    if py-j < 0 or grid[px][py-j] == "@" or dp[px][py-j] <= d:
      break
    if dp[px][py-j] == 10**6:
      dp[px][py-j] = d+1
      q.append((px,py-j))
if dp[gx-1][gy-1] == 10**6:
  print(-1)
else:
  print(dp[gx-1][gy-1])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import deque
h,w,k = map(int,input().split())
sx,sy,gx,gy = map(int,input().split())
grid = [input().rstrip() for i in range(h)]
dp = [[10**6 for i in range(w)] for j in range(h)]
dp[sx-1][sy-1] = 0
q = deque()
q.append((sx-1,sy-1))
while q:
  print(q)
  px,py = q.popleft()
  d = dp[px][py]
  for j in range(1,k+1):
    if px+j >= h or grid[px+j][py] == "@" or dp[px+j][py] <= d:
      break
    dp[px+j][py] = d+1
    q.append((px+j,py))
  for j in range(1,k+1):
    if px-j < 0 or grid[px-j][py] == "@" or dp[px-j][py] <= d:
      break
    dp[px-j][py] = d+1
    q.append((px-j,py))
  for j in range(1,k+1):
    if py+j >= w or grid[px][py+j] == "@" or dp[px][py+j] <= d:
      break 
    dp[px][py+j] = d+1
    q.append((px,py+j))
  for j in range(1,k+1):
    if py-j < 0 or grid[px][py-j] == "@" or dp[px][py-j] <= d:
      break
    dp[px][py-j] = d+1
    q.append((px,py-j))
if dp[gx-1][gy-1] == 10**6:
  print(-1)
else:
  print(dp[gx-1][gy-1])
Problem p02645 (python)

Fixed submission:
s = input()
print(s[:3])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
vw = [[0,0]]+[list(map(int,input().split())) for i in range(n)]
q = int(input())
query = [list(map(int,input().split())) for i in range(q)]
border = 10
knapls = [[] for i in range(2**border)]
knapls[0].append((0,0))
for i in range(1,2**border):
  ls = []
  if i > n:
    break
  ls.extend(knapls[i//2])
  v,w = vw[i]
  l = len(ls)
  for j in range(l):
    vp,wp = ls[j]
    if wp+w > 10**5:
      continue
    ls.append((vp+v,wp+w))
  ls.sort(key = lambda x:x[1])
  knapls[i].append((0,0))

  for j in range(len(ls)):
    vn,wn = ls[j]
    vp,wp = knapls[i][-1]
    if wp <= wn and vp >= vn:
      continue
    knapls[i].append(ls[j])
for v,L in query:
  if v >= 2**border:
    anc = v
    ls = [(0,0)]
    while anc >= 2**border:
      vn,wn = vw[anc]
      l = len(ls)
      for i in range(l):
        vp,wp = ls[i]
        if wp+wn > L:
          continue
        ls.append((vp+vn,wp+wn))
      anc //= 2
    ans = 0
    l = len(ls)
    for i in range(l):
      vn,wn = ls[i]
      rest = L-wn
      left = 0
      right = len(knapls[anc])
      while left+1 < right:
        mid = (left+right)//2
        if knapls[anc][mid][1] > rest:
          right = mid
        else:
          left = mid
      ans = max(knapls[anc][left][0]+vn,ans)
    print(ans)
  else:
    ans = 0
    left = 0
    right = len(knapls[v])
    while left+1 < right:
      mid = (left+right)//2
      if knapls[v][mid][1] > L:
        right = mid
      else:
        left = mid
    ans = knapls[v][left][0]
    print(ans)
Problem p02747 (python)

Fixed submission:
s = input()
if len(s)%2:
  print("No")
  exit()
flg = 1
for i in range(0,len(s),2):
  if s[i:i+2] != "hi":
    flg = 0
if flg:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
ans = [[1 for j in range(2**m-1)] for i in range(2**n-1)]
for i in range(2**n-1):
  for j in range(2**m-1):
    if i%2 != j%2:
      ans[i][j] = 0
    if (abs(i%8) == 3) ^ (abs(j%8) == 3):
      ans[i][j] = 1
for arr in ans:
  print(*arr,sep="")
Problem p02774 (python)

Fixed submission:
import bisect
import numpy as npy
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
n0,np,nn = 0,0,0
for i in a:
  if i>0:  np += 1
  elif i == 0:  n0 += 1
  else:  nn += 1
kp = (np**2-np+nn**2-nn)//2
k0 = n0*(n-n0)+(n0**2-n0)//2
kn = nn*np
if kn < k <= kn+k0:
  print(0)
  exit()
nls = []
pls = []
for i in range(n):
  if a[i] < 0:
    nls.append(a[i])
  elif a[i] > 0:
    pls.append(a[i])
ln = len(nls)
lp = len(pls)
nls = npy.array(nls,dtype=npy.int64)
pls = npy.array(pls,dtype=npy.int64)
if k <= kn:
  l = a[0]*a[-1]-1
  r = 0
  while l+1 < r:
    m = (l+r)//2
    mls = m//nls
    tmp = npy.searchsorted(pls,mls,side="right").sum()
    if tmp > kn-k:
      l = m
    else:
      r = m
  print(l)
else:
  nls = -nls
  nls = nls[::-1]
  k -= kn+k0
  l = 0
  r = max(a[0]**2,a[-1]**2)+1
  while l+1 < r:
    m = (l+r)//2
    tmp  = npy.searchsorted(nls,m//nls,side="right").sum()
    tmp += npy.searchsorted(pls,m//pls,side="right").sum()
    tmp -= npy.searchsorted(nls**2,m,side="left")
    tmp -= npy.searchsorted(pls**2,m,side="left")
    if tmp >= 2*k:
      r = m
    else:
      l = m
  print(r)

Buggy submission (verdict: Runtime Error):
import bisect
import numpy as npy
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
n0 = 0
np = 0
nn = 0
for i in a:
  if i>0:
    np += 1
  elif i == 0:
    n0 += 1
  else:
    nn += 1
kp = (np**2-np+nn**2-nn)//2
k0 = n0*(n-n0)+(n0**2-n0)//2
kn = nn*np
if kn < k <= kn+k0:
  print(0)
  exit()
nls = []
pls = []
for i in range(n):
  if a[i] < 0:
    nls.append(a[i])
  elif a[i] > 0:
    pls.append(a[i])
ln = len(nls)
lp = len(pls)
if k <= kn:
  nls = npy.array(nls,dtype=npy.int32)
  pls = npy.array(pls,dtype=npy.int32)
  l = a[0]*a[-1]-1
  r = 0
  while l+1 < r:
    m = (l+r)//2
    mls = m//nls
    tmp = npy.searchsorted(pls,mls,side="right").sum()
    if tmp > kn-k:
      l = m
    else:
      r = m
  print(l)
else:
  print(2/0)
  """
  l = 0
  r = max(a[0]**2,a[-1]**2)+1
  while l+1 < r:
    m = (l+r)//2
    tmp = 0
    for i in range(ln):
      tmp += 
"""

Buggy submission (verdict: Runtime Error):
import bisect
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
n0 = 0
np = 0
nn = 0
for i in a:
  if i>0:
    np += 1
  elif i == 0:
    n0 += 1
  else:
    nn += 1
kp = (np**2-np+nn**2-nn)//2
k0 = n0*(n-n0)+(n0**2-n0)//2
kn = nn*np
if kn < k <= kn+k0:
  print(0)
  exit()
nls = []
pls = []
for i in range(n):
  if a[i] < 0:
    nls.append(a[i])
  elif a[i] > 0:
    pls.append(a[i])
ln = len(nls)
lp = len(pls)
if k <= kn:
  l = a[0]*a[-1]
  r = 0
  while l+1 < r:
    m = (l+r)//2
    tmp = 0
    for i in range(ln):
      tmp += bisect.bisect_right(pls,m//nls[i])
    if tmp >= kn-k:
      l = m
    else:
      r = m
  print(l)
else:
  print(2/0)
Problem p02798 (python)

Fixed submission:
n = int(input())
a = [list(map(int,input().split())) for _ in range(2)]
dp = [[1000]*(2**n) for _ in range(51)]
dp[0][0] = 0
for S in range(2**n):
  j = bin(S).count("1")
  cnt = 0
  for i in range(n):
    if not (S & 1<<i):
      k = a[(i+j)%2][i]
      for l in range(k+1):
        dp[k][S|1<<i] = min(dp[k][S|1<<i],dp[l][S]+cnt)
    if not (S&1<<i):
      cnt += 1
ans = min(dp[i][-1] for i in range(51))
if ans == 1000:
  print(-1)
else:
  print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import product
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = defaultdict(int)
d = defaultdict(int)
e = []
f = []
forsort = []
for i in range(n):
  if i%2 == 0:
    c[a[i]] = b[i]
    d[b[i]] = a[i]
    e.append(a[i])
    f.append(b[i])
    forsort.append((a[i],1))
    forsort.append((b[i],2))
  else:
    c[a[i]] = b[i]
    d[b[i]] = a[i]
    e.append(b[i])
    f.append(a[i])
    forsort.append((a[i],2))
    forsort.append((b[i],1))
forsort.sort()
x = [forsort[i][1] for i in range(2*n)]
change = [0]
for i in range(1,2*n):
  if x[i] != x[i-1]:
    change.append(i)
change.append(2*n)
changels = []
for i in range(1,len(change)):
  changels.append([j for j in range(change[i-1],change[i])])
p = x[0]
ans = []
for ls in product(*changels):
  array = []
  cannotuse = defaultdict(int)
  for i in range(len(ls)):
    l = ls[i]
    if (p+i)%2 == 1:
      if cannotuse[forsort[l][0]] != 1:
        array.append(forsort[l][0])
        cannotuse[c[forsort[l][0]]] = 1
        cannotuse[forsort[l][0]] = 1
      else:
        break
    if (p+i)%2 == 0:
      if cannotuse[forsort[l][0]] != 1:
        array.append(forsort[l][0])
        cannotuse[d[forsort[l][0]]] = 1
        cannotuse[forsort[l][0]] = 1
      else:
        break
  if len(array) >= n:
    print(array)
    array = array[:n]
    anstmp = 0
    for ind,i in enumerate(array):
      if ind%2 == 0:
        anstmp += abs(e.index(i)-ind)
      else:
        anstmp += abs(f.index(i)-ind)
    ans.append(anstmp)
    anstmp = 0
if not ans:
  print(-1)
else:
  print(min(ans))
Problem p02806 (python)

Fixed submission:
n = int(input())
a = [list(input().split()) for i in range(n)]
b = input()
flg = 0
ans = 0
for i in range(n):
  if a[i][0] == b:
    flg = 1
  elif flg:
    ans += int(a[i][1])
print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = tuple(map(int,input().split()))
mod = 10**9+7
rng = 1001
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
dp = [[0 for i in range(n+1)] for j in range(k+1)]
dp[0][0] = 1
for i in range(1,k+1):
  x = a[i-1]
  for j in range(n+1):
    for t in range(min(n-j,x)+1):
      dp[i][j+t]=(dp[i][j+t]+dp[i-1][j]*cmb(n-j,t)*cmb(n-t,x-t))%mod
print(dp[k][n])

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = tuple(map(int,input().split()))
mod = 10**9+7
rng = 1001
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
dp = [[0 for i in range(n+1)] for j in range(k+1)]
dp[0][0] = 1
for i in range(1,k+1):
  x = a[i-1]
  for j in range(n+1):
    for t in range(min(n-j,x)+1):
      dp[i][j+t]=(dp[i][j+t]+dp[i-1][j]*cmb(n-j,t)*cmb(n-t,x-t))%mod
print(dp[k][n])

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = tuple(map(int,input().split()))
mod = 10**9+7
rng = 1001
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
dp = [[0 for i in range(n+1)] for j in range(k+1)]
dp[0][0] = 1
for i in range(1,k+1):
  x = a[i-1]
  for j in range(n+1):
    for t in range(min(n-j,x)+1):
      dp[i][j+t]=(dp[i][j+t]+dp[i-1][j]*fctr[n-j]*finv[n-j-t]*finv[t]*fctr[n-t]*finv[x-t]*finv[n-x])%mod
print(dp[k][n])