Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(10 ** 8)

A = input()
B = input()

class Source():
  def __init__(self, S):
    self.S = S
    self.pos = 0
   
  
def peek(S):
  return S.S[S.pos] if S.pos < len(S.S) else -1

def next(S):
  print(S.S[S.pos], end='')
  S.pos += 1
  
def tree(S):
  next(S)
  if peek(S) == ')':
    next(S)
    return -1
  left = tree(S)
  center = root(S)
  right = tree(S)
  next(S)
  
def root(S):
  res = 0
  next(S)
  while peek(S) != ']':
    res += res * 10 + int(peek(S))
    next(S)
  next(S)
  
  return res
  
tree(Source('(' + A + ')'))
  

Fixed submission:
p, q, r = [int(i) for i in input().split()]

print(min(p + q, q + r, r + p))
Buggy python submission (verdict: Runtime Error):
q = int(input())
Q = [[int(i) for i in input().split()] for j in range(q)]
p = 10 ** 6 + 3

def fact(n, p=10**9 + 7):
    f = [1]
    for i in range(1, n+1):
        f.append(f[-1]*i%p)
    return f

def invfact(n, f, p=10**9 + 7):
    inv = [pow(f[n], p-2, p)]
    for i in range(n, 0, -1):
        inv.append(inv[-1]*i%p)
    return inv[::-1]

f = fact(p - 1, p)
invf = invfact(p - 1, f, p)

for x, d, n in Q:
    if n >= p or x == 0:
        print(0)
        continue
    if d == 0:
        print(pow(x, n, p))
        continue
    
    inv_d = pow(d, p - 2, p)
    d_n = pow(d, n, p)
    x_over_d = x * inv_d % p

    if x_over_d + n - 1 >= p:
        print(0)
        continue

    print(d_n * f[x_over_d + n - 1] * invf[x_over_d - 1] % p)

Fixed submission:
n = int(input())
print(180 * (n - 2))
Buggy python submission (verdict: Runtime Error):
n = int(input())
U = [[int(i) for i in input().split()] for j in range(n - 1)]

E = [[] for i in range(n + 1)]

for u, v, w in U:
    E[u].append((v, w))
    E[v].append((u, w))

visited = [False] * (n + 1)
color = [0] * (n + 1)

def dfs(v, w):
    if visited[v]:
        return None
    visited[v] = True
    color[v] = 1 if w % 2 == 1 else 0
    for u, weight in E[v]:
        dfs(u, w + weight)

    return None

dfs(1, 0)

for c in color[1:]:
    print(c)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n = int(input())
U = [[int(i) for i in input().split()] for j in range(n - 1)]

E = [[] for i in range(n + 1)]

for u, v, w in U:
    E[u].append((v, w))
    E[v].append((u, w))

visited = [False] * (n + 1)
color = [0] * (n + 1)

def dfs(v, w):
    if visited[v]:
        return None
    visited[v] = True
    color[v] = 1 if w % 2 == 1 else 0
    for u, weight in E[v]:
        dfs(u, w + weight)

    return None

dfs(1, 0)

for c in color[1:]:
    print(c)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H, W = [int(i) for i in input().split()]
A = [[i for i in input()] for j in range(H)]

q = deque()
for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            q.append((h, w))

dh = [1, -1, 0, 0]
dw = [0, 0, 1, -1]
ans = 0

while len(q):
    ans += 1
    n = len(q)
    for i in range(n):
        h, w = q.pop()
        for j in range(4):
            nh = h + dh[j]
            nw = w + dw[j]
            if nh >= H or nh < 0 or nw >= W or nw < 0:
                continue
            if A[nh][nw] == '.':
                A[nh][nw] = '#'
                q.append((nh, nw))

print(ans - 1)

Fixed submission:
from collections import deque

H, W = [int(i) for i in input().split()]
A = [[i for i in input()] for j in range(H)]

q = deque()
for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            q.append((h, w))

dh = [1, -1, 0, 0]
dw = [0, 0, 1, -1]
ans = 0

while len(q):
    ans += 1
    n = len(q)
    for i in range(n):
        h, w = q.popleft()
        for j in range(4):
            nh = h + dh[j]
            nw = w + dw[j]
            if nh >= H or nh < 0 or nw >= W or nw < 0:
                continue
            if A[nh][nw] == '.':
                A[nh][nw] = '#'
                q.append((nh, nw))

print(ans - 1)
Buggy python submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
S = input()
Q = [[i for i in input().split()] for j in range(m)]

l = 0
r = n - 1

for t, d in Q[::-1]:
    if d == 'L' and t == S[l]:
        l += 1
    if d == 'R' and t == S[r]:
        r -= 1

print(r - l + 1)

Fixed submission:
n, m = [int(i) for i in input().split()]
S = input()
Q = [[i for i in input().split()] for j in range(m)]

def solve(i):
    cur = i
    for t, d in Q:
        if S[cur] == t:
            cur += 1 if d == 'R' else -1
        if cur < 0 or cur >= n:
            return False
    return True

def b_search(ok, ng):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if solve(mid):
            ok = mid
        else:
            ng = mid
    return ok

print(max(0, b_search(-1, n) - b_search(n, -1) + 1))
Buggy python submission (verdict: Time Limit Exceeded):
n, x = [int(i) for i in input().split()]
S = [int(i) for i in input().split()]
DP = [[0] * (x + 1) for i in range(n + 1)]
DP[0][x] = 1
p = 10 ** 9 + 7
S.sort(reverse=True)

for i in range(n):
    for j in range(x + 1):
        if i != n - 1:
            DP[i + 1][j] += DP[i][j] * (n - i - 1)
        DP[i + 1][j % S[i]] += DP[i][j]

print(sum(i * d % p for i, d in enumerate(DP[n])) % p)

Fixed submission:
n, x = [int(i) for i in input().split()]
S = [int(i) for i in input().split()]
DP = [[0] * (x + 1) for i in range(n + 1)]
DP[0][x] = 1
p = 10 ** 9 + 7
S.sort(reverse=True)

for i in range(n):
    for j in range(x + 1):
        DP[i][j] %= p
        if i != n - 1:
            DP[i + 1][j] += DP[i][j] * (n - i - 1)
        DP[i + 1][j % S[i]] += DP[i][j]

print(sum(i * d % p for i, d in enumerate(DP[n])) % p)

Buggy python submission (verdict: Time Limit Exceeded):
n, x = [int(i) for i in input().split()]
S = [int(i) for i in input().split()]
DP = [[0] * (x + 1) for i in range(n + 1)]
DP[0][x] = 1
p = 10 ** 9 + 7
S.sort(reverse=True)

for i in range(n):
    for j in range(x + 1):
        if i != n - 1:
            DP[i + 1][j] += DP[i][j] * (n - i - 1)
        DP[i + 1][j % S[i]] += DP[i][j]

print(sum(i * d % p for i, d in enumerate(DP[n])) % p)

Fixed submission:
n, x = [int(i) for i in input().split()]
S = [int(i) for i in input().split()]
DP = [[0] * (x + 1) for i in range(n + 1)]
DP[0][x] = 1
p = 10 ** 9 + 7
S.sort(reverse=True)

for i in range(n):
    for j in range(x + 1):
        DP[i][j] %= p
        if i != n - 1:
            DP[i + 1][j] += DP[i][j] * (n - i - 1)
        DP[i + 1][j % S[i]] += DP[i][j]

print(sum(i * d % p for i, d in enumerate(DP[n])) % p)
Buggy python submission (verdict: Runtime Error):
b, w = [int(i) for i in input().split()]
p = 10 ** 9 + 7

def fact(n, p=10**9 + 7):
    f = [1]
    for i in range(1, n+1):
        f.append(f[-1]*i%p)
    return f

def invfact(n, f, p=10**9 + 7):
    inv = [pow(f[n], p-2, p)]
    for i in range(n, 0, -1):
        inv.append(inv[-1]*i%p)
    return inv[::-1]

def get_inv(n, p=10**9 + 7):
    inv = [0, 1]
    for i in range(2, n+1):
        inv.append(-(p//i * inv[p%i]) % p)
    return inv

f = fact(10 ** 5)
invf = invfact(10 ** 5, f)

def comb(a, b):
    if a < b:
        return 0
    return f[a] * invf[b] * invf[a-b] % p

P = [[0] * 2 for i in range(b + w + 1)]
B = 0
W = 1
inv_2 = invf[2]

for i in range(1, b + w + 1):
    P[i][B] = P[i - 1][B] + comb(i - 1, b - 1) * inv_2  #i番目になくなってる確率
    P[i][W] = P[i - 1][W] + comb(i - 1, w - 1) * inv_2
    inv_2 = inv_2 * invf[2] % p 
    print((1 - P[i - 1][B] + P[i - 1][W]) * invf[2] % p)


Fixed submission:
b, w = [int(i) for i in input().split()]
p = 10 ** 9 + 7

def fact(n, p=10**9 + 7):
    f = [1]
    for i in range(1, n+1):
        f.append(f[-1]*i%p)
    return f

def invfact(n, f, p=10**9 + 7):
    inv = [pow(f[n], p-2, p)]
    for i in range(n, 0, -1):
        inv.append(inv[-1]*i%p)
    return inv[::-1]

def get_inv(n, p=10**9 + 7):
    inv = [0, 1]
    for i in range(2, n+1):
        inv.append(-(p//i * inv[p%i]) % p)
    return inv

f = fact(b + w + 1)
invf = invfact(b + w + 1, f)

def comb(a, b):
    if a < b:
        return 0
    return f[a] * invf[b] * invf[a-b] % p

P = [[0] * 2 for i in range(b + w + 1)]
B = 0
W = 1
inv_2 = invf[2]

for i in range(1, b + w + 1):
    P[i][B] = P[i - 1][B] + comb(i - 1, b - 1) * inv_2  #i番目になくなってる確率
    P[i][W] = P[i - 1][W] + comb(i - 1, w - 1) * inv_2
    inv_2 = inv_2 * invf[2] % p 
    print((1 - P[i - 1][B] + P[i - 1][W]) * invf[2] % p)
Buggy python submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
E = [[] for i in range(n+1)]
used = [False] * (n + 1)
IN = [0] * (n + 1)

for i in range(m):
    a, b = [int(i) for i in input().split()]
    E[a].append(b)
    E[b].append(a)
    IN[a] += 1
    IN[b] += 1

cnt_4 = 0
cnt_6 = 0
for i in IN[1:]:
    if i % 2 == 1 or i == 0:
        print('No')
        exit()
    if i >= 4:
        cnt_4 += 1
    if i >= 6:
        cnt_6 += 1

if cnt_4 >= 2 or cnt_6 >= 1:
    print('Yes')
else:
    print('No')


Fixed submission:
#後ろにある数字を消していく

n = int(input())
B = [int(i) for i in input().split()]

ans = []

while len(B) > 0:
    for i in range(len(B) - 1, -1, -1):
        if B[i] == i + 1:
            ans.append(i + 1)
            del B[i]
            break
    else:
        print(-1)
        exit()

print(*ans[::-1], sep='\n')
Buggy python submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n, m = [int(i) for i in input().split()]
E = [[] for i in range(n+1)]
used = [False] * (n + 1)
IN = [0] * (n + 1)

for i in range(m):
    a, b = [int(i) for i in input().split()]
    E[a].append(b)
    E[b].append(a)
    IN[a] += 1
    IN[b] += 1

cnt_4 = 0
cnt_6 = 0
v_4 = []
for j, i in enumerate(IN[1:]):
    if i % 2 == 1 or i == 0:
        print('No')
        exit()
    if i >= 4:
        cnt_4 += 1
        v_4.append(j + 1)
    if i >= 6:
        cnt_6 += 1

def dfs(p, v):
    if v == v_4[0]:
        return v_4[0]
    if v == v_4[1]:
        return v_4[1]

    for e in E[v]:
        if e == p:
            continue
        return dfs(v, e)

if cnt_4 > 2 or cnt_6 >= 1:
    print('Yes')
elif cnt_4 == 2:
    if all(dfs(v_4[0], e) == v_4[1] for e in E[v_4]):
        print('No')
    else:
        print('Yes')

else:
    print('No')


Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n, m = [int(i) for i in input().split()]
E = [[] for i in range(n+1)]
used = [False] * (n + 1)
IN = [0] * (n + 1)

for i in range(m):
    a, b = [int(i) for i in input().split()]
    E[a].append(b)
    E[b].append(a)
    IN[a] += 1
    IN[b] += 1

cnt_4 = 0
cnt_6 = 0
v_4 = []
for j, i in enumerate(IN[1:]):
    if i % 2 == 1 or i == 0:
        print('No')
        exit()
    if i >= 4:
        cnt_4 += 1
        v_4.append(j + 1)
    if i >= 6:
        cnt_6 += 1

def dfs(p, v):
    if v == v_4[0]:
        return v_4[0]
    if v == v_4[1]:
        return v_4[1]

    for e in E[v]:
        if e == p:
            continue
        return dfs(v, e)

if cnt_4 > 2 or cnt_6 >= 1:
    print('Yes')
elif cnt_4 == 2:
    if all(dfs(v_4[0], e) == v_4[1] for e in E[v_4[0]]):
        print('No')
    else:
        print('Yes')

else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
C = [0] + [int(input()) for i in range(n)]
p = 10 ** 9 + 7

DP = [0] * (n + 1)
last = [0] * (n + 1)
DP[0] = 1

for i in range(n):
    if C[i + 1] == C[i]:
        DP[i + 1] = DP[i] % p
    else:
        DP[i + 1] = (DP[i] + last[C[i + 1]]) % p
    last[C[i + 1]] = DP[i + 1]

print(DP[n])

Fixed submission:
n = int(input())
C = [0] + [int(input()) for i in range(n)]
p = 10 ** 9 + 7

DP = [0] * (n + 1)
last = [0] * int(2e5 + 1)
DP[0] = 1

for i in range(n):
    if C[i + 1] == C[i]:
        DP[i + 1] = DP[i] % p
    else:
        DP[i + 1] = (DP[i] + last[C[i + 1]]) % p
    last[C[i + 1]] = DP[i + 1]

print(DP[n])
Buggy python submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n, a, b = [int(i) for i in input().split()]

if (a ^ b) % 2 == 1 and (a ^ b) != 1:
    print('NO')
    exit()

def dfs(i, a):
    if i == 1:
        return [a & 1, ~a & 1]
    res = dfs(i - 1)
    if a & ((1 << i) - 1) != res[0]:
        res.reverse()
    return [(a & (1 << (i - 1))) + r for r in res] + [((~a) & (1 << (i - 1))) + r for r in res[::-1]]

ans = [(1 << (n - 1)) + r for r in dfs(n - 1, b)[::-1]] + [r for r in dfs(n - 1, a)]
index = ans.index(a)
print('YES')
print(*(ans[index:] + ans[:index]))

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n, a, b = [int(i) for i in input().split()]

if bin(a ^ b).count('1') % 2 == 0:
    print('NO')
    exit()

def dfs(i, a, b):
    if i == 1:
        return [a, b]
    d = (a ^ b) & -(a ^ b)
    ad = ((a & (~d ^ d - 1)) >> 1) + (a & d - 1)
    bd = ((b & (~d ^ d - 1)) >> 1) + (b & d - 1)
    c = ad ^ 1

    res1 = dfs(i - 1, ad, c)
    res2 = dfs(i - 1, bd, c)
    ans1 = [((r & ~(d - 1)) << 1) + (r & d - 1) + (d & a) for r in res1]
    ans2 = [((r & ~(d - 1)) << 1) + (r & d - 1) + (d & b) for r in res2[::-1]]
    return ans1 + ans2

print('YES')
print(*dfs(n, a, b))

Buggy python submission (verdict: Runtime Error):
n, a, b = [int(i) for i in input().split()]

if (a ^ b) % 2 == 1 and (a ^ b) != 1:
    print('NO')
    exit()

def dfs(i, a):
    if i == 1:
        return [a & 1, ~a & 1]
    res = dfs(i - 1)
    if a & ((1 << i) - 1) != res[0]:
        res.reverse()
    return [(a & (1 << (i - 1))) + r for r in res] + [((~a) & (1 << (i - 1))) + r for r in res[::-1]]

ans = [(1 << (n - 1)) + r for r in dfs(n - 1, b)[::-1]] + [r for r in dfs(n - 1, a)]
index = ans.index(a)
print('YES')
print(*(ans[index:] + ans[:index]))

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n, a, b = [int(i) for i in input().split()]

if bin(a ^ b).count('1') % 2 == 0:
    print('NO')
    exit()

def dfs(i, a, b):
    if i == 1:
        return [a, b]
    d = (a ^ b) & -(a ^ b)
    ad = ((a & (~d ^ d - 1)) >> 1) + (a & d - 1)
    bd = ((b & (~d ^ d - 1)) >> 1) + (b & d - 1)
    c = ad ^ 1

    res1 = dfs(i - 1, ad, c)
    res2 = dfs(i - 1, bd, c)
    ans1 = [((r & ~(d - 1)) << 1) + (r & d - 1) + (d & a) for r in res1]
    ans2 = [((r & ~(d - 1)) << 1) + (r & d - 1) + (d & b) for r in res2[::-1]]
    return ans1 + ans2

print('YES')
print(*dfs(n, a, b))
Buggy python submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self, elements):
        self.elements = elements
        self._root = {}
        self._count= {}
        for e in self.elements:
            self._root[e] = e
            self._count[e] = 1
        
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            self._root[x] = y
            self._count[y] += self._count[x]
        
    def root(self, x):
        if self._root[x] != x:
            self._root[x] = self.root(self._root[x])
        return self._root[x]
    
    def size(self, x):
        return self._count[self.root(x)]
        
    def get_union(self):
        union = {}
        for e in self.elements:
            if self.root(e) in union:
                union[self.root(e)].add(e)
            else:
                union[self.root(e)] = {e}
        return union

n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(m)]
A.reverse()

ans = [n * (n - 1) // 2]
uf = UnionFind(range(1, n+1))
for a, b in A:
    if uf.root(a) == uf.root(b):
        ans.append(ans[-1])
        continue
    ans.append(ans[-1] - uf.size(a) * uf.size(b))
    uf.unite(a, b)

print(*ans[:-1][::-1], sep='\n')

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

class UnionFind():
    def __init__(self, elements):
        self.elements = elements
        self._root = {}
        self._count= {}
        for e in self.elements:
            self._root[e] = e
            self._count[e] = 1
        
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            self._root[x] = y
            self._count[y] += self._count[x]
        
    def root(self, x):
        if self._root[x] != x:
            self._root[x] = self.root(self._root[x])
        return self._root[x]
    
    def size(self, x):
        return self._count[self.root(x)]

n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(m)]
A.reverse()

ans = [n * (n - 1) // 2]
uf = UnionFind(range(1, n+1))
for a, b in A:
    if uf.root(a) == uf.root(b):
        ans.append(ans[-1])
        continue
    ans.append(ans[-1] - uf.size(a) * uf.size(b))
    uf.unite(a, b)

print(*ans[:-1][::-1], sep='\n')
Buggy python submission (verdict: Runtime Error):
n = int(input())
X = [[int(i) for i in input().split()] for j in range(n)]

ans = 0

for x, u in X:
    if u == 'BTC':
        x *= 380000
    ans += x

print(ans)

Fixed submission:
n = int(input())
X = [[i for i in input().split()] for j in range(n)]

ans = 0

for x, u in X:
    x = float(x)
    if u == 'BTC':
        x *= 380000
    ans += x

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n, a, b, c = [int(i) for i in input().split()]
L = [int(input()) for i in range(n)]

INF = 10 ** 9

def dfs(i, L, A):
    if all(a == 0 for a in A):
        return 0
    if n - L.count(0) < 3:
        return INF
    if i == n:
        return INF
    if L[i] == 0:
        return dfs(i+1, L[:], A[:])
    for j, a in enumerate(A):
        if a == L[i]:
            A[j] = 0
            return dfs(i+1, L[:], A[:])

    res = dfs(i+1, L[:], A[:])
    for j, a in enumerate(A):
        if a == 0:
            continue
        TL = L[:]
        TL[i] = a
        TA = A[:]
        TA[j] = 0
        d = abs(L[i] - a)
        res = min(res, dfs(i+1, TL, TA) + d)

    if L[i] > max(A):
        return res
    for j in range(i+1, n):
        if L[j] == 0:
            continue
        TL = L[:]
        TL[i] += TL[j]
        TL[j] = 0
        res = min(res, dfs(i, TL, A[:]) + 10)

    return res

print(dfs(0, L[:], [a, b, c]))

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

N, A, B, C = [int(i) for i in input().split()]
L = [int(input()) for i in range(N)]

INF = 10 ** 9

def dfs(n, a, b, c):
    if n == N:
        return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else INF
    res = dfs(n+1, a+L[n], b, c) + 10
    res = min(res, dfs(n+1, a, b+L[n], c) + 10)
    res = min(res, dfs(n+1, a, b, c+L[n]) + 10)
    res = min(res, dfs(n+1, a,  b, c))

    return res

print(dfs(0, 0, 0, 0))

Buggy python submission (verdict: Time Limit Exceeded):
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n, a, b, c = [int(i) for i in input().split()]
L = [int(input()) for i in range(n)]

INF = 10 ** 9

def dfs(i, L, A):
    if all(a == 0 for a in A):
        return 0
    if n - L.count(0) < 3:
        return INF
    if i == n:
        return INF
    if L[i] == 0:
        return dfs(i+1, L[:], A[:])
    for j, a in enumerate(A):
        if a == L[i]:
            A[j] = 0
            return dfs(i+1, L[:], A[:])

    res = dfs(i+1, L[:], A[:])
    for j, a in enumerate(A):
        if a == 0:
            continue
        TL = L[:i] + [a] + L[i+1:]
        TA = A[:j] + [0] + A[j+1:]
        d = abs(L[i] - a)
        res = min(res, dfs(i+1, TL, TA) + d)

    for j in range(i+1, n):
        if L[j] == 0:
            continue
        TL = L[:]
        TL[i] += TL[j]
        TL[j] = 0
        res = min(res, dfs(i, TL, A[:]) + 10, dfs(i+1, TL, A[:]) + 10)

    return res

print(dfs(0, L[:], [a, b, c]))

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

N, A, B, C = [int(i) for i in input().split()]
L = [int(input()) for i in range(N)]

INF = 10 ** 9

def dfs(n, a, b, c):
    if n == N:
        return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else INF
    res = dfs(n+1, a+L[n], b, c) + 10
    res = min(res, dfs(n+1, a, b+L[n], c) + 10)
    res = min(res, dfs(n+1, a, b, c+L[n]) + 10)
    res = min(res, dfs(n+1, a,  b, c))

    return res

print(dfs(0, 0, 0, 0))
Buggy python submission (verdict: Runtime Error):
n, k = [int(i) for i in input.split()]
A = [int(i) for i in input.split()]

print(-1)

Fixed submission:
n, k = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

B = []
for i, a in zip(range(1, n+1), A):
    B.append([a, i])

B.sort(reverse=True)
ans = []

for i in range(n):
    B[i][0] -= 1
    B[i].append(i)
    ans.append(B[i][1])

last = n - 1
for i in range(k):
    mixi = min(B[:last] + B[last+1:])[2]
    cnt = 1
    for j in range(n):
        if j == last or j == mixi:
            continue
        B[j][0] -= 1
        if B[j][0] < 0:
            print(-1)
            exit()
        ans.append(B[j][1])

    ans.append(B[mixi][1])
    B[mixi][0] -= 1
    if B[mixi][0] < 0:
        print(-1)
        exit()
    last = mixi

print(len(ans))
print(*ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = [[int(i) for i in input().split()] for j in range(n)]

C = []
D = []
i = 0

for a, b in A:
    C.append((a - b, i))
    D.append((b - a, i))
    i += 1

C.sort()
D.sort()

used = [False] * n
ans = 0

for i in range(n):
    if i % 2 == 0:
        while used[C[-1][1]]:
            C.pop()
        ans += A[C[-1][1]][0]
        used[C[-1][1]] = True
        C.pop()
    else:
        while used[D[-1][1]]:
            D.pop()
        ans -= A[C[-1][1]][1]
        used[C[-1][1]] = True
        D.pop()

print(ans)

Fixed submission:
n = int(input())
A = [[int(i) for i in input().split()] for j in range(n)]

C = []
D = []
i = 0

for a, b in A:
    C.append((a + b, i))
    i += 1

C.sort(reverse=True)
ans = 0

for i, c in enumerate(C):
    if i % 2 == 0:
        ans += A[c[1]][0]
    else:
        ans -= A[c[1]][1]

print(ans)
Buggy python submission (verdict: Runtime Error):
H, W = [int(i) for i in input().split()]
S = [[j for j in input()]for i in range(H)]

INF = int(1e12)

def dfs(h, w, p):
    b_cnt = 0
    w_cnt = 0
    if h < 0 or h >= H or w < 0 or w >= W:
        return 0, 0
    if S[h][w] == p or S[h][w] == 'x':
        return 0, 0
    if S[h][w] == '#':
        b_cnt += 1
    elif S[h][w] == '.':
        w_cnt += 1
    t = S[h][w]
    S[h][w] = 'x'

    for dh, dw in ((0, 1), (0, -1), (1, 0), (-1, 0)):
        res = dfs(h + dh, w + dw, t)
        b_cnt += res[0]
        w_cnt += res[1]

    return (b_cnt, w_cnt)

ans = 0

for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            b_cnt, w_cnt = dfs(h, w, '.')
            ans += b_cnt * w_cnt

print(ans)

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

H, W = [int(i) for i in input().split()]
S = [[j for j in input()]for i in range(H)]

INF = int(1e12)

def dfs(h, w, p):
    b_cnt = 0
    w_cnt = 0
    if h < 0 or h >= H or w < 0 or w >= W:
        return 0, 0
    if S[h][w] == p or S[h][w] == 'x':
        return 0, 0
    if S[h][w] == '#':
        b_cnt += 1
    elif S[h][w] == '.':
        w_cnt += 1
    t = S[h][w]
    S[h][w] = 'x'

    for dh, dw in ((0, 1), (0, -1), (1, 0), (-1, 0)):
        res = dfs(h + dh, w + dw, t)
        b_cnt += res[0]
        w_cnt += res[1]

    return (b_cnt, w_cnt)

ans = 0

for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            b_cnt, w_cnt = dfs(h, w, '.')
            ans += b_cnt * w_cnt

print(ans)