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

Fixed submission:
H, W = map(int, input().split())
I = [input() for _ in range(H)]
X = [[[0, 1][a=="#"] for a in inp] for inp in I]
k = 32
def r():
    global H, W, I
    I = ["".join([I[H - 1 - j][i] for j in range(H)]) for i in range(W)]
    H, W = W, H
def st1(s):
    return int(s.replace("#", "1" * k).replace(".", "0" * k), 2)
def st2(s):
    return int(s.replace("#", "0" * (k - 1) + "1").replace(".", "0" * k), 2)
def getsum(x):
    for i in range(8):
        x += x >> (k << i)
    return x & ((1 << k) - 1)

ans = 0
for _ in range(4):
    A1 = [st1(inp) for inp in I]
    A2 = [st1("".join([I[i][j] for i in range(H)])) for j in range(W)]
    B = [st2(inp[::-1]) for i, inp in enumerate(I)]
    C = [[0] * W for _ in range(H)]
    for j in range(W):
        s = 0
        m = (1 << j * k) - 1
        for i in range(H)[::-1]:
            s <<= k
            s += B[i] >> (j+1) * k
            s &= m
            C[i][j] = s
    for i in range(1, H):
        for j in range(1, W):
            ans += A1[i] >> (W - j) * k & A2[j] >> (H - i) * k & C[i][j]
    r()
            
print(getsum(ans))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
X = [[[0, 1][a=="#"] for a in input()] for i in range(H)]
def countRD(n, i, j):
    return ccc(n, i, j, 1, 1)
def countRU(n, i, j):
    return ccc(n, i, j, -1, 1)
def countLD(n, i, j):
    return ccc(n, i, j, 1, -1)
def countLU(n, i, j):
    return ccc(n, i, j, -1, -1)
def countR(n, i, j):
    return cc(n, i, j, 0, 1)
def countL(n, i, j):
    return cc(n, i, j, 0, -1)
def countD(n, i, j):
    return cc(n, i, j, 1, 0)
def countU(n, i, j):
    return cc(n, i, j, -1, 0)
def ccc(n, i, j, DU, RL):
    c = 0
    for k in range(1, n):
        if i+k*DU >= 0 and i+k*DU < H:
            if j+(n-k)*RL >= 0 and j+(n-k)*RL < W:
                c += X[i+k*DU][j+(n-k)*RL]
    return c
def cc(n, i, j, DU, RL):
    ret = 0
    if i+n*DU >= 0 and i+n*DU < H:
        if j+n*RL >= 0 and j+n*RL < W:
            ret = X[i+n*DU][j+n*RL]
    return ret

ans = 0
for i in range(H):
    for j in range(W):
        for n in range(1, min(max(i+j,H-i+W-j), max(i+W-j,H-i+J))+2):
            if countR(n, i, j) and countD(n, i, j):
                ans += countLU(n, i, j)
            if countR(n, i, j) and countU(n, i, j):
                ans += countLD(n, i, j)
            if countL(n, i, j) and countD(n, i, j):
                ans += countRU(n, i, j)
            if countL(n, i, j) and countU(n, i, j):
                ans += countRD(n, i, j)
            if countR(n, i, j) and countD(n, i, j) and countL(n, i, j):
                ans += 1
            if countR(n, i, j) and countD(n, i, j) and countU(n, i, j):
                ans += 1
            if countR(n, i, j) and countU(n, i, j) and countL(n, i, j):
                ans += 1
            if countD(n, i, j) and countU(n, i, j) and countL(n, i, j):
                ans += 1
            
            
print (ans)
Problem p03249 (python)

Fixed submission:
def main():
    N = int(input())
    D = [int(input()) for i in range(N)]
    C = [1] * N
    T = [0] * N
    DI = {}
    for i in range(len(D)):
        DI[D[i]] = i
    D = sorted(D)
    P = [-1] * N
    while len(D) > 1:
        d = D.pop()
        i = DI[d]
        nd = d - N + C[i] * 2
        if nd in DI:
            ni = DI[nd]
        else:
            print(-1)
            return
        P[i] = ni
        C[ni] += C[i]
        T[ni] += T[i] + C[i]
    
    if D[0] == T[DI[D[0]]]:
        for i in range(N):
            if P[i] >= 0: print(i+1, P[i]+1)
    else:
        print(-1)

main()

Buggy submission (verdict: Runtime Error):
N = int(input())
D = [int(input()) for i in range(N)]
D = sorted(D)[::-1]

DtoI = {}
pD = [-1] * N
L = [1] * N
T = [0] * N

Y = {}
cnt = 0
for i in range(N):
    DtoI[D[i]] = i

for i in range(N):
    if D[i] in Y:
        for y in Y[D[i]]:
            L[i] += L[y]
            T[i] += T[y] + L[y]
            cnt += 1
        
    p = N - 2 * L[i]
    if p <= 0 or i == N-1:
        pd = -1
    else:
        pd = D[i] - p
    pD[i] = pd
    
    if pd not in Y:
        Y[pd] = []
    Y[pd].append(i)

if pD[-2] < 0:
    print(-1)
else:
    for i in range(N-1):
        print (i + 1, DtoI[pD[i]] + 1)

Buggy submission (verdict: Runtime Error):
N = int(input())
D = [int(input()) for i in range(N)]
D = sorted(D)[::-1]

for i in range(N):
    D[i] -= 0

DtoI = {}
pD = [-1] * N
L = [1] * N
T = [0] * N

Y = {}
cnt = 0
for i in range(N):
    DtoI[D[i]] = i

for i in range(N):
    if D[i] in Y:
        for y in Y[D[i]]:
            L[i] += L[y]
            T[i] += T[y] + L[y]
            cnt += 1
        
    p = N - 2 * L[i]
    if p <= 0 or i == N-1:
        pd = -1
    else:
        pd = D[i] - p
    pD[i] = pd
    
    if pd not in Y:
        Y[pd] = []
    Y[pd].append(i)

for i in range(N-1):
    print (i + 1, DtoI[pD[i]] + 1)
Problem p03260 (python)

Fixed submission:
a, b = map(int, input().split(" "))
if a % 2 == 1 and b % 2 == 1:
    print ("Yes")
else:
    print ("No")

Buggy submission (verdict: Runtime Error):
from functools import reduce

def gcd(a, b):

    if b == 0:
        return a
    else:
        return gcd(b, a % b)

def gcd_list(numbers):
    return reduce(gcd, numbers)

N, X = map(int, input().split(" "))
Xi = [int(a) for a in input().split()]

def minusX(a):
    return abs(a-X)

Xi = map(minusX, Xi)

d = gcd_list(Xi)
print (d)

Buggy submission (verdict: Runtime Error):
Print("Yes")
Problem p03261 (python)

Fixed submission:
N = int(input())
Ws = [input() for i in range(N)]

ret = "Yes"
if len(Ws) != len(list(set(Ws))):
    ret = "No"
    
for i in range(N-1):
    if Ws[i][-1] != Ws[i+1][0]:
        ret = "No"
    
    
print (ret)

Buggy submission (verdict: Runtime Error):
N = int(input())
W = [input() for i in range(N)]

if [W[i][-1] for i in range(N-1)] == [W[i+1][0] for i in range(N-1)] and len(list(set(W))) = len(W):
    print ("Yes")
else:
    print ("No")
Problem p03270 (python)

Fixed submission:
K, N = map(int, input().split())
P = 998244353
fa = [1]
for i in range(1, 10000):
    fa.append(fa[-1] * i % P)
fainv = [pow(fa[-1], P-2, P)]
for i in range(1, 10000)[::-1]:
    fainv.append(fainv[-1] * i % P)
fainv = fainv[::-1]
def C(a, b):
    if not (a >= 0 and 0 <= b <= a): return 0
    return fa[a] * fainv[a-b] * fainv[b] % P

A = []
for i in range(1, (K+1)//2+1):
    s = 0
    for j in range(i+1):
        s += C(N+K-1-2*j, K-1) * C(i, j) * (-1) ** j
        s %= P
    A.append(s)
for i in range(2*K-1):
    print(A[min(i//2, (2*K-i-2)//2)])

Buggy submission (verdict: Runtime Error):
K, N = map(int, input().split())
P = 998244353
fa = [1]
for i in range(1, 10000):
    fa.append(fa[-1] * i % P)
fainv = [pow(fa[-1], P-2, P)]
for i in range(1, 10000)[::-1]:
    fainv.append(fainv[-1] * i % P)
fainv = fainv[::-1]

def C(a, b):
    if not (a >= 0 and 0 <= b <= a): return 0
    return fa[a] * fainv[a-b] * fainv[b] % P

A = []
for i in range(1, K-2):
    s = 0
    for j in range(i+1):
        s += C(N+K-1-2*j, K-1) * C(i, j) * (-1) ** j
        s %= P
    A.append(s)
for a in A:
    print(a)
    print(a)
print(A[-1])
for a in A[::-1][1:]:
    print(a)
    print(a)
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())

for i in range(K):
    if S[i] != "1":
        print(S[i])
        break
else:
    print("1")

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())


a=0
b=0
for i in range(len(S)):
    if int(S[i]) > 1:
        a=i
        b=S[i]
        break
# print(a)
# print(b)
if K< a:
    print (S[a])
    
else:
    print (b)
    
else:
    print (b)
Problem p03284 (python)

Fixed submission:
N, K = map(int, input().split(" "))
if N % K ==0:
    print (0)
else:
    print(1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split(" "))
A = [int(a) for a in input().split()]
 
tmp=0
B=[0]
for i in A:
    tmp += A[i]
    tmp = tmp % M
    B.append(tmp)
 
B.sort()
cnt=0
ret=0
for i in range(len(B)):
    if i ==0:
        cnt += 1
        prev=B[0]
        
    else:
        if B[i] == prev:
            cnt += 1
            
        else:
            ret += int(cnt*(cnt-1)/2)
            prev = B[i]
            cnt = 1
 
ret += int(cnt*(cnt-1)/2)
 
print (ret)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split(" "))
A = [int(a) for a in input().split()]

tmp=0
B=[0]
for i in A:
    tmp += A[i]
    tmp = tmp % M
    B.append(tmp)

B.sort()
print (B)
cnt=0
ret=0
for i in range(len(B)):
    if i ==0:
        cnt += 1
        prev=B[0]
        
    else:
        if B[i] == prev:
            cnt += 1
            
        else:
            ret += int(cnt*(cnt-1)/2)
            prev = B[i]
            cnt = 1

ret += int(cnt*(cnt-1)/2)

print (ret)
Problem p03331 (python)

Fixed submission:
def sum_digit(n):
    ret = 0
    while n>0:
        ret += n % 10
        n //= 10
    return ret

N = int(input())

mi = 999999999
for a in range(1, N):
    b = N - a
    mi = min(mi, sum_digit(a)+sum_digit(b))

print(mi)

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

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
    
def mod_inv(a, mod):
    return (pow(a,mod-2,mod))

def mod_combination(n, k, mod):
    return (fact[n]*mod_inv(fact[k], mod)*mod_inv(fact[n-k], mod)) % mod

mod = 998244353
fact = [1] + [0] * n
for i in range(n):
    fact[i+1] = (fact[i] * (i+1)) % mod

ans = 0
for x in range(n+1):
    if (k-x*a) % b == 0:
        y = (k-x*a)//b
        if y >= 0:
            ans += mod_combination(n, x, mod) * mod_combination(n, y, mod)
            ans %= mod

    
print(ans)

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

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
    
def mod_inv(a, mod):
    return (pow(a,mod-2,mod))

def mod_combination(n, k, mod):
    return (fact[n]*mod_inv(fact[k], mod)*mod_inv(fact[n-k], mod)) % mod

g = gcd(k, gcd(a, b))
a //= g
b //= g
k //= g

mod = 998244353
fact = [1] + [0] * n
for i in range(n):
    fact[i+1] = (fact[i] * (i+1)) % mod
if a < b:
    tmp = a
    a = b
    b = tmp

ans = 0
for x in range(n+1):
    if (k-x*a) % b == 0:
        y = (k-x*a)//b
        if y >= 0:
            ans += mod_combination(n, x, mod) * mod_combination(n, y, mod)
            ans %= mod

    
print(ans)

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

if False:
    n = 4
    a = 1
    b = 2
    k = 5

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
    
def mod_inv(a, mod):
    return (pow(a,mod-2,mod))

def mod_combination(n, k, mod):
    return fact[n]*mod_inv(fact[k], mod)*mod_inv(fact[n-k], mod) % mod

mod = 998244353
fact = [1] + [0] * n
for i in range(n):
    fact[i+1] = (fact[i] * (i+1)) % mod
# print(fact)
if a < b:
    tmp = a
    a = b
    b = tmp

ans = 0
# print("n, a, b =", n, a, b)
# print((k-b*n)//a, k//a+1)
for x in range(max(-int(-(k-b*n)//a),0), k//a+1):
    if (k-x*a) % b == 0:
        y = (k-x*a)//b
        
        # print("n, x, y, mod", n, x, y, mod)
        # print(mod_combination(n, x, mod))
        # print(mod_combination(n, y, mod))
        
        ans += mod_combination(n, x, mod) * mod_combination(n, y, mod)
        ans %= mod
    
print(ans)
Problem p03351 (python)

Fixed submission:
a, b, c, d = map(int, input().split())
if abs(a-c) <= d or (abs(a-b)<= d and abs(b-c)<=d):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int().input())
if abs(a-c) <= d or (abs(a-b)<= d and abs(b-c)<=d):
  print("Yes")
else:
  print("No")
Problem p03377 (python)

Fixed submission:
a,b,x=map(int,input().split());print("YNEOS"[x-a not in range(b+1)::2])

Buggy submission (verdict: Runtime Error):
f
Problem p03480 (python)

Fixed submission:
s = input()
t = s[len(s)//2]
j = len(s)//2
i = len(s)-j-1
ans = j
while i >= 0:
    if s[i] != t or s[j] != t:
        break
    ans += 1
    i -= 1
    j += 1

print(ans)

Buggy submission (verdict: Runtime Error):
 = input()
t = s[len(s)//2]
j = len(s)//2
i = len(s)-j-1
ans = j
while i >= 0:
    if s[i] != t or s[j] != t:
        break
    ans += 1
    i -= 1
    j += 1

print(ans)
Problem p03487 (python)

Fixed submission:
from collections import Counter as C
N = int(input())
A = [int(a) for a in input().split()]
X = C(A)
ans = 0
for x in X:
    ans += X[x] if X[x] < x else X[x] - x
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import counter as C
print(9)
Problem p03494 (python)

Fixed submission:
N = int(input())
def calc(n):
    if n % 2:
        return 0
    else:
        return calc(n//2) + 1

A = [int(a) for a in input().split()]
mi = 9999
for a in A:
    mi = min(mi, calc(a))
print(mi)

Buggy submission (verdict: Runtime Error):
N = int(input())
def calc(n):
    if n % 2:
        return 0
    else:
        return a(n//2) + 1

A = [int(a) for a in input().split()]
mi = 9999
for a in A:
    mi = min(mi, calc(a))
print(a)
Problem p03578 (python)

Fixed submission:
input()
D = {}
for a in [int(a) for a in input().split()]:
    if a not in D: D[a] = 0
    D[a] += 1

input()
for a in [int(a) for a in input().split()]:
    if a not in D: D[a] = 0
    D[a] -= 1

for a in D:
    if D[a] < 0:
        print("NO")
        break
else:
    print("YES")

Buggy submission (verdict: Runtime Error):
input()
D = {}
for a in [int(a) for a in input().split()]:
    if a not in D: D[i] = 0
    D[a] += 1

input()
for a in [int(a) for a in input().split()]:
    if a not in D: D[i] = 0
    D[a] -= 1

for a in D:
    if D[a] < 0:
        print("NO")
        break
else:
    print("YES")

Buggy submission (verdict: Runtime Error):
input()
D = {}
for a in [int(a) for a in input().split()]:
    if a not in D: D[i] = 0
    D[i] += 1

input()
for a in [int(a) for a in input().split()]:
    if a not in D: D[i] = 0
    D[i] -= 1

for a in D:
    if D[a] < 0:
        print("NO")
        break
else:
    print("YES")
Problem p03585 (python)

Fixed submission:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    f = 1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l+r) / 2 if f else (l * rc + r * lc) / (lc + rc)
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**40)<<16)+i for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = (c - N*(N-1)//4) * 2
        else:
            r = m
            rc = (N*(N-1)//4 - c) * 2 + 1
        f ^= 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Buggy submission (verdict: Runtime Error):
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<32, 1<<32, N*(N-1)//4, N*(N-1)//4
    f = 1
    while r - l > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**40)<<16)+i for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = c - N*(N-1)//4
        else:
            r = m
            rc = max(N*(N-1)//4 - c, 1)
        
        f ^= 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))
Problem p03646 (python)

Fixed submission:
K = int(input())
N = 50
s = N * (N-1) // 2
a = K // N
b = K % N
A = [a + i + (1 if i >= N-b else 0) for i in range(N)]
print(len(A))
print(*A)

Buggy submission (verdict: Runtime Error):
K = int(input())
N = 50
s = N * (N-1) // 2
A = [a + i + (1 if i >= N-b else 0) for i in range(N)]
print(N)
print(*A)
Problem p03677 (python)

Fixed submission:
from itertools import accumulate
def acc(X): return list(accumulate(X))

N, M = map(int, input().split())
A = [int(a)-1 for a in input().split()]

X = [0] * M # 1,1,1,...
Y = [0] * M # 1,2,3,...

def tri(l, r, a = 1):
    if l < M:
        Y[l] += a
    if r + 1 < M:
        Y[r+1] -= a
        X[r+1] -= (r-l+1) * a

def box(l, r, a = 1):
    if l < M:
        X[l] += a
    if r + 1< M:
        X[r+1] -= a
    
def calc(a, b):
    if a <= b - 2:
        tri(a+2, b)
    elif a > b and a <= b + M - 2:
        tri(a+2, M-1)
        tri(0, b)
        box(0, b, -a+M-2)
        
    # print(a, b, X, Y, rev())

def rev():
    ret = acc(Y)
    ret = [X[i] + ret[i] for i in range(M)]
    return acc(ret)
    
ans = 0
for i in range(1, N):
    ans += (A[i] - A[i-1]) % M
    calc(A[i-1], A[i])

X = rev()
# print(X)
ans -= max(X)
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
def acc(X): return list(accumulate(X))

N, M = map(int, input().split())
A = [int(a)-1 for a in input().split()]

X = [0] * M # 1,1,1,...
Y = [0] * M # 1,2,3,...

def tri(l, r, a = 1):
    if l < M:
        Y[l] += a
    if r + 1 < M:
        Y[r+1] -= a
        X[r+1] -= (r-l+1) * a

def box(l, r, a = 1):
    if l < M:
        X[l] += a
    if r + 1< M:
        X[r+1] -= a
    
def calc(a, b):
    if a <= b - 2:
        tri(a+2, b)
    elif a > b and a <= b + M - 2:
        tri(a+1, M-1)
        tri(0, b)
        box(0, b, b-a-1)

ans = 0
for i in range(1, N):
    ans += (A[i] - A[i-1]) % M
    calc(A[i-1], A[i])

Y = acc(Y)
X = [X[i] + Y[i] for i in range(N)]
X = acc(X)

ans -= max(X)
print(ans)
Problem p03682 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

def MST(n, E):
    def par(m):
        if UF[m] == m:
            return m
        ret = par(UF[m])
        UF[m] = ret
        return ret
    
    UF = [i for i in range(n)]
    E = sorted(E, key=lambda x: x[2])
    ans = 0
    for i, j, d in E:
        if par(i) != par(j):
            ans += d
            UF[par(i)] = par(j)
    return ans

N = int(input())

X = []
for i in range(N):
    x, y = map(int, input().split())
    X.append((i, x, y))

F = []
Y = sorted(X, key = lambda x: x[1])
for i in range(len(Y)-1):
    F.append((Y[i][0], Y[i+1][0], abs(Y[i+1][1]-Y[i][1])))

Y = sorted(X, key = lambda x: x[2])
for i in range(len(Y)-1):
    F.append((Y[i][0], Y[i+1][0], abs(Y[i+1][2]-Y[i][2])))

print(MST(N, F))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

def MST(n, E):
    def par(m):
        if UF[m] == m:
            return m
        ret = par(UF[m])
        UF[m] = ret
        return ret
    
    UF = [i for i in range(n)]
    E = sorted(E, key=lambda x: x[2])
    ans = 0
    for i, j, d in E:
        if par(i) != par(j):
            ans += d
            UF[par(i)] = par(j)
    return ans

N = int(input())

X = []
for i in range(N):
    x, y = map(int, input().split())
    X.append((i, x, y))

F = []
Y = sorted(X, key = lambda x: x[1])
for i in range(len(Y)-1):
    F.append((Y[i][0], Y[i+1][0], abs(Y[i+1][1]-Y[i][1])))

Y = sorted(X, key = lambda x: x[2])
for i in range(len(Y)-1):
    F.append((Y[i][0], Y[i+1][0], abs(Y[i+1][2]-Y[i][2])))

print(MST(N, F))

Buggy submission (verdict: Runtime Error):
def MST(n, E):
    def par(m):
        if UF[m] == m:
            return m
        ret = par(UF[m])
        UF[m] = ret
        return ret
    
    UF = [i for i in range(n)]
    E = sorted(E, key=lambda x: x[2])
    ans = 0
    for i, j, d in E:
        if par(i) != par(j):
            ans += d
            UF[par(i)] = par(j)
    return ans

N = int(input())

X = []
for i in range(N):
    x, y = map(int, input().split())
    X.append((i, x, y))

F = []
Y = sorted(X, key = lambda x: x[1])
for i in range(len(Y)-1):
    F.append((Y[i][0], Y[i+1][0], abs(Y[i+1][1]-Y[i][1])))

Y = sorted(X, key = lambda x: x[2])
for i in range(len(Y)-1):
    F.append((Y[i][0], Y[i+1][0], abs(Y[i+1][2]-Y[i][2])))

print(MST(N, F))
Problem p03784 (python)

Fixed submission:
A, B = map(int, input().split())
N = A + B
X = [i for i in range(N)]
Y = []
def chk(a, b):
    print("?", a, b)
    return 1 if input() == "Y" else 0
if A <= B:
    print("Impossible")
else:
    while X:
        if not Y:
            Y.append(X.pop())
        else:
            if chk(Y[-1], X[-1]):
                Y.append(X.pop())
            else:
                X.pop()
                Y.pop()
    print("!", "".join([str(chk(Y[-1], i)) for i in range(N)]))

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
X = [i for i in range(N)]
Y = []
def chk(a, b):
    print("?", a, b)
    return 1 if input() == "Y" else 0
while X:
    if not Y:
        Y.append(X.pop())
    else:
        if chk(Y[-1], X[-1]):
            Y.append(X.pop())
        else:
            Y.pop()
print("!", "".join([str(chk(Y[-1], i)) for i in range(N)]))
Problem p03819 (python)

Fixed submission:
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
NN = (M + 10).bit_length()
BIT=[0]*(2**NN+1)

def addrange(l0, r0, x=1):
    l, r = l0, r0
    while l <= 2**NN:
        BIT[l] += x
        l += l & (-l)
    while r <= 2**NN:
        BIT[r] -= x
        r += r & (-r)
def getvalue(r):
    a = 0
    while r != 0:
        a += BIT[r]
        r -= r&(-r)
    return a

X = []
for _ in range(N):
    l, r = map(int, input().split())
    X.append((l, r+1))

X = sorted(X, key = lambda x: -(x[1]-x[0]))
for d in range(1, M+1):
    while X and X[-1][1] - X[-1][0] < d:
        l, r = X.pop()
        addrange(l, r)
    ans = len(X)
    for i in range(d, M+1, d):
        ans += getvalue(i)
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
NN = (M + 10).bit_length() - 1
BIT=[0]*(2**NN+1)

def addrange(l0, r0, x=1):
    l, r = l0, r0
    while l <= 2**NN:
        BIT[l] += x
        l += l & (-l)
    while r <= 2**NN:
        BIT[r] -= x
        r += r & (-r)
def getvalue(r):
    a = 0
    while r != 0:
        a += BIT[r]
        r -= r&(-r)
    return a

X = []
for _ in range(N):
    l, r = map(int, input().split())
    X.append((l, r+1))

X = sorted(X, key = lambda x: -(x[1]-x[0]))
for d in range(1, M+1):
    while X and X[-1][1] - X[-1][0] < d:
        l, r = X.pop()
        addrange(l, r)
    ans = len(X)
    for i in range(d, M+1, d):
        ans += getvalue(i)
    print(ans)
Problem p03838 (python)

Fixed submission:
X, Y = map(int, input().split())
if X * Y > 0:
    if X <= Y: print(Y-X)
    else: print(X-Y+2)
elif X == 0:
    print(Y if Y >= 0 else -Y+1)
elif Y == 0:
    print(-X if X <= 0 else X+1)
else:
    mi = abs(abs(Y)-abs(X))+1
    if X <= Y:
        mi = min(mi, Y-X)
    print(mi)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split())
if X * Y >= 0:
    if X <= Y: print(Y-X)
    else: print(X-Y+2)
else: print(max(abs(Y)+abs(X))+1)
Problem p03853 (python)

Fixed submission:
H, W = map(int, input().split())
for i in range(H):
    s = input()
    print(s)
    print(s)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
for i in range(W):
    s = input()
    print(s)
    print(s)
Problem p03909 (python)

Fixed submission:
H, W = map(int, input().split())
for i in range(H):
    S = input().split()
    for j in range(W):
        if S[j] == "snuke":
            print(chr(65+j) + str(i+1))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
for i in range(H):
    S = input(split())
    for j in range(W):
        if S[j] == "snuke":
            print(chr(65+j) + str(i+1))
Problem p03997 (python)

Fixed submission:
A, B, H = [int(input()) for _ in range(3)]
print((A+B)*H//2)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = [1 if a == "I" else -1 for a in input()]
ma = 0
a = 0
for i in range(N):
    a += S[i]
    ma = max(ma, a)
print(ma)