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

Fixed submission:
inf=10**43
n,m=map(int,input().split())
edges=[None]*m 
for i in range(m):
    a,b,c=map(int,input().split())
    a-=1 
    b-=1 
    edges[i]=(a,b,-c)
d=[inf]*n 
f=1 
d[0]=0 
for i in range(n-1): 
    for (a,b,c) in edges: 
        if d[a]+c<d[b]:
            d[b]=d[a]+c #update distances 
#print(d)
for i in range(n):
    for (a,b,c) in edges: 
        if d[b]>d[a]+c:  #how can a->b be minimised by travelling 
                         #some other path
            if b==n-1:
                f=0
                #print(b,d[b])
            else:
                d[b]=d[a]+c 
if f:  
    print(-d[n-1])
else:
    print('inf')

Buggy submission (verdict: Runtime Error):
# Python program to print all paths from a source to destination. 
cnt=0 
ans=0 
from collections import defaultdict 
from collections import Counter 
def check(arr): 
    #print(arr)
    ans=0 
    for i in range(1,len(arr)):
        ans+=e[(arr[i-1],arr[i])]
   # print(ans)
    return ans 
maxi=-10**1999  
mini=10**9 
#    sents a directed graph 
# using adjacency list representation 
class Graph: 

	def __init__(self,vertices): 
		#No. of vertices 
		self.V= vertices 
		
		# default dictionary to store graph 
		self.graph = defaultdict(list) 

	# function to add an edge to graph 
	def addEdge(self,u,v): 
		self.graph[u].append(v) 
	def printAllPathsUtil(self, u, d, visited, path):
	   
		# Mark the current node as visited and store in path 
		visited[u]= True
		path.append(u) 
		global ans 
		global maxi
		# If current vertex is same as destination, then print 
		# current path[] 
		if u ==d: 
		   # print(path)
		    if check(path): 
		        maxi=max(maxi,check(path))
		else: 
			# If current vertex is not destination 
			#Recur for all the vertices adjacent to this vertex 
			for i in self.graph[u]: 
				if visited[i]==False: 
					self.printAllPathsUtil(i, d, visited, path) 
					
		# Remove current vertex from path[] and mark it as unvisited 
		path.pop() 
		visited[u]= False


	# Prints all paths from 's' to 'd' 
	def printAllPaths(self,s, d): 

		# Mark all the vertices as not visited 
		visited =[False]*(self.V) 

		# Create an array to store paths 
		path = [] 

		# Call the recursive helper function to print all paths 
		self.printAllPathsUtil(s, d,visited, path) 



# Create a graph given in the above diagram 
n,m=map(int,input().split())
g = Graph(n)
e={}
from collections import defaultdict
di=defaultdict(list)
for i in range(m): 
    a,b,c=map(int,input().split())
    g.addEdge(a-1,b-1)
    e[(a-1,b-1)]=c 
    a-=1 
    b-=1 
    di[a].append(b)
    #g.addEdge(b-1,a-1)

s=0 
d=n-1 
q=[n-1]
vis=[0]*n 
vis[n-1]=1 
while q:
    t=q.pop(0)
    for i in di[t]:
        if not vis[i]:
            q.append(i)
            vis[i]=1 
f=1 
if vis[0]:
    f=0 
g.printAllPaths(s, d) 
print(maxi if f else 'inf')
Problem p03738 (python)

Fixed submission:
a=input()
b=input()
if len(a)>len(b):
    print('GREATER')
elif len(a)<len(b):
    print('LESS')
else:
    n=len(a)
    for i in range(n):
        if a[i]<b[i]:
            print('LESS')
            exit()
        if a[i]>b[i]:
            print('GREATER')
            exit()
    print('EQUAL')

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a>b:
    print('GREATER')
elif a<b:
    print('LESS')
else:
    print('EQUAL')
Problem p03760 (python)

Fixed submission:
s1=input()
s2=input()
n=len(s1)
ans=''
for i in range(min(len(s1),len(s2))):
    ans+=s1[i]+s2[i]
#print(i)
if i!=len(s1)-1:
    ans+=s1[i+1]
if i!=len(s2)-1:
    ans+=s2[i+1]
print(ans)

Buggy submission (verdict: Runtime Error):
s1=input()
s2=input()
n=len(s1)
ans=''
for i in range(n):
    ans+=s1[i]+s2[i]
print(ans)
Problem p03863 (python)

Fixed submission:
s=input()
if s[0]==s[-1]:
    opt=len(s)-3 
    if opt&1: 
        print('First')
    else:
        print('Second')
else: 
    opt=len(s)-2 
    if opt&1:
        print('First')
    else:
        print('Second')

Buggy submission (verdict: Runtime Error):
s=input()
if s==s[::-1]:
    opt=n-3 
    if opt&1: 
        print('First')
    else:
        print('Second')
else: 
    print('First')
Problem p03963 (python)

Fixed submission:
n,k=map(int,input().split())
tot=n//2+n%2 
h=n//2 
ans=pow(k,1) *pow(k-1,n-1) 
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
t=n//2+n%2 
h=n//2 
ans=pow(k,tot) *pow(k-1,h) 
print(ans)
Problem p04044 (python)

Fixed submission:
n,m=map(int,input().split())
mat=[]
for i in range(n):
    mat.append(input())
mat.sort(key=lambda x:x)
ans=''
for i in mat:
    ans+=i 
print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
mat=[]
for i in range(n):
    mat.append(list(input()))
mat.sort(key=lambda x:x)
ans=''
for i in mat:
    ans+=i 
print(ans)
Problem p02717 (python)

Fixed submission:
inputline = list(map(lambda x:int(x), input().split(" ")))
print(inputline[2], inputline[0], inputline[1])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))[::-1]
A_sum = sum(A)

count = 0;
criteria = A_sum/(4*M)

print("No") if (A[M - 1] < criteria) else print("Yes")
Problem p03470 (python)

Fixed submission:
import collections
ds = []
N = int(input())
for _ in range(N):
    ds.append(input())
print(len(collections.Counter(ds)))

Buggy submission (verdict: Runtime Error):
import collections
ds = []
N = int(input())
for _ in range(N):
    ds.append(input())
print(len(ollections.Counter(ds)))
Problem p03472 (python)

Fixed submission:
def solve():
    N,H = list(map(int, input().split()))
    az = []
    bz = []
    for i in range(N):
        a,b = list(map(int, input().split()))
        az.append(a)
        bz.append(b)
        
    amax = max(az)
    bz.sort(reverse=True)
    cnt = 0
    for b in bz:
        if amax < b:
            H -= b
            cnt += 1
        if H <= 0:
            return cnt
    if H <= 0:
        return cnt
    cnt += int(H / amax)
    cnt += min(H % amax, 1)
    return cnt
        
print(solve())

Buggy submission (verdict: Runtime Error):
def solve():
    N,H = list(map(int, input().split()))
    az = []
    bz = []
    for i in range(N):
        a,b = list(map(int, input().split()))
        az.append(a)
        bz.append(b)
        
    amax = max(az)
    bz.sort(reverse=True)
    cnt = 0
    for b in bz:
        if amax < b:
            H -= b
            cnt += 1
        if H <= 0:
            return cnt
    if H <= 0:
        return cnt)
    cnt += int(H / amax)
    cnt += min(H % amax, 1)
    return cnt
        
print(solve())
Problem p03501 (python)

Fixed submission:
N, A, B = list(map(int, input().split()))
 
print(B if A*N > B else A*N)

Buggy submission (verdict: Runtime Error):
A, B, C = list(map(int, input().split()))

print(B if A*N < B else A*N)
Problem p04047 (python)

Fixed submission:
#!/usr/bin/python3
N = int(input())
L = list(map(int, input().split()))

L.sort()

print(sum(L[0::2]))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
import sys

sys.setrecursionlimit(100000)

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

def f(a,b):
    if a > b:
        a,b = b,a
    if a==0 or b==0:
        return 0
    if b%a is 0:
        return int(a*(2*(b/a)-1))

    return int(2*a*int(b/a) + f(a,b%a))

print(N+f(N-X, X))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
N = int(input())
L = list(map(int, input().split()))

L.sort()

print(sum(L[0::2]))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
N = int(input())
L = list(map(int, input().split()))

L.sort()

print(sum(L[0::2]))
Problem p02887 (python)

Fixed submission:
n = int(input())
s = input()
 
before = 'aaa'
ans = 0
for char in s:
  if char != before:
    before = char
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()

before = aaa
ans = 0
for char in s:
  if char != before:
    before = char
    ans += 1
print(ans)
Problem p02945 (python)

Fixed submission:
(lambda x, y: print(max(x+y, x-y, x*y)))(*map(int,input().split()))

Buggy submission (verdict: Runtime Error):
(lambda x, y: print(max(a+b, a-b, a*b)))(map(int,input().split()))
Problem p02952 (python)

Fixed submission:
n = int(input())
ans = 0
for i in range(1, n+1):
    if 1 <= i < 10 or 100 <= i < 1000 or 10000 <= i < 100000:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
2 print(len(list(filter(lambda x: len(str(x)) % 2 == 1, range(1, int(input()) + 1)))))
Problem p03029 (python)

Fixed submission:
a, p = map(int, input().split())
print((3 * a + p) // 2)

Buggy submission (verdict: Runtime Error):
print((3*int(input())+int(input()))//2)

Buggy submission (verdict: Runtime Error):
a, p = map(int, input())
print((3 * a + p) // 2)
Problem p03240 (python)

Fixed submission:
# Pyramid
n = int(input())
data = []
h_ = 0
for i in range(n):
    data.append(list(map(int, input().split())))
data = sorted(data, key=lambda x: x[2], reverse=True)
for cx in range(101):
    for cy in range(101):
        for j in range(n):
            if j == 0:
                h_ = data[0][2] + abs(cx - data[0][0]) + abs(cy - data[0][1])
            else:
                if data[j][2] == max(0, h_ - abs(cx - data[j][0]) - abs(cy - data[j][1])):
                    if j == n - 1:
                        print('{0} {1} {2}'.format(cx, cy, h_))
                        exit()
                    else:
                        continue
                else:
                    break

Buggy submission (verdict: Runtime Error):
# Pyramid
n = int(input())
x, y, h = [], [], []
flag = True
ans_x, ans_y, ans_h = 0, 0, 0
for i in range(n):
    _x_, _y_, _h_ = map(int, input().split())
    if _h_ == 0:
        break
    x.append(_x_)
    y.append(_y_)
    h.append(_h_)
for cx in range(101):
    for cy in range(101):
        for j in range(n):
            h_ = h[j] + abs(x[j] - cx) + abs(y[j] - cy)
            if flag is True:
                flag = h_
            elif flag == h_:
                if j == n - 1:
                    ans_x, ans_y, ans_h = cx, cy, h_
                else:
                    pass
            else:
                flag = True
                break
print('{0} {1} {2}'.format(ans_x, ans_y, ans_h))
Problem p03260 (python)

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

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().slice())
if a == 2 or b == 2:
    print('No')
else:
    print('Yes')
Problem p03261 (python)

Fixed submission:
# Shiritori
n = int(input())
li = []
for i in range(n):
    li.append(list(input()))
for j in range(n-1):
    if li[j][-1] == li[j+1][0]:
        for k in range(j):
            if li[j] == li[k] or li[-1] == li[k]:
                print('No')
                exit()
    else:
        print('No')
        exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
# Shiritori
n = int(input())
li = []
for i in range(n):
    li.append(list(input()))
for j in range(n):
    if li[j][-1] != li[j+1][0]:
        print('No1')
        exit()
    for k in range(j):
        if li[j] == li[k]:
            print('No2')
            exit()
print('Yes')
Problem p03280 (python)

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

Buggy submission (verdict: Runtime Error):
# To Infinity
import re
s = input()
k = int(input())
ind = re.search(r'[23456789]', s)
if ind is None:
    ind = k
else:
    ind = ind.start()
if ind < k:
        print(s[ind])
else:
    print(1)
Problem p03294 (python)

Fixed submission:
# Modulo Summation
input()
a = list(map(int, input().split()))
x = 1
for i in a:
    x *= i
print(sum(list(map(lambda j: (x - 1) % j, a))))

Buggy submission (verdict: Runtime Error):
# Modulo Summation
import math
from functools import reduce


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


n = int(input())
a = list(map(int, input().split()))
m = reduce(lcm, a, 1) - 1
print(sum(map(lambda x: m % x, a)))
Problem p03309 (python)

Fixed submission:
# Linear Approximation
from statistics import median
n = int(input())
a = list(map(int, input().split()))
b = []
_sum = 0
for i in range(n):
    b.append(a[i] - i - 1)
med = median(b)
for i in range(n):
    _sum += abs(b[i] - med)
print(int(_sum))

Buggy submission (verdict: Runtime Error):
# Linear Approximation
from statistics import median
n = int(input())
a = list(map(int, input().split()))
b = []
_sum = 0
for i in range(n):
    b.append(a[i] - i - 1)
print(med)
for i in range(n):
    _sum += abs(b[i] - med)
print(int(_sum))
Problem p03644 (python)

Fixed submission:
n = int(input())
l = [1, 2, 4, 8, 16, 32, 64, 128]
i = 0
while l[i] <= n:
  i += 1
else:
  print(l[i-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
l = [1, 2, 4, 8, 16, 32, 64]
i = 0
while l[i] < n:
  i += 1
else:
  print(l[i])
Problem p03645 (python)

Fixed submission:
n, m = map(int, input().split())
ab = [(lambda x, y:(x, y))(*map(int, input().split())) for _ in range(m)]
d = {}
for x in ab:
  if x[0] in d.keys():
    d[x[0]].append(x[1])
  else:
    d[x[0]] = [x[1]]
moyo = []
for z in d[1]:
  if z in d.keys():
    moyo += d[z]
for z in moyo:
  if z == n:
    exit(print('POSSIBLE'))
print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
ab = [(lambda x, y:(x, y))(*map(int, input().split())) for _ in range(m)]
d = {}
for x in ab:
  if x[0] in d.keys():
    d[x[0]].append(x[1])
  else:
    d[x[0]] = [x[1]]
moyo = []
for z in d[1]:
  moyo += d[z]
for z in moyo:
  if z == n:
    exit(print('POSSIBLE'))
print('IMPOSSIBLE')
Problem p02585 (python)

Fixed submission:
import numpy as np


def parse():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    c = list(map(int, input().split()))
    pc = {i: (pi - 1, ci) for i, (pi, ci) in enumerate(zip(p, c))}
    return k, pc


def split_simple():
    k, pc = parse()
    lst = [[]]
    lst[0].append(pc.pop(0))
    while True:
        if not pc:
            break
        p, _ = lst[-1][-1]
        if p in pc:
            pcj = pc.pop(p)
            lst[-1].append(pcj)
        else:
            j = next(iter(pc.keys()))
            pcj = pc.pop(j)
            lst.append([pcj])
    return k, [np.array([ls[1] for ls in lst_], dtype=np.long) for lst_ in lst]


def inner(n, k, s, sim):
    # print(sim)
    # print(s)
    if sim.shape[1] == 1:
        return sim.max()
    if k < n or s <= 0:
        return sim.max()
    div = k // n
    mod = k % n
    # print(k, n, div, mod)
    if mod == 0:
        return max(s * div, s * (div - 1) + sim.max())
    try:
        return max(s * div + sim[:, :mod].max(), s * (div - 1) + sim[:, :mod].max())
    except ValueError:
        print(mod)
        print(sim)
        print(sim.shape)
        raise


def main():
    k, data_set = split_simple()
    result = min([d.min() for d in data_set])
    for data in data_set:
        n = data.size
        rep = np.repeat(data[None], 2, axis=0).flatten()
        # sim_ = np.array([[rep[i:i+p].sum()
        #                  for p in range(1, min(k, n) + 1)] for i in range(n)])
        sim = np.array([np.cumsum(rep[i:i+min(k, n)]) for i in range(n)])
        # print((sim == sim_).all())
        cand = inner(n, k, data.sum(), sim)
        result = max(result, cand)
    print(result)


if __name__ == "__main__":
    main()

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


def parse():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    c = list(map(int, input().split()))
    pc = {i: (pi - 1, ci) for i, (pi, ci) in enumerate(zip(p, c))}
    return k, pc


def split_simple():
    k, pc = parse()
    lst = [[]]
    lst[0].append(pc.pop(0))
    while True:
        if not pc:
            break
        p, _ = lst[-1][-1]
        if p in pc:
            pcj = pc.pop(p)
            lst[-1].append(pcj)
        else:
            j = next(iter(pc.keys()))
            pcj = pc.pop(j)
            lst.append([pcj])
    return k, [np.array([ls[1] for ls in lst_], dtype=np.long) for lst_ in lst]


def inner(n, k, s, sim):
    if k < n or s <= 0:
        return sim.max()
    else:
        div = k // n
        mod = k % n
        return s * div + sim[:, :mod].max()


def main():
    k, data_set = split_simple()
    result = min([d.min() for d in data_set])
    for data in data_set:
        n = data.size
        rep = np.repeat(data[None], 2, axis=0).flatten()
        sim = np.array([[rep[i:i+p].sum()
                         for p in range(1, min(k, n) + 1)] for i in range(n)])
        cand = inner(n, k, data.sum(), sim)
        result = max(result, cand)
    print(result)


if __name__ == "__main__":
    main()
Problem p03126 (python)

Fixed submission:
N, M = map(int, input().split())

like = [1] * M

for i in range(N):
    K, *A = map(int, input().split())
    for i in range(M):
        if i + 1 not in A:
            like[i] = 0
print(sum(like))

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

N, M = map(int, input().split())
A = np.full((N, M), 0)
for i in range(N):
    Ka = map(int, input().split())
    a = Ka[1:]
    for j in a:
        A[i, j-1] = 1
        
print(np.sum(np.prod(A, axis=0)))
Problem p02683 (python)

Fixed submission:
N , M ,X = map(int,input().split())
L = []
for _ in range(N):
    l = list(map(int,input().split()))
    L.append(l)
ans = []
for i in range(2 ** N):
    rikai = [0 for _ in range(M)]
    cost = 0
    for b in range(N):
        if i  & (1 <<  b):
            for x in range(1,M + 1):
                rikai[x-1] += L[b][x] 
            cost += L[b][0]
    for x in rikai:
        if x < X: break
    else:
        ans.append(cost)
try:
    print(min(ans))
except:
    print(-1)

Buggy submission (verdict: Runtime Error):
N , M ,X = map(int,input().split())
L = []
for _ in range(N):
    l = list(map(int,input().split()))
    L.append(l)
ans = []
for i in range(2 ** N):
    rikai = [0 for _ in range(M)]
    cost = 0
    for b in range(N):
        if i  & (1 <<  b):
            for x in range(1,M + 1):
                rikai[x-1] += L[b][x] 
            cost += L[b][0]
    for x in rikai:
        if x < X: break
    else:
        ans.append(cost)

print(min(ans))
Problem p02690 (python)

Fixed submission:
x = int(input())
import math
f = 1
for A in range(-10**5,10**5):
    A5 = A ** 5
    if x - A5 > 0:
        f = -1
        B = round(math.pow(x - A5,1/5),0)
    else:
        B = round(math.pow(-(x - A5),1/5),0)
    if  A5 == x + int(B*f) ** 5:
        print(A,int(B)*f)
        quit()

Buggy submission (verdict: Runtime Error):
x = int(input())
import math
for A in range(-10**5,10**5):
    A5 = A ** 5
    B = round(math.pow(x - A5,1/5),0)
    if  A5 == x + int(B) ** 5:
        print(A,int(B))
        quit()
Problem p02761 (python)

Fixed submission:
N , M = map(int,input().split())
L = []
for _ in range(M):
    m = tuple(map(int,input().split()))
    L.append(m)
if N == 1:
    for ans in range(0,10):
        ans = str(ans)
        for x in L:
            if ans[x[0] - 1] != str(x[1]):
                break
        else:
            print(ans)
            exit()
    print(-1)
    exit()
else:
    for ans in range(10 ** (N - 1),10 ** N ):
        ans = str(ans)
        for x in L:
            if ans[x[0] - 1] != str(x[1]):
                break
        else:
            print(ans)
            exit()
    print(-1)
    exit()

Buggy submission (verdict: Runtime Error):
N, M = map(int,input().split())
S = []
for i in range(M):
    s = tuple(map(int,input().split()))
    S.append(s)
ans = [-1 for _ in range(M)]

for x in S:
    if ans[x[0]-1] == -1 or ans[x[0]-1] == x[1]:
        ans[x[0]-1] = x[1]
    else:
        print(-1)
        exit()
if N > 1 and ans[0] == 0:
    print(-1)
    exit()

for i in range(len(ans)):
    if ans[i] == -1 :    
        if i == 0:
            print('1',end='')
        else:
            print('0',end='')
    else:
        print(ans[i],end='')
print()

Buggy submission (verdict: Runtime Error):
N , M = map(int,input().split())
L = []
for _ in range(M):
    m = tuple(map(int,input().split()))
    L.append(m)
if N == 1:
    for ans in range(0,10):
        ans = str(ans)
        for x in L:
            if ans[x[0] - 1] != str(x[1]):
                break
        else:
            eixt()
    print(-1)
    exit()
else:
    for ans in range(10 ** (N - 1),10 ** N ):
        ans = str(ans)
        for x in L:
            if ans[x[0] - 1] != str(x[1]):
                break
        else:
            print(ans)
            exit()
    print(-1)
    exit()
Problem p02991 (python)

Fixed submission:
N,M = map(int,input().split())
import time
start_t = time.time()
path = [[] for _ in range(N+3)]
for _ in range(M):
    u,v = map(int,input().split())
    path[u].append(v)

S,T = map(int,input().split())
import collections

q = collections.deque()
vis = [[-1 for _ in range(3)] for _ in range(N+3)]
vis[S][0] = 1
q.append([S,0])
while len(q):
    now,cnt = q.popleft()
    step = cnt % 3
    for x in path[now]:
        if vis[x][(step+1)%3] < 0:
            vis[x][(step+1)%3] = cnt
            q.append((x,cnt+1))

if vis[T][0] == -1:
    print(-1)
else:
    print(vis[T][0]//3+1)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
import time
start_t = time.time()
path = [[] for _ in range(N)]
for _ in range(M):
    u,v = map(int,input().split())
    path[u].append(v)

S,T = map(int,input().split())
import collections

q = collections.deque()
vis = [[-1 for _ in range(3)] for _ in range(N+3)]
vis[S][0] = 1
q.append([S,0])
while len(q):
    now,cnt = q.popleft()
    step = cnt % 3
    vis[now][step] = cnt
    if now == T and step  == 0:  
        print(cnt//3)
        exit()
    for x in path[now]:
        if vis[x][(step+1)%3] < 0:
            q.append((x,cnt+1))
print(-1)
exit()

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
path = [[] for _ in range(N*3+3)]
for _ in range(M):
    u,v = map(int,input().split())
    path[u].append(v+N)
    path[u+N].append(v+N+N)
    path[u+N+N].append(v)

S,T = map(int,input().split())
import collections

q = collections.deque()
vis = [10**10 for _ in range(N*3+3)]
def bfs():
    while len(q) > 0:
        now = q.popleft()
        #print(now,T,cnt,path[now],q)
        vis[now] = min(vis[now],cnt)
        if now == T: 
            return cnt
        for x in path[now]:
            if vis[x] == 10**10:
                q.append((x,cnt+1))
vis[S] = 1
q.append([S,0])
ans = bfs()
if vis[T] == 10**10: print(-1)
else: print(ans//3)
Problem p03105 (python)

Fixed submission:
A, B, C = map(int ,input().split())
if B / A >= C:
  print(C)
elif B/ A < C:
  print(int(B/A))

Buggy submission (verdict: Runtime Error):
if B / A >= C:
  print(C)
else:
  print(int(B/A))
Problem p03112 (python)

Fixed submission:
A,B,Q = map(int,input().split())
import bisect
s=[]
t=[]
for _ in range(A):
    s.append(int(input()))
for _ in range(B):
    t.append(int(input()))
s = [-10**20] + s + [10**20]
t = [-10**20] + t + [10**20]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = 10**20
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)

Buggy submission (verdict: Runtime Error):
A,B,q = map(int,input().split())
import bisect
L1=[]
L2=[]
for _ in range(A):
    L1.append(int(input()))
for _ in range(B):
    L2.append(int(input()))
L1 = [-10**9] + L1 + [10**9]
L2 = [-10**9] + L2 + [10**9]
for _ in range(q):
    Q = int(input())
    cand = []
    for i in range(2):
        for j in range(2):
                t =  L1[bisect.bisect_left(L1,Q)-i]
                tmp = abs (t - Q)
                tmp  +=  abs(L2[bisect.bisect_left(L2,t)-j]  - t)
                cand.append(tmp)
                t =  L2[bisect.bisect_left(L2,Q)-i]
                tmp = abs (t - Q)
                tmp  +=  abs(L1[bisect.bisect_left(L1,t)-j]  - t)
                cand.append(tmp)
    print(min(cand))