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

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


w=s.count(".")
ans = w

for i in range(n):

    if s[i]=="#":
        w+=1
    if s[i]==".":
        w-=1
    ans=min(ans,w)
    
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
x=n
flag1=False
flag2=False
for i in range(n):
    if s[i]=="#" and flag1==False:
        x=i
        flag1=True
    if s[n-1-i]!="#" and flag2==False:
        y=n-i
        flag2=True
    if flag1==True and flag2==True:
        break

b=s[x:y].count("#") 
w=len(s[x:y])-b
print(b if b<w else w)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
x=n
for i in range(n):
    if s[i]=="#":
      x=i
      break
for i in range(1,n):
    if s[n-i]=="#":
        s=s[:-i]
    else:
        break
b=s[x:].count("#") 
w=len(s[x:])-b
print(b if b<w else w)
Problem p03106 (python)

Fixed submission:
A = list(map(int,input().split( )))
a=A[0]
b=A[1]
k=A[2]
x=0
for h in range(100):
	i= (b if a>b else a)-h
	if a%i + b%i:
		continue
	x=x+1
	if x == k:
		break
print(i)

Buggy submission (verdict: Runtime Error):
A = list(map(int,input().split( )))
a=A[0]
b=A[1]
k=A[2]
x=0
for h in range(1,51):
	i=50-h
	if a%i + b%i:
		continue
	x=x+1
	print(i)
	if x == k:
		break
print(i)
Problem p02621 (python)

Fixed submission:
a = int(input())

print(a + a**2 + a**3)

Buggy submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]*(N+1)
b = [0]*(M+1)
X = 0
Y = 0
cnt = 0
for n in range(N):
    a[n+1] = a[n] + A[n]
for n in range(M):
    b[n+1] = b[n] + B[n]
for n in range(1, N+1):
    if a[n] <= K:
        X = n
for m in range(1, M+1):
    if b[m] <= K:
        Y = m 
if a[X] < b[Y]:
    K = K - a[X]
    cnt += X
    if K - b[Y] == 0:
        cnt += Y
    else:
        for y in range(1, Y+1):
            if b[y] < K:
                cnt += 1
else:
    K = K - b[Y]
    cnt += Y
    if K - a[X] == 0:
        cnt += X
    else:
        for x in range(1, X+1):
            if a[x] < K:
                cnt += 1
print(cnt)
Problem p02630 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = [0]*(N+1)
for n in range(N):
    B[n+1] = B[n] + A[n]
C = B.pop()

Z = {}
for n in range(N):
    Z[A[n]] = 0
for n in range(N):
    Z[A[n]] += 1

D = []
Q = int(input())
for q in range(Q):
    x, y = map(int, input().split())
    if x in Z:
        C = C - x*Z[x]
        C = C + y*Z[x]
        D.append(C)
        if x == y:
            continue
        if y in Z:
            Z[y] += 1*Z[x]
        else:
            Z[y] = Z[x]
        Z.pop(x)
    else:
        D.append(C)
for d in D:
    print(d)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
C = sum(A)
D = [0]*(10**5)
for n in range(N):
    D[A[n]] += 1
Q = int(input())
Z = []
for q in range(Q):
    x, y = map(int, input().split())
    if D[x]:
        C = C - x*D[x]
        C = C + y*D[x]
        Z.append(C)
        if D[y]:
            D[y] += 1*D[x]
        else:
            D[y] = D[x]
        D[x] = 0
    else:
        Z.append(C)
for z in Z:
    print(z)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
C = sum(A)
D = [0]*(10**5)
for n in range(N):
    D[A[n]] += 1
Q = int(input())
Z = []
for q in range(Q):
    x, y = map(int, input().split())
    if D[x]:
        C = C - x*D[x]
        C = C + y*D[x]
        Z.append(C)
        D[y] += 1*D[x]
        D[x] = 0
    else:
        Z.append(C)
for z in Z:
    print(z)
Problem p02724 (python)

Fixed submission:
X = int(input())

C = 0
P = 0
D = 0
L = 0
total = 0

if X >= 0 and X <= 10 ** 9:
    while True:
        if X >= 500:
            C = X // 500
            P = 500 * C
            X = X - P
        elif X >= 5:
            D = X // 5
            L = 5 * D
            X = X - L
        else:
            break
man = 1000 * C
t   = 5 * D

total = man + t

print(total)

Buggy submission (verdict: Runtime Error):
X = int(input())

if X >= 0 and X <= 10 ** 9:
    while True:
        if X >= 500:
            C = X // 500
            X = X - (500 * C)
        elif X >= 5:
            D = X // 5
            X = X - (5 * D)
        else:
            break

total = (1000 * C) + (5 * D)

print(total)

Buggy submission (verdict: Runtime Error):
X = int(input())

if X >= 0 and X <= 10 ** 9:
    while True:
        if X >= 500:
            C = X // 500
            X = X - (500 * C)
        elif X >= 5:
            D = X // 5
            X = X - (5 * D)
        else:
            break

total = (1000 * C) + (5 * D)

print(total)

Buggy submission (verdict: Runtime Error):
X = int(input())

while True:
    if X >= 500:
        C = X // 500
        X = X - (500 * C)
    elif X >= 5:
        D = X // 5
        X = X - (5 * D)
    else:
        break

total = (500 * C) + (5 * D)

print(total)

Buggy submission (verdict: Runtime Error):
X = int(input())

if X >= 0 and X <= 10 ** 9:
    while True:
        if X >= 500:
            C = X // 500
            X = X - (500 * C)
        elif X >= 5:
            D = X // 5
            X = X - (5 * D)
        else:
            break

total = (500 * C) + (5 * D)

print(total)

Buggy submission (verdict: Runtime Error):
X = int(input())

if X >= 0 and X <= 10 ** 9:
    while True:
        if X > 500:
            C = X // 500
            P = 500 * C
            X = X - P
        elif X > 5:
            D = X // 5
            L = 5 * D
            X = X - L
        else:
            break

total = (1000 * C) + (5 * D)

print(total)

Buggy submission (verdict: Runtime Error):
X = int(input())

if X >= 0 and X <= 10 ** 9:
    while True:
        if X > 500:
            C = X // 500
            P = 500 * C
            X = X - P
            continue
        if X > 5:
            D = X // 5
            L = 5 * D
            X = X - L
            continue
        break

total = (1000 * C) + (5 * D)

print(total)

Buggy submission (verdict: Runtime Error):
X = int(input())

a = 0
b = 0
c = 0
d = 0
e = 0
f = 0

for q in range(100):
    for w in range(100):
        for e in range(100):
            for r in range(100):
                for t in range(100):
                    for y in range(100):
                        num = (500 * q) + (100 * w) + (50 * e) + (10 * r) + (5 * t) + (1 * y)
                        if X % num == 0:
                            m = q
                            i = t
                            break


print(500 * m + 5 * i)
Problem p02756 (python)

Fixed submission:
from collections import deque

S = input()
B = deque()
res = 0
for s in range(len(S)):
    B.append(S[s])
Q = int(input())
for q in range(Q):
    A = list(map(str, input().split()))
    if int(A[0]) == 1:
        if res == 0:
            res = 1
        else:
            res = 0
    else:
        if int(A[1]) == 1:
            if res == 0:
                B.appendleft(A[2])
            else:
                B.append(A[2])
        else:
            if res == 0:
                B.append(A[2])
            else:
                B.appendleft(A[2])
if res == 0:
    print(''.join(B))
else:
    B.reverse()
    print(''.join(B))

Buggy submission (verdict: Runtime Error):
from collections import deque

S = input()
B = deque()
res = 0
for s in range(len(S)):
    B.append(S[s])
Q = int(input())
for q in range(Q):
    A = list(map(str, input().split()))
    if int(A[0]) == 1:
        if res == 0:
            res = 1
        else:
            res = 0
    else:
        if int(A[1]) == 1:
            if res == 0:
                B.appendleft(A[2])
            else:
                B.append(A[2])
        else:
            if res == 0:
                B.append(A[2])
            else:
                B.appendleft(A[2])
if res == 0:
    print(''.join(B))
else:
    B = B[::-1]
    print(''.join(B))
Problem p02802 (python)

Fixed submission:
n, m = map(int, input().split())
tmp  = [0]*n
wtmp = [0]*n
for _ in range(m):
    P, s = map(str, input().split())
    p = int(P)
    p -= 1
    if not tmp[p] == 0:
        continue
    if s == 'AC':
        tmp[p] = 1
    else:
        wtmp[p] += 1
ans1 = sum(tmp)
ans2 = 0
for i in range(n):
    if tmp[i] == 1:
        ans2 += wtmp[i]
print(ans1, ans2)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
L = list()
for m in range(M):
    l = input().split()
    L.append(l)
AC = 0
WA = 0
cnt = 0
for m in range(M):
    res = False
    if L[m][1] == 'AC':
        AC += 1
        res = True
        if res:
            cnt += 1
    elif L[m][1] == 'WA':
        WA += 1
    if int(L[m][0]) == N and res == True:
        break
print('{} {}'.format(AC // cnt, WA))
Problem p02812 (python)

Fixed submission:
N = int(input())
S = input()
cut = S.count('ABC')
print(cut)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
cut = 0
for n in range(N+1):
    if S[n] == 'A' and S[n + 1] == 'B' and S[n + 2] == 'C':
        cut += 1

print(cut)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
cut = 0
for n in range(N):
    if S[n] == 'A' and S[n + 1] == 'B' and S[n + 2] == 'C':
        cut += 1

print(cut)
Problem p03363 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
S = [0]*(N+1)
for n in range(N):
    S[n+1] = S[n] + A[n]
B = {}
for s in range(len(S)):
    B[S[s]] = 0
for s in range(len(S)):
    B[S[s]] += 1
res = 0
for v in B.values():
    if v > 1:
        res += v * (v - 1) // 2
print(res)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
S = [0]*(N+1)
for n in range(N):
    S[n+1] = S[n] + A[n]
C = [0]*(2*10**5+1)
for n in range(len(S)):
    C[S[n]] += 1
cnt = 0
for c in range(2*10**5+1):
    cnt += C[c] * (C[c] - 1) // 2
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
S = [0]*(N+1)
for n in range(N):
    S[n+1] = S[n] + A[n]
C = [0]*(2*10**5)
for n in range(len(S)):
    C[S[n]] += 1
cnt = 0
for c in range(2*10**5):
    cnt += C[c] * (C[c] - 1) // 2
print(cnt)
Problem p03457 (python)

Fixed submission:
import math
N = int(input())
T = [0]*110000
X = [0]*110000
Y = [0]*110000

for n in range(N):
    T[n+1], X[n+1], Y[n+1] = map(int, input().split())

res = True
for n in range(N):
    dt   = T[n+1] - T[n]
    dist = abs(X[n+1] - X[n]) + abs(Y[n+1] - Y[n])
    if dt < dist:
        res = False
    if dt % 2 != dist % 2:
        res = False

if res:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
t = [0]*100000
x = [0]*100000
y = [0]*100000

for n in range(N):
    t[n+1], x[n+1], y[n+1] = map(int, input().split())

ans = True
for n in range(N):
    dt   = t[n+1] - t[n]
    dist = (x[n+1] - x[n]) + (y[n+1] - y[n])
    if dt < dist:
        ans = False
    if dt % 2 != dist % 2:
        ans = False
if ans:
    print('Yes')
else:
    print('No')
Problem p04029 (python)

Fixed submission:
N = int(input())
print(N*(N+1)//2)

Buggy submission (verdict: Runtime Error):
#include<bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  cout << n*(n+1)/2 << endl;
}
Problem p04031 (python)

Fixed submission:
def S(a,N,M):
    m=0
    for i in range(N):
        m+=(a[i]-M)**2
    return m
    

N=int(input())
a=[int(x) for x in input().split()]

m=S(a,N,-100)

for i in range(-99,101):
    if m > S(a,N,i):
        m=S(a,N,i)
        
print(m)

Buggy submission (verdict: Runtime Error):
#include<bits/stdc++.h>
using namespace std;

int S(vector<int> a,int N,int M){
  int S=0;
  for(int i=0;i<N;i++){
    S+=(a.at(i)-M)*(a.at(i)-M);
  }
  return S;
}

int main(){
  int N,V;
  cin >> N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  V=S(a,N,-100);
  for(int i=0;i<201;i++){
    if(S(a,N,-100+i)<V) V=S(a,N,-100+i);
  }
  
  cout << V << endl;
}
Problem p03000 (python)

Fixed submission:
N, X = map(int, input().split())
num = input().split()
cnt = 1
cal = 0
for x in range (N):
  cal += int(num[x])
  if cal <= X:
    cnt +=1
  else:
    break
print(cnt)

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
num = input().split()
cnt = 1
cal = 0
for range in (N):
  cal += int(num[N])
  if cal <= X:
    cnt +=1
  else:
    break
print(cnt)
Problem p03001 (python)

Fixed submission:
W, H ,x, y = map(int, input().split())
if W == H:
  if x == W/2 and y == H/2:
    can = 1
  else:
    can = 0
else:
  if x == W/2 or y == H/2:
    if x == W/2 and y == H/2:
      can = 1
    else:
      can = 0
  else:
    if y == (H/W)*x or y == (-H/W)*x:
      can = 0
    else:
      can = 1
 
print('{:.9f}'.format(W*H/2), can)

Buggy submission (verdict: Runtime Error):
W, H ,x, y = map(int, input().split())
if H > W:
  if x == W/2:
    can = 0
  else:
    can = 1
elif H == W:
  can = 1
else:
  if y == H/2:
    can = 0
  else:
    can = 1
  
print(float(W*H/2) + ' '  + can)
Problem p03434 (python)

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

one =[]
two =[]
count = 0
if N%2 ==0:
  while count <= N-1:
    one.append(max(B))
    B.remove(max(B))
    two.append(max(B))
    B.remove(max(B))
    count +=2
else:
  while count <= N-2:
    one.append(max(B))
    B.remove(max(B))
    two.append(max(B))
    B.remove(max(B))
    count +=2
  one.append(max(B))
  B.remove(max(B))

print(sum(one)-sum(two))

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

one =[]
two =[]
count = 0
if N%2 ==0:
  while count <= N:
    one.append(max(B))
    B.remove(max(B))
    two.append(max(B))
    B.remove(max(B))
    count +=2
else:
  while count <= N-2:
    one.append(max(B))
    B.remove(max(B))
    two.append(max(B))
    B.remove(max(B))
    count +=2
  one.append(max(B))
  B.remove(max(B))

print(sum(one)-sum(two))

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

one =[]
two =[]
count = 0
if N%2 ==0:
  while count <= N:
    one.append(max(B))
    B.remove(max(B))
    two.append(max(B))
    B.remove(max(B))
    count +=2
else:
  while count <= N-2:
    one.append(max(B))
    B.remove(max(B))
    two.append(max(B))
    B.remove(max(B))
    count +=2
  one.append(max(B))
  B.remove(max(B))
print(one)
print(two)
print(sum(one)-sum(two))
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
c = a * b
if c % 2 ==0:
  print('Even')
else:
  print('Odd')

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())
if a*b %2 ==0:
  print('Even')
else:
  print('Odd')

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
c = a * b
if c %= 0:
  print('Even')
else:
  print('Odd')
Problem p03477 (python)

Fixed submission:
a,b,c,d = map(int, input().split())
if a + b > c +d:
	print('Left')
elif a+b == c+d:
	print('Balanced')
else:
	print('Right')

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int, input().split()
if a + b > c +d:
	print('Left')
elif a+b == c+d:
	print('Balanced')
else:
	print('Right')
Problem p03485 (python)

Fixed submission:
import math
a,b = map(int, input().split())
print(math.ceil((a+b)/2))

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
c = a + b
d = c / 2
print(math.ceil(d))
Problem p03486 (python)

Fixed submission:
def a():
  s = input()
  t = input()
  s = ''.join(sorted(s))
  t = ''.join(sorted(t, reverse = True))
  
  if s < t:
    print('Yes')
  else:
    print('No')
   
  return 0

a()

Buggy submission (verdict: Runtime Error):
def a():
  s = input()
  t = input()
  s = ''.join(sorted(s))
  t = ''.join(sorted(t, reverse = True)
  if s < t :
    print('Yes')
  else:
    print('No')
  return 0
          
a()
Problem p03493 (python)

Fixed submission:
a = input()
one_number = a.count('1')
print( 1 * one_number)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = a.count(int(1))
print(b)
Problem p03494 (python)

Fixed submission:
N = int(input())
nums = [int(x) for x in input().split()]
cnt = 0
loop = True
while loop:
  if not all([n % 2 is 0 for n in nums]):
    loop = False 
    break
    
  for i, n in enumerate(nums):
    nums[i] = n//2
  cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
count = 0
numbers = list(map(int, b.split()))
def calicurate():
  for n in numbers:
    if n%2 ==0:
      n = n/2
    else:
      break
for i in calicurate():
  numbers.calicurate(i)
  count += 1
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
nums = [int(x) for x in input().split()]
cnt = 0
loop = True
if loop:
  if not all([n%2 is 0 for n in nums]):
    break
  for i, n in enumerate(nums):
    nums[i] = n//2
  cnt +=1
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
nums = [int(x) for x in input().split()]
cnt = 0
loop = True
while loop:
  if not all([n % 2 is 0 for n in nums]):
    loop = Flase 
    break
    
  for i, n in enumerate(nums):
    nums[i] = n//2
  cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
nums = [int(x) for x in input().split()]
cnt = 0
loop = True
while loop:
  if not all([n%2 is 0 for n in nums]):
    loop = Flase 
    break
  for i, n in enumerate(nums):
    nums[1] = n//2
  cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
nums = [int(x) for x in input().split()]
cnt = 0
loop = True
while Loop:
  if not all([n%2 is 0 for n in nums]):
    loop = Flase 
    break
  for i, n in enumerate(nums):
    nums[1] = n//2
  cnt += 1
print(cnt)
Problem p03502 (python)

Fixed submission:
a = (input())
number_2 = [int(s) for s in a]
total = sum(number_2)
if int(a) % total == 0:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
a = input()
number = [int(s) for s in a]
total = sum(number)
if a % total ==0:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
a = int(input())
number = a.split()
total = sum(number)
if a % total == 0:
  print('Yes')
else:
  print('No')
Problem p03854 (python)

Fixed submission:
word = input()
x = word.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
if x == '':
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
word = input()
b = word
d = word
f = word
h = word
def gyaku(x):
  x = list(x)
  x.reverse()
  return ''.join(x)
if gyaku('eraser') in gyaku(word):
  a = gyaku(word).split(gyaku('eraser'))
  b = ''.join(a)
  h = gyaku(b)
if gyaku('dreamer') in gyaku(h):
  g = gyaku(h).split(gyaku('dreamer')
  h = gyaku(''.join(g))
if gyaku('erase') in gyaku(h):
  c = gyaku(h).split(gyaku('erase'))
  d = ''.join(c)
  h = gyaku(d)
if gyaku('dream') in gyaku(h):
  e = gyaku(h).split(gyaku('dream'))
  f = ''.join(e)
  h = gyaku(f)
 
if h == (''):
  print('YES')
else:
  print('NO')
Problem p02748 (python)

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

reizou = input()
reizou_list = reizou.split()

renji = input()
renji_list = renji.split()
cupon_list = []

price = int(min(reizou_list)) + int(min(renji_list))

for i in range(int(M)):
    # coupon = input()
    # coupon_sub_list = coupon.split()
    # cupon_list.append(coupon_sub_list)
    
    a,b,c = map(int,input().split())
    price_coupon = int(reizou_list[int(a) - 1]) + int(renji_list[int(b) - 1]) - int(c)
    if price > price_coupon: price = price_coupon

print(price)

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

reizou = input()
reizou_list = reizou.split()

renji = input()
renji_list = renji.split()
cupon_list = []

price = int(min(reizou_list)) + int(min(renji_list))

for i in range(int(M)):
    # coupon = input()
    # coupon_sub_list = coupon.split()
    # cupon_list.append(coupon_sub_list)
    
    a,b,c = map(int,input().split())
    price_coupon = int(reizou_list[a]) + int(renji_list[b]) - int(c)
    if price > price_coupon: price = price_coupon

print(price)

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

reizou = input()
reizou_list = reizou.split()

renji = input()
renji_list = renji.split()
cupon_list = []

price = int(min(reizou_list)) + int(min(renji_list))

for i in range(int(M)):
    # coupon = input()
    # coupon_sub_list = coupon.split()
    # cupon_list.append(coupon_sub_list)
    
    a,b,c = map(int,input().split())
    price_coupon = int(reizou_list[a]) + int(renji_list[b]) - int(c)
    if price > price_coupon: price = price_coupon
Problem p02630 (python)

Fixed submission:
import numpy as np
N=int(input())
A=list(map(int,input().split()))
SUM=sum(A)
Q=int(input())
List=np.array([0 for _ in range(10**5+1)])
for a in A:
    List[a]+=1
for q in range(Q):
    B,C=map(int,input().split())
    SUM-=B*List[B]
    SUM+=C*List[B]
    List[C]+=List[B]
    List[B]=0
    print(SUM)

Buggy submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
List=[i for i in range(10**5+1)]
Uf=UnionFind(10**5)
for i in range(Q):
    B,C=map(int,input().split())
    List[B]=C
    Uf.union(B,C)
    for i in Uf.members(B):
        index=i
        while index!=List[index]:
            index=List[index]
            if index==i:
                break
            # print(index)
            # print(List)
        List[i]=index
    ChangedA=[List[a] for a in A]
    print(sum(ChangedA))
Problem p02683 (python)

Fixed submission:
import numpy as np
N,M,X=map(int,input().split())
C=[]
A=[]
for i in range(N):
    buf=list(map(int,input().split()))
    C.append(buf[0])
    A.append(buf[1:])

MinmalCost=1e30

MaxInter=2**N-1
LenOfBin=len(bin(MaxInter)[2:])
for i in range(MaxInter+1):
    binary=bin(i)[2:].rjust(LenOfBin,"0")
    Cost=0
    Learning=np.zeros(M,)
    for j,Switch in enumerate(binary):
        if Switch=="1":
            Cost+=C[j]
            Learning+=A[j]
    if np.all(Learning>=X) and Cost<MinmalCost:
        MinmalCost=Cost
if MinmalCost==1e30:
    print(-1)
else:
    print(MinmalCost)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,M,X=map(int,input().split())
C=[]
A=[]
for i in range(N):
    buf=list(map(int,input().split()))
    C.append(buf[0])
    A.append(buf[1:])

MinmalCost=1e30

MaxInter=2**N-1
LenOfBin=len(bin(MaxInter)[2:])
for i in range(MaxInter+1):
    binary=bin(i)[2:].rjust(LenOfBin,"0")
    Cost=0
    Learning=np.zeros(M,)
    for j,Switch in enumerate(binary):
        if Switch=="1":
            Cost+=C[j]
            Learning+=A[j]
    if np.all(Learning>=X) and Cost<MinmalCost:
        MinmalCost=Cost
if MinmalCost==1e30:
    print(-1)
else:
    print(MinmalCost)