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

Fixed submission:
n = int(input())

v = list(map(int,input().split()))

v.sort(reverse = True)

while len(v) > 1 :
    v.append((v.pop(-1) + v.pop(-1))/2)
    v.sort(reverse = True)

print(v[0])

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

v = list(map(int,input().split()))

v.sort(reverse = True)

while len(v) > 1 :
    v.append((v.pop(-1) + v.pop(-2))/2)
    v.sort(reverse = True)

print(v)
Problem p02987 (python)

Fixed submission:
s = list(input())
t = list(set(s))
if len(t) == 2 and s.count(t[0]) == 2 :
    print("Yes")
else :
    print("No")

Buggy submission (verdict: Runtime Error):
s = list(input())
t = set[s]
if len(t) == 2 and s.count(t[0]) == 2 :
    print("Yes")
else :
    print("No")
Problem p03075 (python)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

l = []
l.append(a)
l.append(b)
l.append(c)
l.append(d)
l.append(e)
ans = 0
for i in range(5):
    for j in range(i+1,5):
        if l[j] - l[i] > k :
            ans += 1

if ans == 0 :
    print("Yay!")
else :
    print(":(")

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

l = []
l.append(a)
l.append(b)
l.append(c)
l.append(d)
l.append(e)
ans = 0
for i in range(5):
    for j in range(i+1,5):
        if l[j] - l[i] > k :
            ans += 1

if ans = 0 :
    print("Yay!")
else :
    print(":(")
Problem p02695 (python)

Fixed submission:
import itertools

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N,M,Q = map(int, input().split())
L = []

for i in range(1,M+1,1):
    L.append(i)

A = []
B = []
C = []
D = []
for _ in range(Q):
    a,b,c,d = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)

List = list(itertools.combinations_with_replacement(L, N))
ans = 0
for l in List:
    temp = 0
    for q in range(Q):
        if (l[B[q]-1]-l[A[q]-1])==C[q]:
            temp = temp + D[q]
    ans = max(ans, temp)
print(ans)

Buggy submission (verdict: Runtime Error):

List = []
def dfs(S):
    global N,M

    if len(S)==N:
        List.append(list(map(int, list(S))))
        return
    for i in range(1, M+1, 1):
        i = str(i)
        dfs(S+i)
    return

N,M,Q = map(int, input().split())
L = []

dfs("")
for i in range(1,M+1,1):
    L.append(i)

A = []
B = []
C = []
D = []
for _ in range(Q):
    a,b,c,d = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)

ans = 0
for l in List:
    temp = 0
    for q in range(Q):
        if (l[B[q]-1]-l[A[q]-1])==C[q]:
            temp = temp + D[q]
    ans = max(ans, temp)
print(ans)
Problem p02762 (python)

Fixed submission:
import sys
sys.setrecursionlimit(500000)
N,M,K = map(int, input().split())
V = []

color = [-1]*N
V_block = []

#各連結成分の次元テーブル
dic = {}

dim = 0
#深さ優先探索
def dfs(node, c):
    global dim

    if color[node]!=-1:
        return
    color[node] = c
    dim = dim + 1
    for next_node in V[node]:
        dfs(next_node, c)
    return

for _ in range(N):
    V.append(set())
    V_block.append(set())
for _ in range(M):
    a,b = map(int, input().split())
    V[a-1].add(b-1)
    V[b-1].add(a-1)

#一旦捨てる
for _ in range(K):
    c,d = map(int, input().split())
    V_block[c-1].add(d-1)
    V_block[d-1].add(c-1)
    
c = 0
for node in range(N):
    if color[node]!=-1:
        continue
    dim = 0
    dfs(node, c)
    dic[c] = dim

    c = c + 1

ans_list = []
for node in range(N):
    num = 0
    for block_node in V_block[node]:
        if color[node]==color[block_node]:
            num = num + 1
    ans_list.append(dic[color[node]]-num-len(V[node])-1)

print(*ans_list)

Buggy submission (verdict: Runtime Error):
N,M,K = map(int, input().split())
V = []

color = [-1]*N
V_block = []

#各連結成分の次元テーブル
dic = {}

dim = 0
#深さ優先探索
def dfs(node, c):
    global dim

    if color[node]!=-1:
        return
    color[node] = c
    dim = dim + 1
    for next_node in V[node]:
        dfs(next_node, c)
    return

for _ in range(N):
    V.append(set())
    V_block.append(set())
for _ in range(M):
    a,b = map(int, input().split())
    V[a-1].add(b-1)
    V[b-1].add(a-1)

#一旦捨てる
for _ in range(K):
    c,d = map(int, input().split())
    V_block[c-1].add(d-1)
    V_block[d-1].add(c-1)
    
c = 0
for node in range(N):
    if color[node]!=-1:
        continue
    dim = 0
    dfs(node, c)
    dic[c] = dim

    c = c + 1

ans_list = []
for node in range(N):
    num = 0
    for block_node in V_block[node]:
        if color[node]==color[block_node]:
            num = num + 1
    ans_list.append(dic[color[node]]-num-len(V[node])-1)

print(*ans_list)
Problem p02829 (python)

Fixed submission:
A = int(input())
B = int(input())
L = [1,2,3]
L.remove(A)
L.remove(B)
for l in L:
  print(l)

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

L = [1,2,3]
L.remove(A)
L.remove(B)
for l in L:
  print(l)
Problem p02831 (python)

Fixed submission:
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)
A,B = map(int, input().split())
print(lcm(A, B))

Buggy submission (verdict: Runtime Error):
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)
A,B = map(int, input().split())
print(lcm(A, B))
Problem p02836 (python)

Fixed submission:
S = list(input())

count = 0

for i in range(len(S)//2):
  if S[i]!=S[-(i+1)]:
  	count = count + 1
   
  
print(count)

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

if len(S)%2==0:
  half_index = len(S)//2
else:
  half_index = len(S)//2 - 1
  
count = 0
for i in range(half_index+1):
  if S[i]!=S[-(i+1)]
  	count = count + 1
    
print(count)

Buggy submission (verdict: Runtime Error):
S = list(input())

count = 0

for i in range(len(S)//2):
  if S[i]!=S[-(i+1)]
  	count = count + 1
   
  
print(count)
Problem p02862 (python)

Fixed submission:
X,Y = map(int, input().split())

if (X+Y)%3!=0:
    print(0)
    exit()

def mcomb(n, k):
    fac = [0] * (n + 1)
    fac[0] = 1
    for i in range(1, n + 1):
        fac[i] = fac[i - 1] * i % 1000000007


    if n == 0 and k == 0:
        return 1
    if n < k or k < 0:
        return 0
    return fac[n] * pow(fac[n - k], 1000000005, 1000000007) * pow(fac[k], 1000000005, 1000000007) % 1000000007

N = (-1*X+2*Y)//3
M = (2*X-Y)//3
print(mcomb(N+M, N)%(10**9+7))

Buggy submission (verdict: Runtime Error):
X,Y = map(int, input().split())


count = 0

def dfs(x,y):
    global count
    if x==X and y==Y:
        count = count + 1
        return
    if x<0 or y<0 or x>=X or y>=Y:
        return
    
    dfs(x+1, y+2)
    dfs(x+2, y+1)

    return

dfs(0,0)
print(count%(10**9+7))

Buggy submission (verdict: Runtime Error):
X,Y = map(int, input().split())


count = 0

def dfs(x,y):
    global count
    if x==X and y==Y:
        count = count + 1
        return
    if x<0 or y<0 or x>=X or y>=Y:
        return
    
    dfs(x+1, y+2)
    dfs(x+2, y+1)

    return

dfs(0,0)
print(count%(10**9+7))

Buggy submission (verdict: Runtime Error):
X,Y = map(int, input().split())


count = 0

def dfs(x,y):
    global count
    if x==X and y==Y:
        count = count + 1
        return
    if x<0 or y<0 or x>=X or y>=Y:
        return
    
    dfs(x+1, y+2)
    dfs(x+2, y+1)

    return

dfs(0,0)
print(count)
Problem p02880 (python)

Fixed submission:
N = int(input())
flg = 0

for i in range(1, 10, 1):
  if flg==1:
    break
  for j in range(1, 10, 1):
    if i*j==N:
      print("Yes")
      flg= 1
      break
    
      
if flg==0:
  print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
flg = 0

for i in range(1, 10, 1):
  for j in range(1, 10, 1):
    if i*j==N:
      print(Yes)
      flg= 1
      
if flg==1:
  print(No)
Problem p02881 (python)

Fixed submission:
N = int(input())

min = float('inf')

times = int(N**0.5)

for i in range(1, times+1, 1):

    if N%i==0:
        j = N//i
    else:
        continue
    temp = i+j-2
    if min > temp:
        min = temp

print(min)

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

N = int(input())

min = float('inf')

def dfs(x, y, count):
    global min

    if x<0 or y<0 or (((x+1)*(y+1))>N):
        return

    if (x+1)*(y+1)==N:
        
        if min > count:
            min = count
            return
        return

    dfs(x+1, y, count+1)
    dfs(x, y+1, count+1)

    return

dfs(0,0,0)

print(min)

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

N = int(input())

min = float('inf')

def dfs(x, y, count):
    global min

    if x<0 or y<0 or (((x+1)*(y+1))>N):
        return

    if (x+1)*(y+1)==N:
        
        if min > count:
            min = count
            return
        return

    dfs(x+1, y, count+1)
    dfs(x, y+1, count+1)

    return

dfs(0,0,0)

while 

print(min)

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

min = float('inf')

def dfs(x, y, count):
    global min

    if x<0 or y<0 or (((x+1)*(y+1))>N):
        return

    if (x+1)*(y+1)==N:
        
        if min > count:
            min = count
            return
        return

    dfs(x+1, y, count+1)
    dfs(x, y+1, count+1)

    return

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

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

min = float('inf')

def dfs(x, y, count):
    global min
    if (x+1)*(y+1)==N:
        
        if min > count:
            min = count
            return
        return
    if x<0 or y<0 or (((x+1)*(y+1))>N):
        return

    count = count + 1

    dfs(x+1, y, count)
    dfs(x, y+1, count)

    return

dfs(0,0,0)
print(min)
Problem p02987 (python)

Fixed submission:
S = input()


S = list(set(S))

if len(S) == 2:
    print("Yes")
else:
    print("No")

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


temp1 = S[1]
temp2 = S[2]
temp3 = S[3]
temp4 = S[4]


if temp1 == temp2 and temp3 == temp4 and len(set(S))==2:
    print("Yes")
elif temp1 == temp3 and temp2 == temp4 and len(set(S))==2:
    print("Yes")
elif temp1 == temp4 and temp2 == temp3 and len(set(S))==2:
    print("Yes")
else:
    print("No")

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

S = S.split()

S = list(set(S))

if len(S == 2:
    print("Yes)
else:
    print("No")
Problem p03075 (python)

Fixed submission:

A = [0, 0, 0, 0, 0]
A[0] = int(input())
A[1] = int(input())
A[2] = int(input())
A[3] = int(input())
A[4] = int(input())
k = int(input())

flg = 0

for i in range(0, 4, 1):
    if flg == 1:
        break

    for j in range(i+1, 5, 1):
        if k < (A[j] - A[i]):
            flg = 1
            print(":(")
            break

if flg == 0:
    print("Yay!")

Buggy submission (verdict: Runtime Error):

A = [0, 0, 0, 0, 0]
A[0] = int(input())
A[1] = int(input())
A[2] = int(input())
A[3] = int(input())
A[4] = int(input())
k = int(input())

flg = 0

for i in range(4):
    for j in range(i+1, 5, 1)
        if k < (A[j] - A[i]):
            flg = 1
            print(":(")
            break

if flg == 0:
    print("Yay!")
Problem p03107 (python)

Fixed submission:
S = input()


count_1 = 0
count_0 = 0

for i in range(len(S)):
  if S[i]=="1":
    count_1 = count_1 + 1
  elif S[i]=="0":
    count_0 = count_0 + 1
    

if count_1 >= count_0:
  print(count_0*2)
else:
  print(count_1*2)

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


count_1 = 0
count_0 = 0

for i in range(len(S)):
  if S[i]=="1":
    count_1 = count_1 + 1
  elif S[i]=="0":
    count_0 = count_0 + 1
    

if count_1 >= count_0:
  print(count_0*2)
elif:
  print(count_1*2)

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

len_now = len(S)
count = 0
pivot = len(S)-1

while True:
  if len(S)==1:
    break
  elif S[0]=="1" and S[1]=="1":
    break
  elif S[0]=="0" and S[1]=="0":
    break
  
  if S[pivot]=="0" and S[pivot+1]=="1":
    S = S[pivot+2:len(S)]
    count = count + 2
  elif S[pivot]=="1" and S[pivot+1]=="0":
    S = S[pivot+2:len(S)]
    count = count + 2
  pivot = pivot+1

print(count)
Problem p03250 (python)

Fixed submission:
a,b,c = sorted(map(int, input().split()),reverse=True)

print(a*10+b+c)

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

A.sort(reverse=True)

print(A[0]*10+A[1]+A[2])
Problem p03631 (python)

Fixed submission:
l = input()
print("Yes" if l[0]==l[2] else "No")

Buggy submission (verdict: Runtime Error):
l = input()
print("Yes" if l[0]=l[2] else "No")
Problem p03775 (python)

Fixed submission:
N = int(input())

min = float("inf")
for A in range(1,int((N**0.5))+1,1):
    if N%A!=0:
        continue
    B = N//A
    keta_A = len(str(A))
    keta_B = len(str(B))
    if keta_A >= keta_B:
        if keta_A<min:
            min = keta_A
        continue
    else:
        if keta_B<min:
            min = keta_B
print(min)

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

min = float('inf')

for i in range(1, int(N**0.5), 1):
    if N%i==0:
        A = i
        B = N//i
        keta = max(len(str(A)), len(str(B)))
        if keta<min:
            min = keta

print(keta)
Problem p03834 (python)

Fixed submission:
l = input().split(",")

print(*l)

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

print(l[1], l[0])
Problem p02659 (python)

Fixed submission:
A,B = map(str,input().split())
A = int(A)
B = int(B.replace(".",""))
ans = A*B//100
print(ans)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = input()
C = (B[0]-'0')*100+(B[2]-'0')*10+(B[3]-'0')
ans = A*C/100
print(ans)
Problem p02860 (python)

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

ans = 1
if N % 2:
  ans = 0
else:
  for i in range(N//2):
    if S[i] != S[N//2 + i]:
      ans = 0
if ans:
  print("Yes")
else:
  print("No")

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

if N % 2 == 1:
  print("No")
  return
for i in range(N/2):
  if S[i] != S[N/2 + i]:
    print("No")
    return
print("Yes")

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

if N % 2:
  print("No")
else:
  for i in range(N/2):
    if S[i] != S[N/2 + i]:
      print("No")
      return
  print("Yes")
Problem p02881 (python)

Fixed submission:
import math

ans = 1000000000000000000
N = int(input())
for i in range(math.ceil(math.sqrt(N+1000))):
  if i > 0 and N % i == 0:
    ans = min(i + N/i - 2, ans)
print(int(ans))

Buggy submission (verdict: Runtime Error):
import math

ans = 1000000000000000000
N = int(input())
for i in range(math.sqrt(N+1000)):
  if i > 0 and N % i == 0:
    ans = min(i + N/i - 2, ans)
print(ans)
Problem p03137 (python)

Fixed submission:
n,m = list(map(int, input().split()))
a=list(map(int, input().split()))
a.sort()
d=[a[i+1]-a[i] for i in range(m-1)]
d.sort()
print(sum(d[:m-n]) if m>n else 0)

Buggy submission (verdict: Runtime Error):
n,m = list(map(int, input().split()))
a=list(map(int, input().split()))
a.sorted()
d=[a[i+1]-a[i] for i in range(m-1)]
d.sorted()
print(sum(d[:m-n]) if m>n else 0)

Buggy submission (verdict: Runtime Error):
n,m = list(map(int, input().split()))
a=list(map(int, input().split()))
a.sorted()
d=[a[i+1]-a[i] for i in range(n-1)]
d.sorted()
print(sum(d[:m-n]) if m>n else 0)

Buggy submission (verdict: Runtime Error):
n,m = list(map(int, input().split()))
a=list(map(int, input().split()))
a.sorted()
d=[a[i+1]-a[i] for i in range(n)]
d.sorted()
print(sum(d[:m-n]) if m>n else 0)
Problem p02577 (python)

Fixed submission:
n=int(input())
l=[int(x) for x in list(str(n))]
result=sum(l)
if result%9==0:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
from decimal import Decimal
n=int(input())
n=Decimal(n)
if n%9==0:
  print('Yes')
else:
  print('No')
Problem p02659 (python)

Fixed submission:
from decimal import Decimal
import math
a,b = map(Decimal,input().split())
ans = a*b
print(math.floor(ans))

Buggy submission (verdict: Runtime Error):
import math
from decimal import *
A,B=input().strip().split()
C=Decimal(A)
D=Decimal(B)
result=math.floor(A*B)
print(result)

Buggy submission (verdict: Runtime Error):
import math
from decimal import *
A,B=input().strip().split()
A,B=[int(A),float(B)]
A=Decimal("A")
B=Decimal("B")
result=math.floor(A*B)
print(result)

Buggy submission (verdict: Runtime Error):
import math 
A,B=input().split()
A,B=[int(A),float(B)]
B=B[:3]
if 0<=A<=10**15 and 0<=B<10:
    result=A*B
    result=int(math.floor(result))
    print(result)

Buggy submission (verdict: Runtime Error):
from decimal import *
A, B = input().strip().split()
A, B = [int(A), float(B)]
if A>=0 and A<=10**15:
    if B>=0 and B<10 :
        Decimal(str(B)).quantize(Decimal('0.01'),round(ROUND_DOWN))
        result=A*B
        new=round(result)
        print(new)
Problem p02597 (python)

Fixed submission:
from collections import Counter


N = int(input())
C = input()
C_cntr = Counter(C)

all_R_cnt = 0
all_W_cnt = 0
R_W_cnt = 0
for i in range(N):
    if C[i] == "W":
        all_R_cnt += 1
    elif C[i] == "R":
        all_W_cnt += 1
    if i < C_cntr.get("R", 0) and C[i] == "W":
        R_W_cnt += 1

print(min(all_R_cnt, all_W_cnt, R_W_cnt))

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


N = int(input())
C = input()
C_cntr = Counter(C)

ans = 0
for i in range(C_cntr["R"]):
　if C[i] == "W":
        ans += 1

print(ans)
Problem p02598 (python)

Fixed submission:
def is_good(mid, key):
    return sum(count_cuts(a, mid) for a in A) <= key


def binary_search(key):
    bad, good = 0, 2 * 10 ** 14 + 1
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


def count_cuts(a, unit):
    return (a + unit - 1) // unit - 1


N, K, *A = map(int, open(0).read().split())
print(binary_search(K))

Buggy submission (verdict: Runtime Error):
def is_good(mid, key):
    res = 0
    for a in A:
        res += (a + mid - 1) // mid - 1
    return res <= key


def binary_search(bad, good, key):
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


N, K, *A = map(int, open(0).read().split())
print(binary_search(-1, 1_000_000_000, K))
Problem p02679 (python)

Fixed submission:
from collections import defaultdict
from math import gcd


MOD = 1000000007
N = int(input())
both_zeros_cnt = 0
bads = defaultdict(lambda: [0, 0])
for _ in range(N):
    A, B = map(int, input().split())
    if A == 0 and B == 0:
        both_zeros_cnt += 1
        continue
    if B < 0 or (B == 0 and A < 0):
        A, B = -A, -B
    g = gcd(A, B)
    A, B = A // g, B // g
    if A > 0:
        bads[(A, B)][0] += 1
    else:
        bads[(B, -A)][1] += 1

ans = 1
for k, l in bads.values():
    ans *= (pow(2, k, MOD) - 1) + (pow(2, l, MOD) - 1) + 1
    ans %= MOD
print((ans + both_zeros_cnt - 1) % MOD)

Buggy submission (verdict: Runtime Error):
from math import gcd
from collections import defaultdict


def cmb(n, r):
    return (fac[n] * pow(fac[r], p - 2, p) * pow(fac[n - r], p - 2, p)) % p


p = 1000000007
fac = [1] * (2 * 10 ** 6 + 1)
for i in range(1, 2 * 10 ** 6 + 1):
    fac[i] = (fac[i - 1] * i) % p


N = int(input())

AB = defaultdict(int)
for i in range(N):
    a, b = map(int, input().split())
    g = gcd(a, b)
    AB[(a // g, b // g)] += 1

bad_pairs_cnt = 0
for a, b in AB:
    bad_pairs_cnt += AB[(a, b)] * (AB.get((-b, a), 0) + AB.get((b, -a), 0))

ans = N
for i in range(2, N + 1):
    b = cmb(N, 2) - bad_pairs_cnt * (N ** (i - 1))
    if b <= 0:
        break
    ans += b
    ans %= p
print(ans)
Problem p02762 (python)

Fixed submission:
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 same(self, x, y):
        return self.find(x) == self.find(y)

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


if __name__ == "__main__":
    n, m, k = map(int, input().split())

    u = UnionFind(n)
    f_cnt = [0] * n
    b_cnt = [0] * n

    for _ in range(m):
        a, b = map(int, input().split())
        u.union(a - 1, b - 1)
        f_cnt[a - 1] += 1
        f_cnt[b - 1] += 1

    for _ in range(k):
        c, d = map(int, input().split())
        if u.same(c - 1, d - 1):
            b_cnt[c - 1] += 1
            b_cnt[d - 1] += 1

    print(*[(u.size(i) - f_cnt[i] - b_cnt[i] - 1) for i in range(n)])

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


def dfs(graph, start):
    visited, stack = set(), [start]
    while stack:
        vertex = stack.pop()
        if vertex not in visited:
            visited.add(vertex)
            stack.extend(graph[vertex] - visited)
    return visited


if __name__ == "__main__":
    n, m, k = map(int, input().split())
    AB = [map(int, input().split()) for _ in range(m)]
    CD = [map(int, input().split()) for _ in range(k)]

    graph_f = defaultdict(set)
    graph_b = defaultdict(set)

    for a, b in AB:
        graph_f[a - 1].add(b - 1)
        graph_f[b - 1].add(a - 1)

    for c, d in CD:
        graph_b[c - 1].add(d - 1)
        graph_b[d - 1].add(c - 1)

    visited = set()
    conns = {}
    for i in range(n):
        if i not in visited:
            conn = dfs(graph_f, i)
            visited |= {i} | conn
            conns = {**conns, **{j: conn for j in conn}}

    print(' '.join([str(len(conns[i] - graph_f[i] - graph_b[i]) - 1) for i in range(n)]))
Problem p02891 (python)

Fixed submission:
S = input()
K = int(input())
prev = S[0]
compressed = [[prev, 1]]
for c in S[1:]:
    if c == compressed[-1][0]:
        compressed[-1][1] += 1
    else:
        compressed.append([c, 1])
if len(compressed) == 1:
    print(len(S) * K // 2)
else:
    ans = sum(cnt // 2 for _, cnt in compressed) * K
    if S[0] == S[-1]:
        tmp = (compressed[0][1] + compressed[-1][1]) // 2
        tmp -= compressed[0][1] // 2
        tmp -= compressed[-1][1] // 2
        ans += tmp * (K - 1)
    print(ans)

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

i = 0
T = []
U = []
while i <= N - 1:
    if i == N - 1:
        T.append(S[-1])
        if S[-2] == S[-1]:
            U.append("?")
        else:
            U.append(S[-1])
        break
    if S[i] == S[i + 1]:
        T.append(S[i] + "?")
        U.append("?" + S[i])
        i += 2
    else:
        T.append(S[i])
        U.append(S[i])
        i += 1

T = "".join(T)
U = "".join(U)
if T[0] == T[-1]:
    print((K + 1) // 2 * T.count("?") + K // 2 * U.count("?"))
else:
    print(K * T.count("?"))
Problem p02912 (python)

Fixed submission:
from heapq import heapify, heappop, heappush


N, M = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))
if N == 1:
    print(N >> M)
    exit()
heapify(A)
while M > 0:
    a = -heappop(A)
    while M > 0 and a >= -A[0]:
        a >>= 1
        M -= 1
    heappush(A, -a)
print(-sum(A))

Buggy submission (verdict: Runtime Error):
from heapq import heapify, heappop, heappush


N, M = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))
if N == 1:
    print(N >> M)
    exit()
heapify(A)
for i in range(M):
    a = -heappop(A)
    while a >= -A[0]:
        a >>= 1
    heappush(A, -a)
    print(A)
print(-sum(A))