Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
def luca(n):
    if n == 0:
        return 2
    elif n == 1:
        return 1
    else:
        return luca(n-1)+luca(n-2)
print(luca(N))

Fixed submission:
from functools import lru_cache
N = int(input())
@lru_cache(maxsize=1000)
def luca(n):
    if n == 0:
        return 2
    elif n == 1:
        return 1
    else:
        return luca(n-1)+luca(n-2)
print(luca(N))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
def Lucas(n):
    if n == 0:
        return 2
    elif n == 1:
        return 1
    else:
        one = Lucas(n-1)
        two = Lucas(n-2)
        return one+two
print(Lucas(N))

Fixed submission:
from functools import lru_cache
N = int(input())
@lru_cache(maxsize=1000)
def luca(n):
    if n == 0:
        return 2
    elif n == 1:
        return 1
    else:
        return luca(n-1)+luca(n-2)
print(luca(N))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
def Lucas(n):
    if n == 0:
        return 2
    elif n == 1:
        return 1
    else:
        return Lucas(n-1)+Lucas(n-2)
print(Lucas(N))

Fixed submission:
from functools import lru_cache
N = int(input())
@lru_cache(maxsize=1000)
def luca(n):
    if n == 0:
        return 2
    elif n == 1:
        return 1
    else:
        return luca(n-1)+luca(n-2)
print(luca(N))
Buggy python submission (verdict: Runtime Error):
N,Z,W = map(int,input().split())
a = list(map(int,input().split()))
A = abs(a[-1]-W)
B = abs(a[-2]-a[-1])
print(max(A,B))

Fixed submission:
N,Z,W = map(int,input().split())
a = list(map(int,input().split()))
A = abs(a[-1]-W)
if N == 1:
    print(A)
else:
    B = abs(a[-2]-a[-1])
    print(max(A,B))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
count = 0
for i in range(N):
    a = A[i]
    for j in range(N):
        if B[j] > a:
            b = B[j]
            for k in range(N):
                if C[k] > b:
                    count+=(N-k)
                    break
                else:
                    pass
print(count)

Fixed submission:
#C
import bisect
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()

bi = [0 for i in range(N)]
for i in range(N):
    b = B[i]
    c = bisect.bisect_right(C,b)
    bi[i]+=(N-c)

S = sum(bi)
rui = [0]
for bii in bi:
    rui.append(rui[-1]+bii)

rui = rui[::-1]
ans = 0
for i in range(N):
    a = A[i]
    ind = bisect.bisect_right(B,a)
    #print(ind,rui[N-ind])
    ans+=(S-rui[N-ind])

    
    
print(ans)
#print(rui)
Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
f = list(str(input()) for i in range(H))

for i in range(H):
  for j in range(W):
    if f[i][j] == "#":
      continue
    
    count = 0
    if i > 0 and j > 0:
      if f[i-1][j-1] == "#":
        count+=1
    if i > 0:
      if f[i-1][j] == "#":
        count+=1
    if i > 0 and j < W-1:
      if f[i-1][j+1] == "#":
        count+=1
    if j > 0:
      if f[i][j-1] == "#":
        count+=1
    if j < W-1:
      if f[i][j+1] == "#":
        count+=1
    if i < H-1 and j > 0:
      if f[i+1][j-1] == "#":
        count+=1
    if i < H-1:
      if f[i+1][j] == "#":
        count+=1
    if i < H-1 and j < W-1:
      if f[i+1][j+1] == "#":
        count+=1
    
    f[i][j] = str(count)
    
for i in range(H):
  print(f[i])
    

Fixed submission:
H,W = map(int,input().split())
f = list(list(str(input())) for i in range(H))

for i in range(H):
  for j in range(W):
    if f[i][j] == "#":
      continue
    
    count = 0
    if i > 0 and j > 0:
      if f[i-1][j-1] == "#":
        count+=1
    if i > 0:
      if f[i-1][j] == "#":
        count+=1
    if i > 0 and j < W-1:
      if f[i-1][j+1] == "#":
        count+=1
    if j > 0:
      if f[i][j-1] == "#":
        count+=1
    if j < W-1:
      if f[i][j+1] == "#":
        count+=1
    if i < H-1 and j > 0:
      if f[i+1][j-1] == "#":
        count+=1
    if i < H-1:
      if f[i+1][j] == "#":
        count+=1
    if i < H-1 and j < W-1:
      if f[i+1][j+1] == "#":
        count+=1
    
    f[i][j] = str(count)

for i in range(H):
  n = ""
  for j in range(W):
    n+=f[i][j]
  print(n)
Buggy python submission (verdict: Time Limit Exceeded):
#C問題
N = int(input())

M = 3500
flag = 0
for k in range(1,3500):
    for h in range(1,3500):
        bunbo = 4*k*h-k*N-h*N
        bunshi = N*k*h
        if bunbo != 0 and bunshi%bunbo == 0:
            w = bunshi//bunbo
            if w >= 0:
            	print(k,h,w)
            	flag = 1
            	break
    if flag == 1:
        break
            


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

M = 3500
flag = 0
for k in range(1,3500):
    for h in range(1,3500):
        bunbo = 4*k*h-k*N-h*N
        bunshi = N*k*h
        if bunbo != 0 and bunshi%bunbo == 0:
            w = bunshi//bunbo
            if w >= 0:
            	print(k,h,w)
            	flag = 1
            	break
    if flag == 1:
        break
Buggy python submission (verdict: Time Limit Exceeded):
#D問題
import copy

N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
G = copy.deepcopy(A)
whole = 0
for i in range(N):
    for j in range(N):
        whole+=A[i][j]


#print(A,G)
#warshall_floyd法
def warshall_floyd(dist):
    global N
    #dist[i][j]: iからjへの最短距離
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j])

warshall_floyd(G)
#print(A,G)

flag = 0
ans = 0
for i in range(N):
    for j in range(N):
        if A[i][j] != G[i][j]:
            flag = 1
        else:
            for k in range(N):
                if k != i and k != j:
                    #print(G[i][j],G[i][k]+G[k][j])
                    if G[i][j] == G[i][k] + G[k][j]:
                        ans+=A[i][j]
                        #print(A[i][j])
                        break
                
            
if flag == 1:
    print(-1)
else:
    print((whole-ans)//2)

Fixed submission:
#D問題
import copy

N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
G = copy.deepcopy(A)
whole = 0
for i in range(N):
    for j in range(N):
        whole+=A[i][j]


#print(A,G)
#warshall_floyd法
def warshall_floyd(dist):
    global N
    #dist[i][j]: iからjへの最短距離
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j])

warshall_floyd(G)
#print(A,G)

flag = 0
ans = 0
for i in range(N):
    for j in range(N):
        if A[i][j] != G[i][j]:
            flag = 1
        else:
            for k in range(N):
                if k != i and k != j:
                    #print(G[i][j],G[i][k]+G[k][j])
                    if G[i][j] == G[i][k] + G[k][j]:
                        ans+=A[i][j]
                        #print(A[i][j])
                        break
                
            
if flag == 1:
    print(-1)
else:
    print((whole-ans)//2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for i in range(N)]
kami = []
for i in range(N):
    if A[i] in kami:
        kami.remove(A[i])
    else:
        kami.append(A[i])
print(len(kami))

Fixed submission:
import collections
N = int(input())
A = [int(input()) for i in range(N)]
acount = collections.Counter(A)
a = acount.most_common()
count = 0
alen = len(a)
for j in range(alen):
    if a[j][1]%2 == 1:
        count+=1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
#D問題

#warshall_floyd法
def warshall_floyd(dist):
    #dist[i][j]: iからjへの最短距離
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j])
    return dist

N,M,R=map(int,input().split())
r=list(map(int,input().split()))

dist = [[float("inf") for i in range(N)] for i in range(N)] 
#dist[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(M):
    a,b,c = map(int,input().split())
    dist[a-1][b-1] = c
    dist[b-1][a-1] = c
for i in range(N):
    dist[i][i] = 0 #自身のところに行くコストは０
dist=warshall_floyd(dist)

ever=[]
MIN=10000000
def ans_func(ever):
    global R
    global r
    global dist
    global MIN
    
    if len(ever) == R:
        if R == 2:
            kari=dist[ever[0]][ever[1]]
            MIN=min(MIN,kari)
        else:
            kari=0
            for i in range(R-1):
                kari+=dist[ever[i]][ever[i+1]]
            MIN=min(MIN,kari)
    else:
        i=0
        for i in range(R):
            if r[i]-1 in ever:
                pass
            else:
                ever.append(r[i]-1)
                ans_func(ever)
                ever.remove(r[i]-1)
    return
ans_func(ever)
print(MIN)
    

Fixed submission:
#D問題

#warshall_floyd法
def warshall_floyd(dist):
    #dist[i][j]: iからjへの最短距離
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j])
    return dist

N,M,R=map(int,input().split())
r=list(map(int,input().split()))

dist = [[float("inf") for i in range(N)] for i in range(N)] 
#dist[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(M):
    a,b,c = map(int,input().split())
    dist[a-1][b-1] = c
    dist[b-1][a-1] = c
for i in range(N):
    dist[i][i] = 0 #自身のところに行くコストは０
dist=warshall_floyd(dist)

ever=[]
MIN=100000000
def ans_func(ever):
    global R
    global r
    global dist
    global MIN
    
    if len(ever) == R:
        if R == 2:
            kari=dist[ever[0]][ever[1]]
            MIN=min(MIN,kari)
        else:
            kari=0
            for i in range(R-1):
                kari+=dist[ever[i]][ever[i+1]]
            MIN=min(MIN,kari)
    else:
        i=0
        for i in range(R):
            if r[i]-1 in ever:
                pass
            else:
                ever.append(r[i]-1)
                ans_func(ever)
                ever.remove(r[i]-1)
    return
ans_func(ever)
print(MIN)
Buggy python submission (verdict: Time Limit Exceeded):
#D問題
A = list(str(input()))
N = len(A)

left = ""
right = ""
count = 0
for i in range(N):
    I = i
    left = A[I]
    for j in range(N-i-1):
        J = i+j+1
        right = A[J]
        if left == right:
            count+=1
            
ans = 1
for i in range(N):
    if i == 0:
        pass
    else:
        ans+=(N-i)
#print(ans,count)
ans-=count
print(ans)


Fixed submission:
#D問題
A = list(str(input()))
N = len(A)

used = []
count = 0
for a in A:
    if a not in used:
        used.append(a)
        c = A.count(a)
        count+=(c*(c-1)//2)
            
ans = 1
for i in range(N):
    if i == 0:
        pass
    else:
        ans+=(N-i)
#print(ans,count)
ans-=count
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#D問題
A = list(str(input()))
N = len(A)

left = ""
right = ""
count = 0
for i in range(N):
    I = i
    left = A[I]
    for j in range(N-i-1):
        J = i+j+1
        right = A[J]
        if left == right:
            count+=1
            
ans = 1
for i in range(N):
    if i == 0:
        pass
    else:
        ans+=(N-i)
#print(ans,count)
ans-=count
print(ans)


Fixed submission:
#D問題
A = list(str(input()))
N = len(A)

used = []
count = 0
for a in A:
    if a not in used:
        used.append(a)
        c = A.count(a)
        count+=(c*(c-1)//2)
            
ans = 1
for i in range(N):
    if i == 0:
        pass
    else:
        ans+=(N-i)
#print(ans,count)
ans-=count
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(M)]
flag = 0
for i in range(M):
    if ab[i][0] == 1:
        j = 0
        for j in range(M):
            if ab[j] == [ab[i][1],N]:
                print("POSSIBLE")
                flag = 1
                break
    if flag == 1:
        break
if flag == 0:
    print("IMPOSSIBLE")

Fixed submission:
N,M = map(int,input().split())
voy = [[] for i in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    voy[a-1].append(b)
alen = len(voy[0])
flag = 0
for j in range(alen):
    qu = voy[0][j]-1
    if N in voy[qu]:
        print("POSSIBLE")
        flag = 1
        break
if flag == 0:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int,input().split()))
SUM = sum(a)
MIN = 10**10
for i in range(N-1):
    suma = 0
    for j in range(i+1):
        suma+=a[j]
    kari = abs(SUM-2*suma)
    MIN = min(MIN,kari)
print(MIN)

Fixed submission:
def solve(N,a):
    suma = 0
    SUM = sum(a)
    MIN = 10**15
    for i in a[:(N-1)]:
        suma+=i
        MIN = min(MIN,abs(2*suma-SUM))
    return abs(MIN)

if __name__ == "__main__":
    N = int(input())
    a = list(map(int,input().split()))
    print(solve(N,a))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int,input().split()))
SUM = sum(a)
MIN = 10**10
for i in range(N-1):
    suma = sum(a[:i+1])
    kari = abs(SUM-2*suma)
    MIN = min(MIN,kari)
print(MIN)

Fixed submission:
def solve(N,a):
    suma = 0
    SUM = sum(a)
    MIN = 10**15
    for i in a[:(N-1)]:
        suma+=i
        MIN = min(MIN,abs(2*suma-SUM))
    return abs(MIN)

if __name__ == "__main__":
    N = int(input())
    a = list(map(int,input().split()))
    print(solve(N,a))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int,input().split()))
SUM = sum(a)
MIN = 10**10
for i in range(N-1):
    suma = sum(a[:i+1])
    sumb = SUM-suma
    kari = abs(suma-sumb)
    MIN = min(MIN,kari)
print(MIN)

Fixed submission:
def solve(N,a):
    suma = 0
    SUM = sum(a)
    MIN = 10**15
    for i in a[:(N-1)]:
        suma+=i
        MIN = min(MIN,abs(2*suma-SUM))
    return abs(MIN)

if __name__ == "__main__":
    N = int(input())
    a = list(map(int,input().split()))
    print(solve(N,a))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
alist = list(map(int,input().split()))
b = []
for i in range(n):
    if i%2 == 0:
        front = int(i/2)
        b.insert(front,alist[-1-i])
    else:
        if i!=1:
            back = -int((i-1)/2)
            b.insert(back,alist[-1-i])
        else:
            b.append(alist[-1-i])
for j in range(n):
    print(b[j],end=" ")

Fixed submission:
#C問題
N = int(input())
A = list(map(int,input().split()))
if N%2 == 0:
    front = []
    back = []
    for i in range(N):
        if i%2 == 1:
            front.append(A[i])
        else:
            back.append(A[i])
    front = front[::-1]
    for i in range(N//2):
        print(front[i],end=" ")
    for i in range(N//2):
        print(back[i],end=" ")
        
else:
    front = []
    back = []
    for i in range(N):
        if i%2 == 0:
            front.append(A[i])
        else:
            back.append(A[i])
    front = front[::-1]
    for i in range(N//2 + 1):
        print(front[i],end=" ")
    for i in range(N//2):
        print(back[i],end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
alist = list(map(int,input().split()))
b = []
c = []
for i in range(n):
    b.append(alist[i])
    blen = len(b)
    c = b[::-1]
    b = [c[j] for j in range(blen)]
    c = []        
blen = len(b)
for k in range(blen):
    print(b[k],end=" ")

Fixed submission:
#C問題
N = int(input())
A = list(map(int,input().split()))
if N%2 == 0:
    front = []
    back = []
    for i in range(N):
        if i%2 == 1:
            front.append(A[i])
        else:
            back.append(A[i])
    front = front[::-1]
    for i in range(N//2):
        print(front[i],end=" ")
    for i in range(N//2):
        print(back[i],end=" ")
        
else:
    front = []
    back = []
    for i in range(N):
        if i%2 == 0:
            front.append(A[i])
        else:
            back.append(A[i])
    front = front[::-1]
    for i in range(N//2 + 1):
        print(front[i],end=" ")
    for i in range(N//2):
        print(back[i],end=" ")
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())
if A > B:
  print("GREATER")
elif A < B:
  print("LESS")
else:
  print("EQUAL")

Fixed submission:
A = int(input())
B = int(input())
if A > B:
  print("GREATER")
elif A < B:
  print("LESS")
else:
  print("EQUAL")
Buggy python submission (verdict: Time Limit Exceeded):
#C問題
import sys
sys.setrecursionlimit(500000)
N,M = map(int,input().split())
ab=[list(map(int,input().split())) for i in range(M)]
reach=[-1]*(N)
reach[0]=0
ans=0
def cdfs(n):
    global ans
    global reach
    if sum(reach)==0:
        ans+=1
        reach=[-1]*(N)
        reach[0]=0
        return
    else:
        for j in range(N):
            if reach[j] == -1 and ([n+1,j+1] in ab or [j+1,n+1] in ab):
                reach[j] = 0
                cdfs(j)
                reach[j] = -1
            else:
                pass
        return
reach[0]=0
cdfs(0)
print(ans)
    

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

path = [(i+1) for i in range(N)]
p_list = list(itertools.permutations(path,N))

ans = 0
for pl in p_list:
    if pl[0] == 1:
        flag = 0
        for i in range(N-1):
            ab1 = [pl[i],pl[i+1]]
            ab2 = [pl[i+1],pl[i]]
            if ab1 in AB or ab2 in AB:
                pass
            else:
                flag = 1
                break
        if flag == 0:
            ans+=1
            
print(ans)

Buggy python submission (verdict: Runtime Error):
#C問題
N,M = map(int,input().split())
ab=[list(map(int,input().split())) for i in range(M)]
reach=[-1]*(N)
reach[0]=0
ans=0
def cdfs(n):
    global ans
    global reach
    if sum(reach)==0:
        ans+=1
        reach=[-1]*(N)
        reach[0]=0
        return
    else:
        for j in range(N):
            if reach[j] == -1 and ([n+1,j+1] in ab or [j+1,n+1] in ab):
                reach[j] = 0
                cdfs(j)
                reach[j] = -1
            else:
                pass
        return
reach[0]=0
cdfs(0)
print(ans)
    

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

path = [(i+1) for i in range(N)]
p_list = list(itertools.permutations(path,N))

ans = 0
for pl in p_list:
    if pl[0] == 1:
        flag = 0
        for i in range(N-1):
            ab1 = [pl[i],pl[i+1]]
            ab2 = [pl[i+1],pl[i]]
            if ab1 in AB or ab2 in AB:
                pass
            else:
                flag = 1
                break
        if flag == 0:
            ans+=1
            
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split(" "))
a = 0
ans = 0
while a <= K:
  b = 0
  while b <= K:
    c = S-a-b
    if c <= K and c >= 0:
       ans+=1
    b += 1
  a+=1
print(ans)

Fixed submission:
#B問題
K,S=map(int,input().split())
count=0
for y in range(K+1):
    x=0
    for x in range(K+1):
        z=S-(x+y)
        if z <= K and z >= 0:
            count+=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split(" "))
a = 0
ans = 0
while a <= K:
  b = 0
  while b <= K:
    if S-(a+b) <= K and S-(a+b) >= 0:
       ans+=1
    b += 1
  a+=1
print(ans)

Fixed submission:
#B問題
K,S=map(int,input().split())
count=0
for y in range(K+1):
    x=0
    for x in range(K+1):
        z=S-(x+y)
        if z <= K and z >= 0:
            count+=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split(" "))
a = 0
ans = 0
while a <= K:
  b = 0
  while b <= K:
    if S-(a+b) <= K and S-(a+b) >= 0:
       ans+=1
    b += 1
  a+=1
print(ans)

Fixed submission:
#B問題
K,S=map(int,input().split())
count=0
for y in range(K+1):
    x=0
    for x in range(K+1):
        z=S-(x+y)
        if z <= K and z >= 0:
            count+=1
print(count)
Buggy python submission (verdict: Runtime Error):
#C問題
S=str(input())
Slist=list(S)
Slen=len(Slist)
Srev=Slist[::-1]
kari=""
for i in range(Slen):
    if len(kari) == 5:
        if kari == "maerd":
            kari=Srev[i]
        elif kari == "esare":
            kari=Slev[i]
        else:
            kari+=Srev[i]
    elif len(kari) == 6:
        if kari == "resare":
            kari=Srev[i]
        else:
            kari+=Srev[i]
    elif len(kari) == 7:
        if kari == "remaerd":
            kari=Srev[i]
        else:
            break
    else:
        kari+=Srev[i]
if kari == "esare" or kari == "maerd" or kari == "resare" or kari == "remaerd":
    print("YES")
else:
    print("NO")

Fixed submission:
#C問題
S=str(input())
Slist=list(S)
Slen=len(Slist)
Srev=Slist[::-1]
kari=""
for i in range(Slen):
    if len(kari) == 5:
        if kari == "maerd":
            kari=Srev[i]
        elif kari == "esare":
            kari=Srev[i]
        else:
            kari+=Srev[i]
    elif len(kari) == 6:
        if kari == "resare":
            kari=Srev[i]
        else:
            kari+=Srev[i]
    elif len(kari) == 7:
        if kari == "remaerd":
            kari=Srev[i]
        else:
            break
    else:
        kari+=Srev[i]
if kari == "esare" or kari == "maerd" or kari == "resare" or kari == "remaerd":
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
#C問題
#UnionFind
def find(A,x):
    p = A[x]
    if p == x:
        return x
    a = find(A,p)
    A[x] = a
    return a
 
def union(A, x, y):
    if find(A,x) > find(A,y):
        bx, by = find(A,y), find(A,x)
    else:
        bx, by = find(A,x), find(A,y)
    A[y] = bx
    A[by] = bx

import heapq

H,W = map(int,input().split())
PQ = []
for i in range(W+H+1):
    if i == W:
        continue
    pq = int(input())
    heapq.heappush(PQ,[pq,i,i+1])


uf = UnionFind(H+W+2)
a = W+1
b = H+1
ans = 0
V = [i for i in range(H+W+2)]

while PQ:
    edge = heapq.heappop(PQ)
    w,s,t = edge[0],edge[1],edge[2]
    if find(V,s) != find(V,t):
        union(V,s,t)
        if s < W+1: #P
            ans+=w*b
            a-=1
        else:#Q
            ans+=w*a
            b-=1
            
print(ans)



Fixed submission:
#C問題
#UnionFind
def find(A,x):
    p = A[x]
    if p == x:
        return x
    a = find(A,p)
    A[x] = a
    return a
 
def union(A, x, y):
    if find(A,x) > find(A,y):
        bx, by = find(A,y), find(A,x)
    else:
        bx, by = find(A,x), find(A,y)
    A[y] = bx
    A[by] = bx

import heapq

W,H = map(int,input().split())
PQ = []
for i in range(W+H+1):
    if i == W+1:
        continue
    pq = int(input())
    heapq.heappush(PQ,[pq,i,i+1])

#print(PQ)
w = W+1
h = H+1
ans = 0
V = [i for i in range(H+W+2)]

while PQ:
    e,s,t = heapq.heappop(PQ)
    if find(V,s) != find(V,t):
        union(V,s,t)
        if s < W: #P
            ans+=(e*h)
            w-=1
        else:#Q
            ans+=(e*w)
            h-=1
            
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
if s[2]=s[3] and s[4]=s[5]:
    print("Yes")
else:
    print("No")    

Fixed submission:
s=input()
if s[2]==s[3] and s[4]==s[5]:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
s=input()
if s[2]=s[3]ands[4]=s[5]:
    print("Yes")
else:
    print("No")    

Fixed submission:
s=input()
if s[2]==s[3] and s[4]==s[5]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
X = int(input())

A = 0
B = 0
test = 10**3
for i in range(-test, test):
	a = (X + i**5)**0.2
	if type(a) == float:
		if round(a, 10).is_integer():
			# print(int(a), i)
			A, B = int(a), i
			break
print(A, B)

Fixed submission:
S = input()

if "B" in S:
  print(S.replace("B", "R"))
elif "R" in S:
  print(S.replace("R", "B"))