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

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
l.sort()
 
from bisect import bisect_left
ans = 0
for i in range(n):
  for j in range(i+1, n):
    t = l[i]+l[j]
    idx = bisect_left(l, t)
    ans += max(0, idx-j-1)
print(ans)

Buggy submission (verdict: Runtime Error):
# D

import itertools
n = int(input())
l = list(map(int, input().split()))
l.sort()
 
from bisect import bisect_left
ans = 0

for i, j in itertools.combinations(len(l),2):
    t = l[i]+l[j]
    idx = bisect_left(l, t)
    ans += max(0, idx-j-1)
print(ans)

Buggy submission (verdict: Runtime Error):
# D

import itertools
n = int(input())
l = list(map(int, input().split()))
l.sort()
 
from bisect import bisect_left
ans = 0

for i, j in itertools.combinations(len(n),2):
    t = l[i]+l[j]
    idx = bisect_left(l, t)
    ans += max(0, idx-j-1)
print(ans)

Buggy submission (verdict: Runtime Error):
# D

import itertools
n = int(input())
l = list(map(int, input().split()))
l.sort()
 
from bisect import bisect_left
ans = 0

for i, j in itertools.combination(len(n),2):
    t = l[i]+l[j]
    idx = bisect_left(l, t)
    ans += max(0, idx-j-1)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
l = list(map(int, input().split()))
l.sort()
 
from bisect import bisect_left
ans = 0
for i in range(n):
  for j in range(i+1, n):
    t = l[i]+l[j]
    idx = bisect_left(l, t)
    ans += max(0, idx-j-1)
print(ans)

Buggy submission (verdict: Runtime Error):
# D TLE
import bisect

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

L.sort()
value = 0


for i in range(0, len(L)-2):
    for j in range(i, len(L)-1):
    index = bisect.bisect_left(L[j+1:], L[i]+L[j])
    value+=max(0, index)

print(value)

Buggy submission (verdict: Runtime Error):
# D TLE
import bisect

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

L.sort()
value = 0


for i in range(0, len(L)-2)
    for j in range(i, len(L)-1)
    index = bisect.bisect_left(L[j+1:], L[i]+L[j])
    value+=index

print(value)

Buggy submission (verdict: Runtime Error):
# D TLE
import itertools
import bisect

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

L.sort()
value = 0

for i, j in itertools.combinations(range(len(L-1)), 2):
    index = bisect.bisect_left(L[j+1:], L[i]+L[j])
    value+=index

print(value)

Buggy submission (verdict: Runtime Error):
# D
N = map(int, input().split())
L = list(map(int, input().split()))

value = 0
for i in itertools.combinations(L, 3):
    a, b, c = i
    
    if a<b+c:
        if b<c+a:
            if c<a+b:
                value+=1
print(value)
Problem p02917 (python)

Fixed submission:
N = int(input())
B = list(map(int, input().split()))
A = [0]*(len(B)+1)

A[0] = B[0]
for i in range(len(B)):
    if A[i]>=B[i]:
        A[i]=B[i]
    A[i+1]=B[i]
print(sum(A))

Buggy submission (verdict: Runtime Error):

A = [0]*(len(B)+1)

A[0] = B[0]
for i in range(len(B)):
    if A[i]>=B[i]:
        A[i]=B[i]
    A[i+1]=B[i]
print(sum(A))
Problem p02995 (python)

Fixed submission:
#!/usr/bin/env python3

from fractions import gcd

a, b, c, d = list(map(int, input().split()))


def calc(min_, max_, div_num):
    if (min_ % div_num) != 0:
        min_ = min_ - (min_ % div_num)+div_num

    if min_ > max_:
        return 0
    return (max_-min_)//div_num+1


# print(calc(a, b, c))
# print(calc(a, b, d))
# print(calc(a, b, c*d//gcd(c, d)))
print((b-a+1)-(calc(a, b, c)+calc(a, b, d)-calc(a, b, c*d//gcd(c, d))))

Buggy submission (verdict: Runtime Error):
# C
import math

A, B, C, D = map(int, input().split())

num = B-A+1
if A%C==0:
    x=A
else:
    x = A-A%C+C
if B%C==0:
    y=B
else:
    y = B-B%C
C_multi = (y-x)//C+1
# print(x)
# print(y)
# print(C_multi)

if A%D==0:
    x=A
else:
    x = A-A%D+D
if B%D==0:
    y=B
else:
    y = B-B%D
D_multi = (y-x)//D+1
# print(x)
# print(y)
# print(D_multi)

E = C * D / math.gcd(C,D)
if A%E==0:
    x=A
else:
    x = A-A%E+E
if B%E==0:
    y=B
else:
    y = B-B%E
E_multi = (y-x)//E+1

print(int(num-C_multi-D_multi+E_multi))
Problem p03035 (python)

Fixed submission:
A, B = map(int, input().split())

if(A>=13):
    print(B)
elif(A>=6):
    print(B//2)
else:
    print("0")

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

key = np.zeros(N)
for i in range(0, M):
    L, R = map(int, input().split())
    for j in range(L, R+1):
        key[j-1]+=1

print(np.sum(key==M))
Problem p03037 (python)

Fixed submission:
#!/usr/bin/env python3

n, m = list(map(int, input().split()))

min_, max_ = 0, 10**5
for i in range(m):
    a, b = list(map(int, input().split()))

    min_ = max(min_, a)
    max_ = min(max_, b)

print(max(max_-min_+1, 0))

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

key = np.zeros(N)
for i in range(0, M):
    L, R = map(int, input().split())
    for j in range(L, R+1):
        key[j-1]+=1

print(np.sum(key==M))
Problem p03049 (python)

Fixed submission:
#問題C
N = int(input())

naka=0
a_kazu=0
b_kazu=0
b_a_kazu=0
for i in range(N):
    a = str(input())
    naka+=a.count("AB")
    if (a[0]=="B" and a[-1]=="A"):
        b_a_kazu+=1
    elif a[0]=="B":
        b_kazu+=1
    elif a[-1]=="A":
        a_kazu+=1
if b_a_kazu==0:
    print(naka+min(a_kazu, b_kazu))
else:
    if (a_kazu==0 and b_kazu==0):
        print(naka+(b_a_kazu-1))
    elif (a_kazu==0 or b_kazu==0):
        print(naka+(b_a_kazu))
    else:
        print(naka+(b_a_kazu-1)+min(a_kazu+1, b_kazu+1))

Buggy submission (verdict: Runtime Error):
#問題C
N = int(input())
s = []

naka=0
a_kazu=0
b_kazu=0
b_a_kazu=0
for i in range(N):
    a = str(input())
    naka+=a.count("AB")
    if (a[0]=="B" and a[-1]=="A"):
        b_a_kazu+=1
    elif a[0]=="B":
        b_kazu+=1
    elif a[-1]=="A":
        a_kazu+=1
if b_a_kazu==0:
    print(naka+min(a_kazu, b_kazu))
else:
    if a_kazu==0 and b_kazu==0:
        print(naka+(b_a_kazu-1))
    elif a_lazu==0 or b_kazu==0:
        print(naka+(b_a_kazu))
    else:
        print(naka+(b_a_kazu-1)+min(a_kazu+1, b_kazu+1))

Buggy submission (verdict: Runtime Error):
#問題C
N = int(input())
s = []

naka=0
a_kazu=0
b_kazu=0
b_a_kazu=0
for i in range(N):
    a = str(input())
    naka+=a.count("AB")
    if (a[0]=="B" and a[-1]=="A"):
        b_a_kazu+=1
    elif a[0]=="B":
        b_kazu+=1
    elif a[-1]=="A":
        a_kazu+=1
if b_a_kazu==0:
    print(naka+min(a_kazu, b_kazu))
else:
    if a_kazu==0 and b_kazu==0:
        print(naka+(b_a_kazu-1))
    elif a_lazu==0 or b_kazu==0:
        print(naka+(b_a_kazu))
    else:
        print()
    print(naka+(b_a_kazu-1)+min(a_kazu+1, b_kazu+1))
Problem p03161 (python)

Fixed submission:
# B(TLE) 2104ms

import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))
cost = np.zeros(N, dtype="int32")

cost[0] = 0
for i in range(1,N):
    start = 0 if i < K else i-K
    cost[i] = np.min(cost[start:i] + np.abs(h[i]-h[start:i]))

print(cost[-1])

Buggy submission (verdict: Runtime Error):
# B(TLE) 2104ms

N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))
cost = np.zeros(N, dtype="int32")

cost[0] = 0
for i in range(1,N):
    start = 0 if i < K else i-K
    cost[i] = np.min(cost[start:i] + np.abs(h[i]-h[start:i]))

print(cost[-1])

Buggy submission (verdict: Runtime Error):
# B(TLE) 2104ms

N, K = map(int, input().split())
h = np.array(list(map(int, input().split())), dtype="int32")
cost = np.zeros(N, dtype="int32")

cost[0] = 0
for i in range(1,N):
    start = 0 if i < K else i-K
    cost[i] = np.min(cost[start:i] + np.abs(h[i]-h[start:i]))

print(cost[-1])

Buggy submission (verdict: Runtime Error):
# B(TLE) 2104ms

N, K = map(int, input().split())
h = np.array(list(map(int, input().split()), dtype="int32"))
cost = np.zeros(N, dtype="int32")

cost[0] = 0
for i in range(1,N):
    start = 0 if i < K else i-K
    cost[i] = np.min(cost[start:i] + np.abs(h[i]-h[start:i]))

print(cost[-1])

Buggy submission (verdict: Runtime Error):
# B(TLE) 2104ms

N, K = map(int, input().split())
h = np.array(map(int, input().split()))
cost = np.zeros(N, dtype="int32")

cost[0] = 0
for i in range(1,N):
    start = 0 if i < K else i-K
    cost[i] = np.min(cost[start:i] + np.abs(h[i]-h[start:i]))


print(cost[-1])
Problem p03162 (python)

Fixed submission:
# C
N = int(input())
abc = [list(map(int, input().split())) for i in range(N)]

da, db, dc = 0, 0, 0

for a, b, c in abc:
    na = max(db, dc) + a
    nb = max(da, dc) + b
    nc = max(da, db) + c
    da = na
    db = nb
    dc = nc
    
print(max([na, nb, nc]))

Buggy submission (verdict: Runtime Error):
# C
N = int(input())
abc = [list(map(int, input().split())) for i in range(N)]

da, db, dc = 0, 0, 0

for a, b, c in abc:
    na = max(db, dc) + a
    na = max(da, dc) + a
    na = max(da, db) + a
    
print(max([na, nb, nc]))

Buggy submission (verdict: Runtime Error):
# C
N = int(input())
abc = [list(map(int, input().split())) for i in range(N)]

da, db, dc = 0, 0, 0

for a, b, c in abc:
    na = max(db, dc) + a
    na = max(da, dc) + a
    na = max(da, db) + a
    
print(max(na, nb, nc))
Problem p03163 (python)

Fixed submission:
# D
N, W = map(int, input().split())

import numpy as np
dp = np.zeros(W+1, dtype="int64")

for i in range(1, N+1):
    w, v = map(int, input().split())
    dp[w:] = np.maximum(dp[w:], dp[0:W-w+1] + v)

print(dp[-1])

Buggy submission (verdict: Runtime Error):
# D
N, W = map(int, input().split())
 
import numpy as np

dp = np.zeros((N+1, W+1))

for i in range(1, N+1):
    w, v = map(int, input().split())
    dp[w:W+1] = np.maximum(dp[0:W-w+1]+v, dp[w:W+1])

print(dp[-1])

Buggy submission (verdict: Runtime Error):
# D
N, W = map(int, input().split())
 
import numpy as np

dp = np.zeros((N+1, W+1))

for i in range(1, N+1):
    w, v = map(int, input().split())
    dp[w:W+1] = np.maximum(dp[0:W-w+1]+v[w:W+1], dp[w:W+1])

    print(dp[-1])

Buggy submission (verdict: Runtime Error):
# D
N, W = map(int, input().split())
 
import numpy as np

dp = np.zeros((N+1, W+1))

for i in range(1, N+1):
    w, v = map(int, input().split())
    dp[:w] = np.max(dp[0:W-w]+v[w:], dp[w:])

    print(dp[-1])

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

import numpy as np
dp = np.zeros(W+1, dtype="int64")

for i in range(1, N+1):
    w, v = map(int, input().split())
    dp[w:] = np.max(dp[w:], dp[0:W-w+1] + v)

print(dp[-1])
Problem p03210 (python)

Fixed submission:
#!/usr/bin/env python3

x = int(input())

if x == 3 or x == 5 or x == 7:
    print("YES")
else:
    print("NO")

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

a = int(input())
a, b = list(map(int, input().split()))
a = list(str(input()))
Problem p03282 (python)

Fixed submission:
#!/usr/bin/env python3

s = str(int(input()))
k = int(input())


for i in range(k):
    if s[i] != "1":
        print(s[i])
        exit()

print(s[i])

# if s[0] == "1":
#     if k == 1:
#         print(1)
#     else:
#         print(s[1])
# else:
#     print(s[0])

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

s = str(int(input()))
k = int(input())


for i in range(k):
    if s[i] != "1":
        print(s[i])
        exit()

print(s[i+1])

# if s[0] == "1":
#     if k == 1:
#         print(1)
#     else:
#         print(s[1])
# else:
#     print(s[0])

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

s = str(int(input()))
k = int(input())

# if len(s) == 1:
#     print(s)
#     exit()


if s[0] == "1":
    print(s[1])
else:
    print(s[0])
Problem p03287 (python)

Fixed submission:
#!/usr/bin/env python3

import numpy as np
from scipy.special import comb

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

a_sum = np.cumsum(a)


re_list = {}
re_list[0] = 1
for i in a_sum:
    re = i % m
    if re in re_list:
        re_list[re] += 1
    else:
        re_list[re] = 1

# print(re_list)
ans = 0
for value in re_list.values():
    ans += comb(value, 2, exact=True)

print(ans)

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

import numpy as np
from scipy.special import comb

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

a_sum = np.cumsum(a)


re_list = {}
for i in a_sum:
    re = i % m
    if re in re_list:
        re_list[re] += 1
    else:
        re_list[re] = 1
re_list[0] += 1
# print(re_list)
ans = 0
for value in re_list.values():
    ans += comb(value, 2, exact=True)

print(ans)

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

import numpy as np
from scipy.special import comb

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

a_sum = np.cumsum(a)


re_list = {}
for i in a_sum:
    re = i % m
    if re in re_list:
        re_list[re] += 1
    else:
        re_list[re] = 1
re_list[0] += 1
print(re_list)
ans = 0
for value in re_list.values():
    ans += comb(value, 2, exact=True)

print(ans)
Problem p03320 (python)

Fixed submission:
#!/usr/bin/env python3

k = int(input())

now = 1
step = 1


def sunuke(n):
    r = 0
    while n:
        r += n % 10
        n //= 10
    return r


def ok(a, b):
    return a * sunuke(b) <= b*sunuke(a)


while k:
    if ok(now, now+step):
        print(now)
        k -= 1
        now += step
    else:
        nstep = step*10
        while now % nstep != nstep-1:
            now += step
        step = nstep

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

k = int(input())

now = 1
step = 1


def sunuke(n):
    r = 0
    while n:
        r += n % 10
        n //= 10
    return r


def ok(a, b):
    return a * s(b) <= b*s(a)


while k:
    if ok(now, now+step):
        print(now)
        k -= 1
        now += step
    else:
        nstep = step*10
        while now % nstep != nstep-1:
            now += step
        step = nstep

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

k = int(input())

keta = 3

ans_c = []
sunuke = []
for i in range(1, 10**keta):  # 1~999
    a = i
    b = sum([int(j) for j in str(i)])
    tmp_sunuke = a/b
    ans_c.append(a)
    sunuke.append(tmp_sunuke)

base = 10
nines = 9
while(len(ans_c) <= 100000):
    for i in range(10**(keta-1), 10**keta):  # 1000~999
        a = i*base+nines
        b = sum([int(j) for j in str(i)])
        tmp_sunuke = a/b
        ans_c.append(a)
        sunuke.append(tmp_sunuke)
    base *= 10
    nines = nines*10 + 9
    # print(len(ans_c))

# print(ans_c)

tmp = 10**10
ans = []
for i in reversed(range(len(ans_c))):
    if sunuke[i] <= tmp:
        tmp = sunuke[i]
        ans.append(ans_c[i])
# print(ans)


for i in range(0, k):
    print(ans[-1-i])
Problem p03330 (python)

Fixed submission:
#!/usr/bin/env python3

from itertools import permutations

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

D = [list(map(int, input().split())) for i in range(C)]
# c = [list(map(int, input().split())) for i in range(N)]

colors = [[0]*C for i in range(3)]
for i in range(N):
    tmp = list(map(int, input().split()))
    for j, color in enumerate(tmp):
        num = ((i+1) + (j+1)) % 3
        colors[num][color-1] += 1
# print(colors)

data = [[0]*C for i in range(3)]


for i in range(3):
    # color[i]
    for j in range(C):
        for k in range(C):
            data[i][k] += colors[i][j] * D[j][k]
# print(data)

ans = 10**10
for iter_ in permutations(list(range(C)), 3):
    # print(iter_)
    tmp = []
    for i, j in enumerate(iter_):
        tmp.append(data[i][j])
    ans = min(ans, sum(tmp))
print(ans)

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

from itertools import product

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

D = [list(map(int, input().split())) for i in range(C)]
# c = [list(map(int, input().split())) for i in range(N)]

colors = [[0]*C for i in range(3)]
for i in range(N):
    tmp = list(map(int, input().split()))
    for j, color in enumerate(tmp):
        num = ((i+1) + (j+1)) % 3
        colors[num][color-1] += 1
# print(colors)

data = [[0]*C for i in range(3)]


for i in range(3):
    # color[i]
    for j in range(C):
        for k in range(C):
            data[i][k] += colors[i][j] * D[j][k]
# print(data)

ans = 10**10
for iter_ in product([0, 1, 2], repeat=C):
    if len(set(iter_)) != 3:
        continue
    tmp = []
    for i, j in enumerate(iter_):
        tmp.append(data[i][j])
    ans = min(ans, sum(tmp))
print(ans)
Problem p03372 (python)

Fixed submission:
#!/usr/bin/env python3

n, c = list(map(int, input().split()))

x, v = [], []
for i in range(n):
    a, b = list(map(int, input().split()))
    x.append(a)
    v.append(b)

cw = [0]*(n+1)
ccw = [0]*(n+1)
for i in range(n):
    cw[i+1] = cw[i]+v[i]
    ccw[i+1] = ccw[i]+v[-i-1]


for i in range(1, n+1):
    cw[i] -= x[i-1]
    ccw[i] -= c-x[-i]


maxcw = [0]*(n+1)
maxccw = [0]*(n+1)
for i in range(1, n+1):
    maxcw[i] = max(maxcw[i-1], cw[i])
    maxccw[i] = max(maxccw[i-1], ccw[i])

ans = max(0, maxcw[-1], maxccw[-1])

for i in range(1, n+1):
    ans = max(ans, cw[i] + maxccw[-i-1] - x[i-1])
    ans = max(ans, ccw[i] + maxcw[-i-1]-(c-x[-i]))

print(ans)

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


n, c = list(map(int, input().split()))
xv = [[0, 0]]+[list(map(int, input().split())) for i in range(n)] + [[c, 0]]
xv_rev = reversed(xv)

print(xv)
ans = 0
cal = 0
dis = 0

for i in range(1, len(xv)):
    cal += xv[i][1]
    cal -= (xv[i][0]-xv[i-1][0])
    ans = max(cal, ans)

for i in range(1, xv_rev):
    cal += xv[i][1]
    cal -= (xv[i][0]-xv[i-1][0])
    ans = max(cal, ans)

print(ans)
Problem p03402 (python)

Fixed submission:
#!/usr/bin/env python3

a, b = list(map(int, input().split()))
# print(a, b)

a -= 1
b -= 1
wide = 100

ans1 = [["#"]*wide for i in range(wide//2)]

ans2 = [["."]*wide for i in range(wide//2)]

index_x = 0
index_y = 0
while(a > 0):
    ans1[index_y][index_x] = "."
    index_x += 2
    if index_x == wide:
        index_x = 0
        index_y += 2
    a -= 1


index_x = 0
index_y = 1
a = b
while(a > 0):
    ans2[index_y][index_x] = "#"
    index_x += 2
    if index_x == wide:
        index_x = 0
        index_y += 2
    a -= 1

print(100, 100)
for i in ans1+ans2:
    print("".join(i))

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

a, b = list(map(int, input().split()))
# print(a, b)

a -= 1
b -= 1
wide = 12

ans1 = [["#"]*wide for i in range(wide//2)]

ans2 = [["."]*wide for i in range(wide//2)]

index_x = 0
index_y = 0
while(a > 0):
    ans1[index_y][index_x] = "."
    index_x += 2
    if index_x == wide:
        index_x = 0
        index_y += 2
    a -= 1


index_x = 0
index_y = 1
a = b
while(a > 0):
    ans2[index_y][index_x] = "#"
    index_x += 2
    if index_x == wide:
        index_x = 0
        index_y += 2
    a -= 1

print(100, 100)
for i in ans1+ans2:
    print("".join(i))
Problem p03409 (python)

Fixed submission:
#!/usr/bin/env python3

import networkx as nx


n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(n)]


match_list = [[] for i in range(n)]
for i in range(n):
    for j in range(n):
        a, b = ab[i]
        c, d = cd[j]

        if a < c and b < d:
            match_list[i].append(j)
# print(match_list)


group1 = range(n)
group2 = range(n, 2*n)

g = nx.Graph()
g.add_nodes_from(group1, bipartite=1)
g.add_nodes_from(group2, bipartite=0)

for i, list_ in enumerate(match_list):
    for j in list_:
        g.add_edge(i, j+n, weight=1)

# A, B = bipartite.sets(g)
# print(A, B)
# pos = dict()
# pos.update((n, (1, i)) for i, n in enumerate(A))
# pos.update((n, (2, i)) for i, n in enumerate(B))
# nx.draw_networkx(g, pos)
# nx.draw_networkx_edges(g, pos)
# plt.axis("off")
# plt.show()


d = nx.max_weight_matching(g)

print(len(d))

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

import networkx as nx
from networkx.algorithms import bipartite
import numpy as np
import itertools
import matplotlib.pyplot as plt


n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(n)]


match_list = [[] for i in range(n)]
for i in range(n):
    for j in range(n):
        a, b = ab[i]
        c, d = cd[j]

        if a < c and b < d:
            match_list[i].append(j)
# print(match_list)


group1 = range(n)
group2 = range(n, 2*n)

g = nx.Graph()
g.add_nodes_from(group1, bipartite=1)
g.add_nodes_from(group2, bipartite=0)

for i, list_ in enumerate(match_list):
    for j in list_:
        g.add_edge(i, j+n, weight=1)

# A, B = bipartite.sets(g)
# print(A, B)
# pos = dict()
# pos.update((n, (1, i)) for i, n in enumerate(A))
# pos.update((n, (2, i)) for i, n in enumerate(B))
# nx.draw_networkx(g, pos)
# nx.draw_networkx_edges(g, pos)
# plt.axis("off")
# plt.show()


d = nx.max_weight_matching(g)

print(len(d))
Problem p03450 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(200002)

n, m = list(map(int, input().split()))

graph = [[] for i in range(n)]
for i in range(m):
    l, r, d = list(map(int, input().split()))

    graph[l-1].append([r-1, d])
    graph[r-1].append([l-1, -d])
# print(graph)


def dfs(s):
    for t, d in graph[s]:
        if x[t] is None:
            x[t] = x[s]+d
            if not dfs(t):
                return False
        else:
            if x[t]-x[s] != d:
                return False
    return True


x = [None]*n
ans = True
for i in range(n):
    if x[i] is None:
        x[i] = 0
        if not dfs(i):
            ans = False

print(('No', 'Yes')[ans])

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

graph = [[] for i in range(n)]
for i in range(m):
    l, r, d = list(map(int, input().split()))

    graph[l-1].append([r-1, d])
    graph[r-1].append([l-1, -d])
# print(graph)


def dfs(s):
    for t, d in graph[s]:
        if x[t] is None:
            x[t] = x[s]+d
            if not dfs(t):
                return False
        else:
            if x[t]-x[s] != d:
                return False
    return True


x = [None]*n
ans = True
for i in range(n):
    if x[i] is None:
        x[i] = 0
        if not dfs(i):
            ans = False

print(('No', 'Yes')[ans])
Problem p03545 (python)

Fixed submission:
import itertools
A, B, C, D =  list(input())

for ops in itertools.product(["+", "-"], repeat=3):
    eq = A+ops[0]+B+ops[1]+C+ops[2]+D
    x = eval(eq)
    if x == 7:
        break
 
print(eq+'=7')

Buggy submission (verdict: Runtime Error):
S = tuple((input()))
S = [int(s) for s in S]

flag=0
for i in [0,1]:
    if flag==1:
        break
    for j in [0,1]:
        if flag==1:
            break
        for k in [0,1]:
            value = S[0]
            if i==0:
                value+=S[1]
            else:
                value-=S[1]
            if j==0:
                value+=S[2]
            else:
                value-=S[2]
            if j==0:
                value+=S[3]
            else:
                value-=S[3]
            if value==7:
                flag=1
                x = i
                y = j
                z = k
            if flag==1:
                break
if x==0:
    a = "+"
else:
    a = "-"
if y==0:
    b = "+"
else:
    b = "-"
if z==0:
    c = "+"
else:
    c = "-"

print("{}{}{}{}{}{}{}=7".format(S[0], a, S[1], b, S[2], c, S[3]))
Problem p02678 (python)

Fixed submission:
from collections import deque
n, m = map(int, input().split())
r = [[0] for i in range(n+1)]
num = {0:0, 1:1}
e = deque([]) 
for i in range(m):
	a, b = map(int, input().split())
	r[a].append(b)
	r[b].append(a)
e.append(1)
while len(e) > 0:
	x = e.popleft()
	for y in r[x]:
		if y not in num:
			num[y] = x
			e.append(y)
print("Yes")
for i in range(2, n+1):
	print(num[i])

Buggy submission (verdict: Runtime Error):
from collections import deque
n, m = map(int, input().split())
r = [[0] for i in range(n+1)]
num = {0:0, 1:1}
e = deque([]) 
for i in range(m):
	a, b = map(int, input().split())
	r[a].append(b)
	r[b].append(a)
def c(x):
	for y in r[x]:
		if y not in num:
			num[y] = x
			e.append(y)
	if len(e) > 0:
		c(e.popleft())
	else:
		return
c(1)
print("Yes")
for i in range(2, n+1):
	print(num[i])