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

Fixed submission:
import heapq
def sol(inp=input):
    s=3
    n,m=map(int,inp().split())
    G={(i+1,j):set() for i in range(n) for j in range(s)}
    for _ in range(m):
        u,v=map(int,inp().split())
        for i in range(s):
            G[(u,i)].add((v,(i+1)%s))
    s,t=map(int,inp().split())
    visited={(s,0)}
    que=[]
    heapq.heappush(que,(0,(s,0)))
    while len(que)>0:
        step,u=heapq.heappop(que)
        for v in G[u]:
            if v not in visited:
                visited.add(v)
                heapq.heappush(que,(step+1,v))
            if v==(t,0):
                return (step+1)//3
    return -1
print(sol())

Buggy submission (verdict: Runtime Error):
import heapq
def sol(inp=input):
    n,m=map(int,inp().split())
    G={i+1:set() for i in range(n)}
    for _ in range(m):
        i,j=map(int,inp().split())
        G[i].add((j,1))
    s,t=map(int,inp().split())
    cache_kenken={}
    def kenkenpa(v):
        for v1,l1 in tuple(G[v]):
            if l1==1:
                for v2,l2 in tuple(G[v1]):
                    if l1+l2==3:
                        yield v2
                        continue
                    else:
                        G[v].add((v2,l1+l2))
                        for v3,l3 in G[v2]:
                            G[v1].add((v3,l2+l3))
                            yield v3
                            continue
            if l1==2:
                for v2,l2 in G[v1]:
                    if l1+l2==3:
                        yield v2
                        continue
        
    visited={s}
    revisited=set()
    v_steps=[]
    visited_pa={s}
    que=[]
    heapq.heappush(que,(0,s))
    while len(que)>0:
        step,u=heapq.heappop(que)
        for v in kenkenpa(u):
            if v not in visited:
                visited.add(v)
                v_steps.append((step+1,v))
                heapq.heappush(que,(step+1,v))
            if v==t:
                return step+1
            if v not in visited:
                visited.add(v)
    return -1
print(sol())
Problem p02995 (python)

Fixed submission:
def sol(inp=input):
    a,b,c,d=map(int,inp().split())
    def gcd(x,y):
        while y>0:
            x,y=y,x%y
        return x
    def fix_min(b):
        c_=b//c
        d_=b//d
        cd_=b//(c*d//gcd(c,d))
        return b-c_-d_+cd_
    return fix_min(b)-fix_min(a-1)
print(sol())

Buggy submission (verdict: Runtime Error):
def sol(inp=input):
    import math
    a,b,c,d=map(int,inp().split())
    def fix_min(b):
        c_=b//c
        d_=b//d
        cd_=b//(c*d//math.gcd(c,d))
        return b-c_-d_+cd_
    return fix_min(b)-fix_min(a-1)
print(sol())
Problem p03008 (python)

Fixed submission:
def knapsack_123(values,weights,capacity):
    work = [0 for i in range(capacity+1)]
    for v,w in zip(values,weights):
        for c in range(w, capacity+1):
            work[c]=max(work[c],work[c-w]+v)
    return work[-1]
def sol(inp=input):
    n=int(inp())
    prices_a=list(map(int,inp().split()))+[1]
    prices_b=list(map(int,inp().split()))+[1]
    
    valA=knapsack_123(values=prices_b,weights=prices_a,capacity=n)
    valB=knapsack_123(values=prices_a,weights=prices_b,capacity=valA)
    return '{}'.format(valB)
print(sol())

Buggy submission (verdict: Runtime Error):
def knapsack_123(values,weights,capacity):
    work = [0 for i in range(capacity+1)]
    for v,w in zip(values,weights):
        for c in range(w, capacity+1):
            work[c]=max(work[c],work[c-w]+v)
    return work[-1]
def sol(inp=input):
    n=int(inp())
    prices_a=list(map(int,inp().split()))+[1]
    prices_b=list(map(int,inp().split()))+[1]
    
    valA,_=knapsack_123(values=prices_b,weights=prices_a,capacity=n)
    print(valA)
    valB,_=knapsack_123(values=prices_a,weights=prices_b,capacity=valA)
    return '{}'.format(valB)
print(sol())
Problem p03043 (python)

Fixed submission:
import math
def sol(inp=input):
    n,k=map(int,inp().split())
    res=0
    for dice_m1 in range(n):
        dice=dice_m1+1
        head=max(0,math.ceil(math.log(k/dice,2)))
        res+=2**-head
    res/=n
    return res
print(sol())

Buggy submission (verdict: Runtime Error):
import math
def sol(inp=input):
    n,k=map(int,inp().split())
    res=0
    for dice_m1 in range(n):
        dice=dice_m1+1
        head=max(0,math.ceil(math.log2(k/dice)))
        res+=2**-head
    res/=n
    return res
print(sol())
Problem p03260 (python)

Fixed submission:
a,b=map(int,input().split())
if(a*b%2==0):
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
a,b=input(int,input().split())
if(a*b%2==0):
  print('No')
else:
  print('Yes')
Problem p03280 (python)

Fixed submission:
a,b=map(int,input().split())
print((a-1)*(b-1))

Buggy submission (verdict: Runtime Error):
n,m,q=map(int,input().split())
counts=[[0 for _ in range(n)]for _ in range(n)]

for _ in range(m):
    l,r=map(int,input().split())
    for i in range(l):
        for j in range(r-1,n):
            counts[i][j]+=1
for _ in range(q):
    l,r=map(int,input().split())
    print(counts[l-1][r-1])
Problem p03282 (python)

Fixed submission:
s=input()
k=int(input())
import re
s1,s2=re.match('^(1*)([2-9])?',s).groups()
if(s1 and k<=len(s1)):
  print(1)
else:
  print(s2)

Buggy submission (verdict: Runtime Error):
s=input()
k=int(input())
import re
s1,s2=re.match('^(1*)([2-9])?',s).groups()
if(s1 and k<=len(s1)):
  print(1)
  else:
    print(s2)
Problem p03283 (python)

Fixed submission:
n,m,q=map(int,input().split())
counts=[[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    l,r=map(int,input().split())
    counts[l-1][r-1]+=1
cumsum=[[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(n):
    for j in range(n):
        cumsum[i+1][j+1]=cumsum[i+1][j]+counts[i][j]
for j in range(n+1):
    for i in range(n):
        cumsum[i+1][j]+=cumsum[i][j]
        
for _ in range(q):
    l,r=map(int,input().split())
    print(cumsum[r][r]-cumsum[r][l-1]-cumsum[l-1][r]+cumsum[l-1][l-1])

Buggy submission (verdict: Runtime Error):
n,m,q=map(int,input().split())
counts=[[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    l,r=map(int,input().split())
    counts[l-1][r-1]+=1
cumsum=[[0 for _ in range(n+1)] for _ in range(n)]
for i in range(m):
    for j in range(m):
        cumsum[i][j+1]=cumsum[i][j]+counts[i][j]
    
for _ in range(q):
    l,r=map(int,input().split())
    print(sum(cumsum[i][r]-cumsum[i][l-1] for i in range(l-1,r)))
Problem p03363 (python)

Fixed submission:
from collections import defaultdict

n=int(input())
cumsum=0
a=list(map(int,input().split()))
counter=defaultdict(int)

counter[0]+=1
for k in a:
  cumsum+=k
  counter[cumsum]+=1

print(sum(map(lambda v: v*(v-1)//2,counter.values())))

Buggy submission (verdict: Runtime Error):
from itertools import combinations, product
n=int(input())
s=[["a" for _ in range(n)] for _ in range(n)]
for i in range(n):
  s[i]=list(input())

res=0
for a in product(range(n)):
  for i,j in combinations(range(n),2):
    if(s[(i+a)%n][(j)%n]!=s[(j+a)%n][(i)%n]):
      break
  else:
    res+=1

print(res*n)
Problem p03404 (python)

Fixed submission:
a,b=map(int,input().split())
print(40,100)
rows=['#'*100 for _ in range(20)]+['.'*100 for _ in range(20)]
rows[0]='#.'*((a-1)%50)+'##'*(50-(a-1)%50)
for i in range((a-1)//50):
  rows[2*i+2]='#.'*50
rows[21]='#.'*((b-1)%50)+'..'*(50-(b-1)%50)
for i in range((b-1)//50):
  rows[2*i+23]='#.'*50
print('\n'.join(rows))

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
print(40,100)
rows=['#'*100 for _ in range(20)]+['.'*100 for _ in range(20)]
rows[0]='#.'*(a%50-1)+'##'*(51-a%50)
for i in range(a//50):
  rows[2*i+2]='#.'*50
rows[21]='#.'*(b%50-1)+'..'*(51-b%50)
for i in range(b//50):
  rows[2*i+23]='#.'*50
for row in rows:
  print(row)
Problem p03423 (python)

Fixed submission:
n=int(input())
print(n//3)

Buggy submission (verdict: Runtime Error):
h,w,d=map(int,input().split())

board=[0 for _ in range(h*w)]

for i in range(h):
    for j,a in enumerate(input().split()):
        board[i*w+j]=int(a)

q=int(input())


distances=[0 for _ in range(h*w)]

for i in range(d,h*w):
    a=h*w-i
    tmp=board.index(a)
    i=tmp//w
    j=tmp%w
    tmp=board.index(a+d)
    x=tmp//w
    y=tmp%w
    distances[a-1]=distances[a+d-1]+abs(i-x)+abs(j-y)

for _ in range(q):
    l,r=map(int,input().split())
    print(distances[l-1]-distances[r-1])
Problem p03451 (python)

Fixed submission:
import numpy as np

N=int(input())

a=[[],[]]
a[0]=list(map(int,input().split()))
a[1]=list(map(int,input().split()))

s=np.array(a)

s[1]=np.cumsum(s[1][::-1])[::-1]

s[0][-1]+=s[1][-1]

for i in range(N-2,-1,-1):
    s[0][i]+=max(s[1][i],s[0][i+1])
print(s[0][0])

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())

x=[0 for _ in range(N)]
gp=[i for i in range(N)]

for _ in range(M):
    l,r,d=map(int,input().split())
    if(gp[l-1]==gp[r-1]):
        if(x[r-1]-x[l-1]!=d):
            print('No')
            break
    else:
        if(gp.count(gp[l-1])<gp.count(gp[r-1])):
            from_gp=gp[l-1]
            to_gp=gp[r-1]
        else:
            from_gp=gp[l-1]
            to_gp=gp[r-1]
        x=[x_+d+gp[l-1] if gp[i]==gp[r-1] else x_ for i,x_ in enumerate(x)]
        gp=[to_gp if gp_==from_gp else gp_ for gp_ in gp]
        if(max(x)>100000):
            print('No')
            break
else:
    print('Yes')
Problem p03494 (python)

Fixed submission:
import numpy as np

s=input()
ar=np.array(list(map(int,input().split())))

i=0
while(np.all(ar%2==0)):
    i+=1
    ar//=2
print(i)

Buggy submission (verdict: Runtime Error):
import numpy as np

s=input()
ar=np.array(list(map(int,input().split())))

i=0
while(np.all(ar%2==0)):
    i+=1
    ar//=2
print(i)
Problem p03547 (python)

Fixed submission:

a,b=input().split()
if(a<b):
  print('<')
elif(a>b):
  print('>')
else:
  print("=")

Buggy submission (verdict: Runtime Error):
a,b=input.split()
if a<b:
  print('<')
elif a>b:
  print('>')
else:
  print("=")
Problem p03557 (python)

Fixed submission:
inf=10**9+1

n=int(input())
array_a=sorted([a for a in map(int, input().split())])+[inf]
array_b=sorted([a for a in map(int, input().split())])+[inf]
array_c=sorted([a for a in map(int, input().split())])

nums_b=[0 for _ in range(n)]
cur=0
for (idx,b) in enumerate(array_b[:-1]):
    while(array_a[cur]<b):
        cur+=1
    nums_b[idx]=cur


cur=0
res=0
for (idx,c) in enumerate(array_c):
    while(array_b[cur]<c):
        res+=nums_b[cur]*(n-idx)
        cur+=1
print(res)

Buggy submission (verdict: Runtime Error):
n=int(input())
array_a=sorted([a for a in map(int, input().split())])+[inf]
array_b=sorted([a for a in map(int, input().split())])+[inf]
array_c=sorted([a for a in map(int, input().split())])
nums_b=[0 for _ in range(n)]
cur=0
for (idx,b) in enumerate(array_b[:-1]):
    while(array_a[cur]<b):
        cur+=1
    nums_b[idx]=cur
nums_c=[0 for _ in range(n)]
cur=0
for (idx,c) in enumerate(array_c):
    while(array_b[cur]<c):
        cur+=1
    nums_c[idx]=sum(nums_b[:cur])
print(sum(nums_c))
Problem p03565 (python)

Fixed submission:
s_=input()
t=input()
 
filled_idx=[i for i in range(len(s_)) if s_[i]!="?"]
 
for t_s in range(len(s_)-len(t),-1,-1):
    t_e=t_s+len(t)
    s=s_[:t_s]+t+s_[t_e:]
    if(all(s[i]==s_[i] for i in filled_idx)):
        s=s.replace("?","a")
        print(s)
        break
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s_=input()
t=input()

p=re.compile(s_.replace("?","."))
t_s=len(s_)-len(t)
t_e=t_s+len(t)
for t_s in range(t_s,-1,-1):
    s=s_[:t_s]+t+s_[t_e:]
    if(p.match(s)):
        s=s.replace("?","a")
        print(s)
        break
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s_=input()
t=input()


t_s=len(s_)-len(t)
t_e=t_s+len(t)
for t_s in range(t_s,-1,-1):
    s=s_[:t_s]+t+s_[t_e:]
    if(re.match(s_.replace("?","."),s)):
        s=s.replace("?","a")
        print(s)
        break
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s_=input()
t=input()

filled_idx=[i for i in range(len(s_)) if s_[i]!="?"]

t_s=len(s_)-len(t)
t_e=t_s+len(t)
for t_s in range(t_s,-1,-1):
    s=s_[:t_s]+t+s_[t_e:]
    if(all(s[i]==s_[i] for i in filled_idx)):
        s=s.replace("?","a")
        print(s)
        break
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s_=input()
t=input()

filled_idx=[i for i in range(len(s_)) if s_[i]!="?"]

t_s=len(s_)-len(t)
t_e=t_s+len(t)
for t_s in range(t_s,-1,-1):
    s=s_[:t_s]+t+s_[t_e:]
    if(all(s[i]==s_[i] for i in filled_idx)):
        s=s.replace("?","a")
        print(s)
        break
else:
    print("UNRESTORABLE")
Problem p03592 (python)

Fixed submission:
N,M,K=map(int,input().split())
isYes=False
for n in range(N+1):
    for m in range(M+1):
        if(N*m+M*n-2*n*m==K and not isYes):
            print('Yes')
            isYes=True
if(not isYes):
    print('No')

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split())

x=N*M-2*K

if x==0:
    print('Yes')
else:
    for d in range(1,abs(x)+1):
        if x%d==0 and (d<newM and abs(x//d)<newM and (N-d)%2==0 and (M-x//d)%2==0):
            print('Yes')
            break
    else:
        print('No')
Problem p03623 (python)

Fixed submission:
myinput=input()
a=[int(x) for x in myinput.split()]
if abs(a[0]-a[1])<abs(a[0]-a[2]):
    print("A")
else:
    print("B")

Buggy submission (verdict: Runtime Error):
myinput=raw_input()
a=[int(x) for x in myinput.split()]
if abs(a[0]-a[1])<abs(a[0]-a[2]):
    print("A")
else:
    print("B")
Problem p03624 (python)

Fixed submission:
myinput=input()
for c in 'abcdefghijklmnopqrstuvwxyz':
    if c not in myinput:
        print(c)
        break
else:
    print('None')

Buggy submission (verdict: Runtime Error):
myinput=input()
for c in string.ascii_lowercase:
    if c not in myinput:
        print(c)
        break
else:
    print('None')

Buggy submission (verdict: Runtime Error):
myinput=input()
a=[int(x) for x in myinput.split()]
if abs(a[0]-a[1])<abs(a[0]-a[2]):
    print("A")
else:
    print("B")

Buggy submission (verdict: Runtime Error):
myinput=raw_input()
for c in string.ascii_lowercase:
    if c not in myinput:
        print(c)
        break
else:
    print('None')
Problem p03625 (python)

Fixed submission:
n=int(input())
a=map(int, input().split())
a=sorted(a)[::-1]
k=-2
l=-2
for i in range(n-1):
    if (a[i]==a[i+1])&(i>k+1):
        if (k>=0):
            l=i
            break
        else:
            k=i
if l>=0:
    print(a[k]*a[l])
else:
    print(0)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=map(int, input().split())
a=sorted(a)[::-1]
n=int(myinput)
myinput="3 3 3 3 4 4 4 5 5 5"
a=map(int, myinput.split())
a=sorted(a)[::-1]
Problem p02612 (python)

Fixed submission:
n=int(input())
k=n//1000
if n%1000!=0:print((k+1)*1000-n)
else:print(0)

Buggy submission (verdict: Runtime Error):
n=int(input())
if k%1000!=0:print((k+1)*1000-n)
else:print(0)
Problem p02613 (python)

Fixed submission:
n=int(input())
a,b,c,d=0,0,0,0
l=[input() for _ in range(n)]
for i in range(n):
    if l[i]=='AC':a+=1
    elif l[i]=='WA':b+=1
    elif l[i]=='TLE':c+=1
    else:d+=1
print('AC','x',a)
print('WA','x',b)
print('TLE','x',c)
print('RE','x',d)

Buggy submission (verdict: Runtime Error):
n=int(input())
a,b,c,d=0,0,0,0
for i in range(n):
    if str(input())=='AC':a+=1
    elif str(input())=='WA':b+=1
    elif str(input())=='TLE':c+=1
    else:d+=1
print('AC','x',a)
print('WA','x',b)
print('TLE','x',c)
print('RE','x',d)

Buggy submission (verdict: Runtime Error):
n=int(input())
a,b,c,d=0,0,0,0
for i in range(n):
    if input()=='AC':a+=1
    elif input()=='WA':b+=1
    elif input()=='TLE':c+=1
    else:d+=1
print('AC','x',a)
print('WA','x',b)
print('TLE','x',c)
print('RE','x',d)
Problem p02616 (python)

Fixed submission:
import numpy as np
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
s=1
c=0
l=0
r=-1
c1=0
while True:
    if k-c>=2:
        if a[r]*a[r-1]>a[l]*a[l+1]:
            s*=a[r]*a[r-1]
            r-=2
            c+=2
        else:
            s*=a[l]*a[l+1]
            l+=2
            c+=2
    else:
        if a[r]<0:
            s=1
            a=np.absolute(a)
            a=list(a)
            a.sort()
            while True:
                s*=a[c1]
                c1+=1
                s%=10**9+7
                if c1==k:
                    s=-s
                    print(s%10**9+7)
                    exit()
        else:s*=a[r]
        c+=1
    s%=10**9+7
    if k==c:break
print(s)

Buggy submission (verdict: Runtime Error):
import numpy as np
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
s=1
c=0
l=0
r=-1
while True:
    if k-c>=2:
        if a[r]*a[r-1]>=a[l]*a[l+1]:
            s*=a[r]*a[r-1]
            r-=2
            c+=2
        else:
            s*=a[l]*a[l+1]
            l+=2
            c+=2
    else:
        if a[r]<0:
            s=1
            a=np.absolute(a)
            a=list(a)
            a.sort()
            while True:
                s*=a[c1]
                c1+=1
                s%=10**9+7
                if c1==k:
                    s=-s
                    print(s%10**9+7)
                    exit()
        else:s*=a[r]
        c+=1
    s%=10**9+7
    if k==c:break
print(s)

Buggy submission (verdict: Runtime Error):
import numpy as np
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
s=1
c=0
l=0
r=-1
while True:
    if k-c>=2:
        if a[r]*a[r-1]>=a[l]*a[l+1]:
            s*=a[r]*a[r-1]
            r-=2
            c+=2
        else:
            s*=a[l]*a[l+1]
            l+=2
            c+=2
    else:
        if a[r]<0:
            s=1
            a=np.abs(a)
            a=list(a)
            a.sort()
            while True:
                s*=a[c1]
                c1+=1
                s%=10**9+7
                if c1==k:
                    s=-s
                    print(s%10**9+7)
                    exit()
        else:s*=a[r]
        c+=1
    s%=10**9+7
    if k==c:break
print(s)

Buggy submission (verdict: Runtime Error):
import numpy as np
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
s=1
c=0
l=0
r=-1
while True:
    if k-c>=2:
        if a[r]*a[r-1]>=a[l]*a[l+1]:
            s*=a[r]*a[r-1]
            r-=2
            c+=2
        else:
            s*=a[l]*a[l+1]
            l+=2
            c+=2
    else:
        if a[r]<0:
            s=1
            a=np.abs(a)
            a=list(a)
            a.sort()
            print(a)
            while True:
                s*=a[c1]
                c1+=1
                s%=10**9+7
                print(s)
                if c1==k:
                    s=-s
                    print(s%10**9+7)
                    exit()
        else:s*=a[r]
        c+=1
    s%=10**9+7
    if k==c:break
print(s)
Problem p02630 (python)

Fixed submission:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
q=int(input())
s=sum(a)
d=Counter(a)
for i in range(q):
    b,c=map(int,input().split())
    if b in d:
        l=d[b]
        d[b]=0
        d[c]+=l
        s+=(c-b)*l
        print(s)
    else:print(s)

Buggy submission (verdict: Runtime Error):
from collections import Counter
a=list(map(int,input().split()))
s=sum(a)
d=Counter(a)
for i in range(q):
    b,c=map(int,input().split())
    if b in d:
        l=d[b]
        d[b]=0
        d[c]+=l
        s+=(c-b)*l
        print(s)
    else:print(s)
Problem p02660 (python)

Fixed submission:
n=int(input())

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])

    return arr

def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

k=make_divisors(n)
c=0
for i in range(len(k)):
    if i==0:pass
    else:
        l1=factorization(k[i])
        seigo=is_prime(l1[0][0])
        if len(l1)==1 and seigo==True and n%k[i]==0:
            n//=k[i]
            c+=1
        
print(c)

Buggy submission (verdict: Runtime Error):
import sympy
n=int(input())
k=sympy.divisors(n)
c=0
for i in range(len(k)):
    if i==0:pass
    else:
        if n%k[i]==0:
            n//=k[i]
            c+=1
print(c)
Problem p02683 (python)

Fixed submission:
n,m,x=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(n)]
l=[]
for i in range(2**n):
    l.append(format(i,'b').zfill(n))
l1=[]
for i in range(len(l)):
    s=[0]*(m+1)
    for j in range(n):
        if l[i][j]=='1':
            for k in range(m+1):
                s[k]+=c[j][k]

    for o in range(1,m+1):
        if s[o]<x:break
        if o==m:l1.append(s[0])
if len(l1)==0:print(-1) 
else:print(min(l1))

Buggy submission (verdict: Runtime Error):
n,m,x=map(int,input().split())
c=list(map(int,input().split()))
l=[]
for i in range(2**n):
    l.append(format(i,'b').zfill(n))
l1=[]
for i in range(len(l)):
    s=[0]*(m+1)
    for j in range(n):
        if l[i][j]=='1':
            for k in range(m+1):
                s[k]+=c[j][k]

    for o in range(1,m+1):
        if s[o]<x:break
        if o==m:l1.append(s[0])
if len(l1)==0:print(-1) 
else:print(min(l1))

Buggy submission (verdict: Runtime Error):
n,m,x=map(int,input().split())
c=list(map(int,input().split()) for _ in range(n))
l=[]*n
for i in range(n):
    b=[0,0]
    b[0]+=i+1
    b[1]+=a[i]
    l.append(b)
c=0
ne=0
l1=[0]*n
while True:
    if c==k:
        print(l[ne][1])
        exit()
    ne+=-ne+l[ne][1]-1
    c+=1
    if l1[ne]==0:l1[ne]+=1
    else:break

roop_c=0
while True:
    if c+roop_c==k:
        print(l[ne][1])
        exit()
    if l1[ne]==1:l1[ne]+=1
    else:break
    ne+=-ne+l[ne][1]-1
    roop_c+=1

re=(k-c)%roop_c
if re==0:print(l[ne][0])
else:
    for i in range(re):
        if i==re-1:print(l[ne][1])
        ne+=-ne+l[ne][1]-1
Problem p02684 (python)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
l1=[0]*n
l1[0]+=1
c=0 #ループに入る前までの移動回数
now=0#現在位置
ne=a[now]-1 #次の移動位置
while True:
    if c==k:
        print(now+1)
        exit()
    if l1[ne]==0:
        l1[ne]+=1
        now=ne
        ne=a[now]-1
        c+=1
    else:
        now=ne
        ne=a[now]-1
        c+=1
        break

roop_c=0
while True:
    if c+roop_c==k:
        print(now+1)
        exit()
    if l1[ne]==1:
        l1[ne]+=1
        now=ne
        ne=a[now]-1
        roop_c+=1
    else:break

re=(k-c)%roop_c
if re==0:print(now+1)
else:
    for i in range(re):
        if i==re-1:print(ne+1)
        ne+=-ne+a[ne]-1

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=[]*n
for i in range(n):
    b=[0,0]
    b[0]+=i+1
    b[1]+=a[i]
    l.append(b)
c=0
ne=0
l1=[0]*n
while True:
    if c==k:
        print(l[ne][1])
        exit()
    ne+=-ne+l[ne][1]-1
    c+=1
    if l1[ne]==0:l1[ne]+=1
    else:
        roop_act+=ne
        break

roop_c=0
while True:
    if c+roop_c==k:
        print(l[ne][1])
        exit()
    if l1[ne]==1:l1[ne]+=1
    else:break
    ne+=-ne+l[ne][1]-1
    roop_c+=1

re=(k-c)%roop_c
if re==0:print(l[ne][0])
else:
    for i in range(re):
        if i==re-1:print(l[ne][1])
        ne+=-ne+l[ne][1]-1
Problem p02719 (python)

Fixed submission:
n,k=map(int,input().split())
if n%k==0:print(0)
else:print(min(k-n%k,n%k))

Buggy submission (verdict: Runtime Error):
import fractions
n,k=map(int,input().split())
if k==1:print(0)
else:print(gcd(n,k))