Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a = int(input(""))
b = int(input(""))

print(str(a * b) + " " + str(2 * a + 2 * b))


Fixed submission:
a, b = map(int, input().split())

print(str(a * b) + " " + str(2 * a  + 2 * b))

Buggy python submission (verdict: Runtime Error):
a = int(input(""))
b = int(input(""))

print(str(a * b) + " " + str(2 * a + 2 * b))
print("")


Fixed submission:
a, b = map(int, input().split())

print(str(a * b) + " " + str(2 * a  + 2 * b))

Buggy python submission (verdict: Runtime Error):
a = int(input(""))
b = int(input(""))

print(str(a * b) + " " + str(2 * a + 2 * b))


Fixed submission:
a, b = map(int, input().split())

print(str(a * b) + " " + str(2 * a  + 2 * b))

Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

print(str(a * b) + " " + str(2 * a  + 2 * b))


Fixed submission:
a, b = map(int, input().split())

print(str(a * b) + " " + str(2 * a  + 2 * b))
Buggy python submission (verdict: Runtime Error):
a = int(input())
i = 0

while a != 0:
	print("Case " + i + ": " + a)
	i += 1
	a = int(input())


Fixed submission:
a = input()
i = 1

while a != "0":
	print("Case " + str(i) + ": " + a)
	i += 1
	a = input()
Buggy python submission (verdict: Runtime Error):
n = int(input())
i = 0

card_S = []
card_H = []
card_C = []
card_D = []

while i < n:
	mark, num = input().split()
	if mark == S:
		card_S.append(int(num))
	elif mark == H:
		card_H.append(int(num))
	elif mark == C:
		card_C.append(int(num))
	else:
		card_D.append(int(num))
	i += 1

i = 1
while i < 14:
	if not(i in card_S):
		print("S " + str(i))

i = 1
while i < 14:
	if not(i in card_H):
		print("H " + str(i))

i = 1
while i < 14:
	if not(i in card_C):
		print("C " + str(i))

i = 1
while i < 14:
	if not(i in card_D):
		print("D " + str(i))


Fixed submission:
n = int(input())
i = 0

card_S = []
card_H = []
card_C = []
card_D = []

while i < n:
	mark, num = input().split()
	if mark == "S":
		card_S.append(int(num))
	elif mark == "H":
		card_H.append(int(num))
	elif mark == "C":
		card_C.append(int(num))
	else:
		card_D.append(int(num))
	i += 1

i = 1
while i < 14:
	if not(i in card_S):
		print("S " + str(i))
	i += 1

i = 1
while i < 14:
	if not(i in card_H):
		print("H " + str(i))
	i += 1

i = 1
while i < 14:
	if not(i in card_C):
		print("C " + str(i))
	i += 1

i = 1
while i < 14:
	if not(i in card_D):
		print("D " + str(i))
	i += 1
Buggy python submission (verdict: Runtime Error):
w = int(input())
n = int(input())

amida = []

for i in range(0,w+1):
    amida.append(i)
    
for i in range(n):
    ai,bi = map(int,input().split())
    aa = amida[ai]
    bb = amida[bi]
    amida[ai] = bb
    amida[bi] = aa
    
for i in range(1,w+1):
    print(w[i])
    


Fixed submission:
w = int(input())
n = int(input())

amida = []

for i in range(0,w+1):
    amida.append(i)
    
for i in range(n):
    ai,bi = map(int,input().split(","))
    aa = amida[ai]
    bb = amida[bi]
    amida[ai] = bb
    amida[bi] = aa
    
for i in range(1,w+1):
    print(amida[i])
Buggy python submission (verdict: Runtime Error):
#問題2
#https://qiita.com/drken/items/a5e6fe22863b7992efdb
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B&lang=jp
n, w = map(int,input().split())
value = []
weight = []

for i in range(n):
    val,wei = map(int,input().split())
    value.append(val)
    weight.append(wei)
    
#dp i <= 110, w <= 1010
dp = []
for i in range(110):
    o = [0 for i in range(1010)]
    dp.append(o)

#i = 0 何も入れない状態を初期化する

for ww in range(w):
    dp[0][ww] = 0

for i in range(0,n):
    for ww in range(w+1):
        #dp[i+1]に最終状態が格納される
        if ww >= weight[i] :
            dp[i+1][ww] = max(dp[i][ww-weight[i]] + value[i], dp[i][ww])
        else:
            dp[i+1][ww] = dp[i][ww]
print(dp[n][w])


Fixed submission:
#問題2
#https://qiita.com/drken/items/a5e6fe22863b7992efdb
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_B&lang=jp
n, w = map(int,input().split())
value = []
weight = []

for i in range(n):
    val,wei = map(int,input().split())
    value.append(val)
    weight.append(wei)
    
#dp i <= 110, w <= 1010
dp = []
for i in range(110):
    o = [0 for i in range(10010)]
    dp.append(o)

#i = 0 何も入れない状態を初期化する

for ww in range(w):
    dp[0][ww] = 0

for i in range(0,n):
    for ww in range(w+1):
        #dp[i+1]に最終状態が格納される
        if ww >= weight[i] :
            dp[i+1][ww] = max(dp[i][ww-weight[i]] + value[i], dp[i][ww])
        else:
            dp[i+1][ww] = dp[i][ww]
print(dp[n][w])
Buggy python submission (verdict: Runtime Error):
while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    else:
        s = 0
        l = []
        for _ in range(n):
            d, p = map(int, input().split())
            s += d * p
            l.append((p,d))

        l.sort()
        while m > 0:
            a, b = l.pop()
            if m >= b:
                s -= a * b
                m -= b
            else:
                s -= a * m
                m = 0

        print(s)


Fixed submission:
while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    else:
        s = 0
        l = []
        for _ in range(n):
            d, p = map(int, input().split())
            s += d * p
            l.append((p,d))

        l.sort()
        while m > 0 and l:
            a, b = l.pop()
            if m >= b:
                s -= a * b
                m -= b
            else:
                s -= a * m
                m = 0

        print(s)

Buggy python submission (verdict: Runtime Error):
while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    else:
        s = 0
        l = []
        for _ in range(n):
            d, p = map(int, input().split())
            s += d * p
            l.append((p,d))

        l.sort()
        while m > 0:
            a, b = l.pop()
            if m >= b:
                s -= a * b
                m -= b
            else:
                s -= a * m
                m = 0

        print(s)


Fixed submission:
while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    else:
        s = 0
        l = []
        for _ in range(n):
            d, p = map(int, input().split())
            s += d * p
            l.append((p,d))

        l.sort()
        while m > 0 and l:
            a, b = l.pop()
            if m >= b:
                s -= a * b
                m -= b
            else:
                s -= a * m
                m = 0

        print(s)
Buggy python submission (verdict: Runtime Error):
m = [[0 for _ in range(n+1)] for _ in range(n+1)]
mm = [[] for _ in range(n+1)]

n = int(input())
for _ in range(n):
	tmp = [int(x) for x in input().split()]
	u,k,l = tmp[0],tmp[1],tmp[2:]
	mm[u] += tmp[2:]
	for x in l:
		m[u][x] = 1
		
dp = [float('inf') for _ in range(n+1)]
queue = [1]

while queue:
	t = queue.pop(0)
	for x in mm[t]:
		if dp[x] > dp[t] + 1:
			dp[x] = dp[t] + 1
			queue.append(x)
		else:
			pass
			
for i,x in enumerate(queue):
	if i == 0:
		pass
	else:
		if x == float('inf'):
			print(i, -1)
		else:
			print(i, x)
			

	


Fixed submission:
n = int(input())

m = [[] for _ in range(n+1)]

for _ in range(n):
	tmp = [int(x) for x in input().split()]
	u,k,l = tmp[0],tmp[1],tmp[2:]
	m[u] += tmp[2:]
		
dp = [float('inf') for _ in range(n+1)]
dp[1] = 0
queue = [1]

while queue:
	t = queue.pop(0)
	for x in m[t]:
		if dp[x] > dp[t] + 1:
			dp[x] = dp[t] + 1
			queue.append(x)
			
for i,x in enumerate(dp):
	if i == 0:
		pass
	else:
		if x == float('inf'):
			print(i, -1)
		else:
			print(i, x)
Buggy python submission (verdict: Runtime Error):
n,q = map(int, input().split())

root_list = [i for i in range(n)]

def root(x):
    path_to_root = []
    while root_list[x] != x:
        path_to_root.append(x):
        x = root_list[x]
    for node in path_to_root:
        root_list[node] = x
    return x

def is_same_set(x,y):
    return root(x) == root(y)

def unite(x,y):
    root_list[root(x)] = root(y)

for _ in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        #unite
        unite(x,y)
    else:
        if is_same_set(x,y):
            print(1)
        else:
            print(0)


Fixed submission:
n,q = map(int, input().split())

root_list = [i for i in range(n)]

def root(x):
    path_to_root = []
    while root_list[x] != x:
        path_to_root.append(x)
        x = root_list[x]
    for node in path_to_root:
        root_list[node] = x
    return x

def is_same_set(x,y):
    return root(x) == root(y)

def unite(x,y):
    root_list[root(x)] = root(y)

for _ in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        #unite
        unite(x,y)
    else:
        if is_same_set(x,y):
            print(1)
        else:
            print(0)
Buggy python submission (verdict: Time Limit Exceeded):
V,E,r = map(int, input().split())

#edges = [[float('inf') for _ in range(V)] for _ in range(V)]
edges = []

for _ in range(E):
    tmp = [int(x) for x in input().split()]
    #edges[s][t] = d
    edges.append(tmp)

d = [float('inf') for _ in range(V)]
d[r] = 0

for _ in range(V-1):
    for x in edges:
        d[x[1]] = min(d[x[1]], d[x[0]] + x[2])

for x in d:
    if x == float('inf'):
        print('INF')
    else:
        print(x)


Fixed submission:

#Bellman-FordだとTLEになる(はず)
V,E,r = map(int, input().split())
edges = []
for _ in range(E):
    tmp = [int(x) for x in input().split()]
    edges.append(tmp)

d = [float('inf') for _ in range(V)]
d[r] = 0

for _ in range(V-1):
    count = 0
    for x in edges:
        s,t,w = x
        if d[t] > d[s] + w:
            count += 1
            d[t] = d[s] + w
    if count == 0:
        break

for x in d:
    if x == float('inf'):
        print('INF')
    else:
        print(x)

Buggy python submission (verdict: Runtime Error):
V,E,r = map(int, input().split())
edges = []
for _ in range(E):
    tmp = [int(x) for x in input().split()]
    edges.append(tmp)

d = [float('inf') for _ in range(V)]
d[r] = 0

for _ in range(V-1):
    count = 0
    for x in edges:
        s,t,d = x
        if d[t] > d[s] + d:
            count += 1
            d[t] = d[s] + d
    if count == 0:
        break

for x in d:
    if x == float('inf'):
        print('INF')
    else:
        print(x)


Fixed submission:

#Bellman-FordだとTLEになる(はず)
V,E,r = map(int, input().split())
edges = []
for _ in range(E):
    tmp = [int(x) for x in input().split()]
    edges.append(tmp)

d = [float('inf') for _ in range(V)]
d[r] = 0

for _ in range(V-1):
    count = 0
    for x in edges:
        s,t,w = x
        if d[t] > d[s] + w:
            count += 1
            d[t] = d[s] + w
    if count == 0:
        break

for x in d:
    if x == float('inf'):
        print('INF')
    else:
        print(x)
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())

s = a*b
l = 2*(a+b)

return s,l


Fixed submission:
a,b = map(int,input().split())

s = a*b
l = 2*(a+b)

print(s,l)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
dic=[]
for _ in range(N):
    c,s=input().split()
    if c=="insert":
        dic.append(s)
    else:
        print("yes" if s in dic else "no")


Fixed submission:
N=int(input())
dic={}
for _ in range(N):
    c,s=input().split()
    if c=="insert":
        dic[s]=True
    else:
        print("yes" if s in dic else "no")

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
dic=[]
for _ in range(N):
    c,s=input().split()
    if c=="insert":
        dic.append(s)
    else:
        print("yes" if s in dic else "no")


Fixed submission:
N=int(input())
dic={}
for _ in range(N):
    c,s=input().split()
    if c=="insert":
        dic[s]=True
    else:
        print("yes" if s in dic else "no")

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
dic=[]
for _ in range(N):
    c,s=input().split()
    if c=="insert":
        dic.append(s)
    else:
        print("yes" if s in dic else "no")


Fixed submission:
N=int(input())
dic={}
for _ in range(N):
    c,s=input().split()
    if c=="insert":
        dic[s]=True
    else:
        print("yes" if s in dic else "no")
Buggy python submission (verdict: Runtime Error):
while True:
    N,K = map(int, input().strip().split(" "))
    X = list(map(int,input().strip().split(" ")))
    L = [X[i+1] - X[i] for i in range(0,N-1)]
    L.sort()
    print(L)
    s = 0
    for i in range(0,N-K):
        s = s + L[i]
    print(s)


Fixed submission:

# coding: utf-8

# In[23]:


#ｎは戸数
#ｋは発電機の個数
#ｘは家の座標

t = int(input()) 
for t in range(t):
    N,K = map(int, input().strip().split(" "))
    X = list(map(int,input().strip().split(" ")))
    L = [X[i+1] - X[i] for i in range(0,N-1)]
    L.sort()
    s = 0
    for i in range(0,N-K):
        s = s + L[i]
    print(s)
    
#Country Road
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2104&lang=jp
#右中央

Buggy python submission (verdict: Runtime Error):
while True:
    N,K = map(int, input().strip().split(" "))
    X = list(map(int,input().strip().split(" ")))
    L = [X[i+1] - X[i] for i in range(0,N-1)]
    L.sort()
    s = 0
    for i in range(0,N-K):
        s = s + L[i]
    print(s)


Fixed submission:

# coding: utf-8

# In[23]:


#ｎは戸数
#ｋは発電機の個数
#ｘは家の座標

t = int(input()) 
for t in range(t):
    N,K = map(int, input().strip().split(" "))
    X = list(map(int,input().strip().split(" ")))
    L = [X[i+1] - X[i] for i in range(0,N-1)]
    L.sort()
    s = 0
    for i in range(0,N-K):
        s = s + L[i]
    print(s)
    
#Country Road
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2104&lang=jp
#右中央
Buggy python submission (verdict: Runtime Error):
def ramp(t):
    if t >= 0:
        return t
    else:
        return 0
def heav(t):
    if t >= 0:
        return(1)
    else:
        return(0)

N,W = map(int,input().strip().split(" "))
lst = []
for i in range(N):
    l = list(map(int,input().strip().split(" ")))
    lst.append(l)
table = [[0 for c in range(W+1)] for i in range(N+1)]
for i in range(1,N+1):
    for c in range(1,W+1):
        table[i][c] = max(table[i-1][c],table[i-1][sgn(c-lst[i-1][1])]+lst[i-1][0]*heav(c-lst[i-1][1]))
print(table[N][W])



Fixed submission:
def ramp(t):
    if t >= 0:
        return t
    else:
        return 0
def heav(t):
    if t >= 0:
        return(1)
    else:
        return(0)
N,W = map(int,input().strip().split(" "))
lst = []
for i in range(N):
    l = list(map(int,input().strip().split(" ")))
    lst.append(l)
table = [[0 for c in range(W+1)] for i in range(N+1)]
for i in range(1,N+1):
    for c in range(1,W+1):
        table[i][c] = max(table[i-1][c],table[i-1][ramp(c-lst[i-1][1])]+lst[i-1][0]*heav(c-lst[i-1][1]))
print(table[N][W])

Buggy python submission (verdict: Runtime Error):
#引数が非負ならそのまま、負なら0を返す
def ramp(t):
    if t >= 0:
        return t
    else:
        return 0
def heav(t):
    if t >= 0:
        return(1)
    else:
        return(0)
N,W = map(int,input().strip().split(" "))
lst = []
for i in range(N):
    l = list(map(int,input().strip().split(" "))) #[v,w]の順で格納
    lst.append(l)
table = [[0 for c in range(W+1)] for i in range(N+1)]
for i in range(1,N+1):
    for c in range(1,W+1):
        table[i][c] = max(table[i-1][c],table[i-1][sgn(c-lst[i-1][1])]+lst[i-1][0]*heav(c-lst[i-1][1]))
print(table[N][W])


Fixed submission:
def ramp(t):
    if t >= 0:
        return t
    else:
        return 0
def heav(t):
    if t >= 0:
        return(1)
    else:
        return(0)
N,W = map(int,input().strip().split(" "))
lst = []
for i in range(N):
    l = list(map(int,input().strip().split(" ")))
    lst.append(l)
table = [[0 for c in range(W+1)] for i in range(N+1)]
for i in range(1,N+1):
    for c in range(1,W+1):
        table[i][c] = max(table[i-1][c],table[i-1][ramp(c-lst[i-1][1])]+lst[i-1][0]*heav(c-lst[i-1][1]))
print(table[N][W])
Buggy python submission (verdict: Runtime Error):


def dis_func(n, x, y):
    dis = [round(0, 6) for i in range(n+1)]
    for x, y in zip(x, y):
        tmp = abs(x - y)
        dis[0] += tmp
        dis[1] += (tmp ** 2)
        dis[2] += (tmp ** 3)
        dis[3] = max(dis[3], tmp)

    dis[1] = dis[1] ** (1/2)
    dis[2] = dis[2] ** (1/3)
    print('\n'.join(list(map(str, dis))))


if __name__ == '__main__':
    n = int(input())
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))

    dis_func(n, x, y)

Fixed submission:


def dis_func(x, y):
    dis = [round(0, 6) for i in range(4)]
    for x, y in zip(x, y):
        tmp = abs(x - y)
        dis[0] += tmp
        dis[1] += (tmp ** 2)
        dis[2] += (tmp ** 3)
        dis[3] = max(dis[3], tmp)

    dis[1] = dis[1] ** (1/2)
    dis[2] = dis[2] ** (1/3)
    print('\n'.join(list(map(str, dis))))


if __name__ == '__main__':
    n = int(input())
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))

    dis_func(x, y)
Buggy python submission (verdict: Runtime Error):
def func(amat, bmat, nm):
    for i in range(nm[0]):
        ans = 0
        for j in range(nm[1]):
            ans += amat[i][j] * bmat[j][0]
        print(ans)


if __name__ == '__main__':
    nm = input().split(' ')
    nm = [int(i) for i in nm]
    amat = [[0 for i in range(nm[1])] for j in range(nm[0])]
    bmat = [[0] for i in range(nm[1])]

    for i in range(nm[0]):
        a = input().split(' ')
        for j in range(nm[1]):
            amat[i][j] = int(a[j])

    for i in range(nm[1]):
        b = int(input())
        bmat[i][0] = b

    func(amat, bmat, nm)

Fixed submission:
def func(amat, bmat, nm):
    for i in range(nm[0]):
        ans = 0
        for j in range(nm[1]):
            ans += amat[i][j] * bmat[j][0]
        print(ans)


if __name__ == '__main__':
    nm = input().split(' ')
    nm = [int(i) for i in nm]
    amat = [[0 for i in range(nm[1])] for j in range(nm[0])]
    bmat = [[0] for i in range(nm[1])]

    for i in range(nm[0]):
        a = input().split(' ')
        for j in range(nm[1]):
            amat[i][j] = int(a[j])

    for i in range(nm[1]):
        b = int(input())
        bmat[i][0] = b

    func(amat, bmat, nm)
Buggy python submission (verdict: Runtime Error):
def func(amat, bmat, nm):
    ans = [[0 for i in range(nm[0])] for j in range(nm[2])]
    for i in range(nm[0]):
        for j in range(nm[1]):
            for l in range(nm[2]):
                ans[i][l] += amat[i][j] * bmat[j][l]
    for i in ans:
        print("{0} {1} {2}".format(i[0], i[1], i[2]))


if __name__ == '__main__':
    nm = [int(i) for i in input().split(' ')]
    amat = [[0 for i in range(nm[1])] for j in range(nm[0])]
    bmat = [[0 for i in range(nm[2])] for i in range(nm[1])]

    for i in range(nm[0]):
        a = input().split(' ')
        for j in range(nm[1]):
            amat[i][j] = int(a[j])

    for i in range(nm[1]):
        b = input().split(' ')
        for j in range(nm[2]):
            bmat[i][j] = int(b[j])

    func(amat, bmat, nm)

Fixed submission:
def func(amat, bmat, nm):
    ans = [[0 for i in range(nm[2])] for j in range(nm[0])]
    for i in range(nm[0]):
        for j in range(nm[1]):
            for l in range(nm[2]):
                ans[i][l] += amat[i][j] * bmat[j][l]
    for i in ans:
        print(' '.join(map(str, i)))


if __name__ == '__main__':
    nm = [int(i) for i in input().split(' ')]
    amat = [[0 for i in range(nm[1])] for j in range(nm[0])]
    bmat = [[0 for i in range(nm[2])] for i in range(nm[1])]

    for i in range(nm[0]):
        a = input().split(' ')
        for j in range(nm[1]):
            amat[i][j] = int(a[j])

    for i in range(nm[1]):
        b = input().split(' ')
        for j in range(nm[2]):
            bmat[i][j] = int(b[j])

    func(amat, bmat, nm)

Buggy python submission (verdict: Runtime Error):
def func(amat, bmat, nm):
    ans = [[0 for i in range(nm[0])] for j in range(nm[2])]
    for i in range(nm[0]):
        for j in range(nm[1]):
            for l in range(nm[2]):
                ans[i][l] += amat[i][j] * bmat[j][l]
    for i in ans:
        print(' '.join(map(str, i)))


if __name__ == '__main__':
    nm = [int(i) for i in input().split(' ')]
    amat = [[0 for i in range(nm[1])] for j in range(nm[0])]
    bmat = [[0 for i in range(nm[2])] for i in range(nm[1])]

    for i in range(nm[0]):
        a = input().split(' ')
        for j in range(nm[1]):
            amat[i][j] = int(a[j])

    for i in range(nm[1]):
        b = input().split(' ')
        for j in range(nm[2]):
            bmat[i][j] = int(b[j])

    func(amat, bmat, nm)

Fixed submission:
def func(amat, bmat, nm):
    ans = [[0 for i in range(nm[2])] for j in range(nm[0])]
    for i in range(nm[0]):
        for j in range(nm[1]):
            for l in range(nm[2]):
                ans[i][l] += amat[i][j] * bmat[j][l]
    for i in ans:
        print(' '.join(map(str, i)))


if __name__ == '__main__':
    nm = [int(i) for i in input().split(' ')]
    amat = [[0 for i in range(nm[1])] for j in range(nm[0])]
    bmat = [[0 for i in range(nm[2])] for i in range(nm[1])]

    for i in range(nm[0]):
        a = input().split(' ')
        for j in range(nm[1]):
            amat[i][j] = int(a[j])

    for i in range(nm[1]):
        b = input().split(' ')
        for j in range(nm[2]):
            bmat[i][j] = int(b[j])

    func(amat, bmat, nm)
Buggy python submission (verdict: Runtime Error):
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0117

INF = 1e12


def dijkstra(graph, source):
    lg = len(graph)
    unused = list(range(lg))
    d = [INF] * (lg)
    d[source] = 0

    while unused:
        v = min(unused, key=lambda u: d[u])
        unused.remove(v)
        for u in range(n + 1):
            d[u] = min(d[u], d[v] + graph[v][u])

    return d

n = int(input())
m = int(input())

cost = [[INF] * (n + 1) for i in range(n + 1)]
for i in range(m):
    ai, bi, ci, di = map(int, input().split(','))
    cost[ai][bi] = ci
    cost[bi][ai] = di

x1, x2, y1, y2 = map(int, input().split(','))

d_go = dijkstra(cost, x1)[x2]
d_back = dijkstra(cost, x2)[x1]

print(y1 - y2 - d_go - d_back)

Fixed submission:
INF = 1e12


def dijkstra(graph, source):
    lg = len(graph)
    unused = list(range(lg))
    d = [INF] * (lg)
    d[source] = 0

    while unused:
        v = min(unused, key=lambda u: d[u])
        unused.remove(v)
        for u in range(n + 1):
            d[u] = min(d[u], d[v] + graph[v][u])

    return d

n = int(input())
m = int(input())

cost = [[INF] * (n + 1) for i in range(n + 1)]
for i in range(m):
    ai, bi, ci, di = map(int, input().split(','))
    cost[ai][bi] = ci
    cost[bi][ai] = di

x1, x2, y1, y2 = map(int, input().split(','))

d_go = dijkstra(cost, x1)[x2]
d_back = dijkstra(cost, x2)[x1]

print(y1 - y2 - d_go - d_back)
Buggy python submission (verdict: Runtime Error):
while True:
    n, m = (int(s) for s in input().split())
    if not n:
        break

    sections = sorted(([int(s) for s in input().split()] for i in range(n)),
                      key=lambda x: x[1], reverse=True)

    for i, (d, p) in enumerate(sections):
        m -= d
        if m <= 0:
            print(sum(s[0] * s[1] for s in sections[i+1:]) - p * m)
            break
    else:
        print(0)

Fixed submission:
while True:
    n, m = (int(s) for s in input().split())
    if not n:
        break

    sections = sorted(([int(s) for s in input().split()] for i in range(n)),
                      key=lambda x: x[1], reverse=True)

    for i, (d, p) in enumerate(sections):
        m -= d
        if m <= 0:
            print(sum(s[0] * s[1] for s in sections[i+1:]) - p * m)
            break
    else:
        print(0)