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

Fixed submission:
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

key = []
for i, v in enumerate(A):
    for k, j in enumerate(v):
        if (j in B):
            key.append([i, k])

ans = [[[0, 0], [1, 0], [2, 0]], [[0, 1], [1, 1], [2, 1]], [[0, 2], [1, 2], [2, 2]], [[0, 0], [1, 1], [2, 2]], [
    [0, 2], [1, 1], [2, 0]], [[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]], [[2, 0], [2, 1], [2, 2]]]

for i in ans:
    count = 0
    for j in i:
        if (j in key):
            count += 1
    if (count == 3):
        print('Yes')
        exit()

print('No')

Buggy submission (verdict: Runtime Error):
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

key = []
for i, v in enumerate(A):
    for k, j in enumerate(v):
        if (j in B):
            key.append([i, k])

ans = [[[0, 0], [1, 0], [2, 0]], [[0, 1], [1, 1], [2, 1]], [[0, 2], [1, 2], [2, 2]], [[0, 0], [1, 1], [2, 2]], [
    [0, 2], [1, 1], [2, 0]], [[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]], [[2, 0], [2, 1], [2, 2]]]

for i in ans:
    for j in i:
        if (j in key.sort()):
            print('Yes')
            exit()

print('No')
Problem p02917 (python)

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

ans = B[0] + B[-1]
for i in range(1, N - 1):
    ans += min(B[i], B[i - 1])

print(ans)

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

L = B[:]
for i in range(N - 1):
    if (i >= N - 2):
        break
    elif (i == 0 and B[0] > B[1]):
        p = L.pop(0)
        L.append(p)
    elif (B[i] > B[i + 1]):
        L.pop(i)

if (len(L) == 1):
    print(sum(B) * 2)
else:
    print(sum(L) + L[-2])

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

L = B[:]
for i in range(N - 1):
    if (i >= N - 2):
        break
    elif (i == 0 and B[0] > B[1]):
        p = L.pop(0)
        L.append(p)
    elif (B[i] > B[i + 1]):
        L.pop(i)

print(L)
if (len(L) == 1):
    print(sum(B) * 2)
else:
    print(sum(L) + L[-2])

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

L = B[:]
for i in range(N - 1):
    if (i >= N - 2):
        break
    elif (B[i] > B[i + 1]):
        L.pop(i)

if (len(B) == 1):
    print(sum(B) * 2)
else:
    print(sum(L) + L[-2])
Problem p02936 (python)

Fixed submission:
from collections import deque
n, q = map(int, input().split())

road = [[] for _ in range(n)]
cnt = [0 for _ in range(n)]

for i in range(n - 1):
    a, b = map(int, input().split())
    road[a - 1].append(b - 1)
    road[b - 1].append(a - 1)

for i in range(q):
    idx, v = map(int, input().split())
    cnt[idx - 1] += v

dist = [-1] * n
que = deque()
dist[0] = 0
que.append(0)

while(len(que) != 0):
    # BFS/DFS
    v = que.pop()
    for r in road[v]:
        if dist[r] != -1:
            continue
        # print(r, v)
        dist[r] = dist[v] + 1
        cnt[r] += cnt[v]
        que.append(r)
print(*cnt)

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

road = [[] for _ in range(n)]
cnt = [0 for _ in range(n)]

for i in range(n - 1):
    a, b = map(int, input().split())
    road[a - 1].append(b - 1)
    road[b - 1].append(a - 1)

for i in range(q):
    idx, v = map(int, input().split())
    cnt[idx - 1] += v

dist = [-1] * n
que = deque()
dist[0] = 0
que.append(0)

while(len(que) != 0):
    # BFS/DFS
    v = que.pop()
    for r in road[v]:
        if dist[r] != -1:
            continue
        # print(r, v)
        dist[r] = dist[v] + 1
        cnt[r] += cnt[v]
        que.append(r)
print(*cnt)

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

road = [[] for _ in range(n)]
cnt = [0 for _ in range(n)]

for i in range(n - 1):
    a, b = map(int, input().split())
    road[a - 1].append(b - 1)
    road[b - 1].append(a - 1)

for i in range(q):
    idx, v = map(int, input().split())
    cnt[idx - 1] += v

dist = [-1] * n
que = deque()
dist[0] = 0
que.append(0)

while(len(que) != 0):
    # BFS/DFS
    v = que.pop()
    for r in road[v]:
        if dist[r] != -1:
            continue
        # print(r, v)
        dist[r] = dist[v] + 1
        print(cnt)
        cnt[r] += cnt[v]
        que.append(r)
print(*cnt)
Problem p02995 (python)

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


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(x, y):
    return (x * y) // gcd(x, y)


C_num = B // C - A // C

D_num = B // D - A // D

lcm = lcm(C, D)
CD_num = B // lcm - A // lcm


# Cで割れる時
tasu = 0
if (A % C == 0):
    tasu += 1
tasu += C_num

# Dで割れる時
if (A % D == 0):
    tasu += 1
tasu += D_num

# CでもDでも割れる
hiku = 0
if (A % lcm == 0):
    hiku += 1
hiku += CD_num

print((B - A + 1) - (tasu - hiku))

Buggy submission (verdict: Runtime Error):
import math

A, B, C, D = map(int, input().split())


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


C_num = B // C - A // C

D_num = B // D - A // D

lcm = lcm(C, D)
CD_num = B // lcm - A // lcm


# Cで割れる時
tasu = 0
if (A % C == 0):
    tasu += 1
tasu += C_num

# Dで割れる時
if (A % D == 0):
    tasu += 1
tasu += D_num

# CでもDでも割れる
hiku = 0
if (A % lcm == 0):
    hiku += 1
hiku += CD_num

print((B - A + 1) - (tasu - hiku))

Buggy submission (verdict: Runtime Error):
import math

A, B, C, D = map(int, input().split())


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


C_num = B // C - A // C

D_num = B // D - A // D

lcm = lcm(C, D)
CD_num = B // lcm - A // lcm


# Cで割れる時
tasu = 0
if (A % C == 0):
    tasu += 1
tasu += C_num

# Dで割れる時
if (A % D == 0):
    tasu += 1
tasu += D_num

# CでもDでも割れる
hiku = 0
if (A % (lcm(C, D)) == 0):
    hiku += 1
hiku += CD_num

print((B - A + 1) - (tasu - hiku))

Buggy submission (verdict: Runtime Error):
import math

A, B, C, D = map(int, input().split())


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


Csita = A // C
Cue = B // C

Dsita = A // D
Due = B // D

CDsita = A // lcm(C, D)
CDue = B // lcm(C, D)


# Cで割れる時
tasu = 0
if (A % C == 0):
    tasu += 1
tasu += Cue - Csita

# Dで割れる時
if (A % D == 0):
    tasu += 1
tasu += Due - Dsita

# CでもDでも割れる
hiku = 0
if (A % (lcm(C, D)) == 0):
    hiku += 1
hiku += CDue - CDsita

print((B - A + 1) - (tasu - hiku))

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


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


Csita = A // C
Cue = B // C

Dsita = A // D
Due = B // D

CDsita = A // lcm(C, D)
CDue = B // lcm(C, D)


# Cで割れる時
tasu = 0
if (A % C == 0):
    tasu += 1
tasu += Cue - Csita

# Dで割れる時
if (A % D == 0):
    tasu += 1
tasu += Due - Dsita

# CでもDでも割れる
hiku = 0
if (A % (lcm(C, D)) == 0):
    hiku += 1
hiku += CDue - CDsita

print(B - A + 1 - (tasu - hiku))
Problem p03043 (python)

Fixed submission:
from fractions import Fraction

N, K = map(int, input().split())

y = Fraction(1, N)


count = 0
for i in range(1, N + 1):
    kakuritu = 1
    while 1 <= i and i <= K - 1:
        i *= 2
        kakuritu /= 2
        if (i <= K):
            continue
        elif (i >= K):
            break
    count += kakuritu
print("{:.12f}".format(count * float(y)))

Buggy submission (verdict: Runtime Error):
from fractions import Fraction

N, K = map(int, input().split())


def saikoro(x):
    y = Fraction(1, N)
    kakuritu = 1
    while 1 <= x and x <= K - 1:
        # 表
        x *= 2
        kakuritu *= 0.5
        if (x <= K):
            continue
        elif (x >= K):
            return kakuritu * float(y)
            break


count = 0
for i in range(1, N + 1):
    count += saikoro(i)
print(count)
Problem p03262 (python)

Fixed submission:
import fractions
from functools import reduce

N, X = map(int, input().split())
L = list(map(int, input().split()))

# move1 = D
# move2 = -D


# D = 1のときは必ずゴールできる
ans = []
# 初期のXとそれ以外の街の差をDで割ったあまりが全て0なら訪れることができる
# つまりそれぞれの街の差を保存し、その最大公約数がDとなる
for i in range(N):
    dfe = abs(L[i] - X)
    ans.append(dfe)

ans = list(set(ans))

# reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]
# functoolsのreduceはある関数があり、それを前の計算結果と重なりを考慮しながら
# 関数に当てはめる、というアクションを繰り返す


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


# print(ans)
# print(reduce(lambda x, y: x + y, ans))
print(gcd_list(ans))

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

N, X = map(int, input().split())
L = list(map(int, input().split()))

# move1 = D
# move2 = -D


# D = 1のときは必ずゴールできる
ans = []
# 初期のXとそれ以外の街の差をDで割ったあまりが全て0なら訪れることができる
# つまりそれぞれの街の差を保存し、その最大公約数がDとなる
for i in range(N):
    dfe = abs(L[i] - X)
    ans.append(dfe)

ans = list(set(ans))

# reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]
# functoolsのreduceはある関数があり、それを前の計算結果と重なりを考慮しながら
# 関数に当てはめる、というアクションを繰り返す


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


# print(ans)
# print(reduce(lambda x, y: x + y, ans))
print(gcd_list(ans))
Problem p03545 (python)

Fixed submission:
i = input()

a=int(i[0])
b=int(i[1])
c=int(i[2])
d=int(i[3])
sa=i[0]
sb=i[1]
sc=i[2]
sd=i[3]

if(a+b+c+d==7):
    print(sa+"+"+sb+"+"+sc+"+"+sd+"=7")
elif (a+b+c-d==7):
    print(sa+"+"+sb+"+"+sc+"-"+sd+"=7")
elif (a+b-c+d==7):
    print(sa+"+"+sb+"-"+sc+"+"+sd+"=7")
elif(a-b+c+d==7):
    print(sa+"-"+sb+"+"+sc+"+"+sd+"=7")
elif(a-b-c+d==7):
    print(sa+"-"+sb+"-"+sc+"+"+sd+"=7")
elif(a-b+c-d==7):
    print(sa+"-"+sb+"+"+sc+"-"+sd+"=7")
elif(a+b-c-d==7):
    print(sa+"+"+sb+"-"+sc+"-"+sd+"=7")
elif(a-b-c-d==7):
    print(sa+"-"+sb+"-"+sc+"-"+sd+"=7")

Buggy submission (verdict: Runtime Error):
i = int(input())
lst = []
while i > 0:
    lst.append(i%10)
    i //= 10 
lst.reverse()
a=lst[0]
b=lst[1]
c=lst[2]
d=lst[3]
sa=str(a)
sb=str(b)
sc=str(c)
sd=str(d)

if(a+b+c+d==7):
    print(sa+"+"+sb+"+"+sc+"+"+sd+"=7")
elif (a+b+c-d==7):
    print(sa+"+"+sb+"+"+sc+"-"+sd+"=7")
elif (a+b-c+d==7):
    print(sa+"+"+sb+"-"+sc+"+"+sd+"=7")
elif(a-b+c+d==7):
    print(sa+"-"+sb+"+"+sc+"+"+sd+"=7")
elif(a-b-c+d==7):
    print(sa+"-"+sb+"-"+sc+"+"+sd+"=7")
elif(a-b+c-d==7):
    print(sa+"-"+sb+"+"+sc+"-"+sd+"=7")
elif(a+b-c-d==7):
    print(sa+"+"+sb+"-"+sc+"-"+sd+"=7")
elif(a-b-c-d==7):
    print(sa+"-"+sb+"-"+sc+"-"+sd+"=7")

Buggy submission (verdict: Runtime Error):
i = int(input())
lst = []
while i > 0:
    lst.append(i%10)
    i //= 10 
lst.reverse()
a=lst[0]
b=lst[1]
c=lst[2]
d=lst[3]
sa=str(a)
sb=str(b)
sc=str(c)
sd=str(d)

if(a+b+c+d==7):
    print(sa+"+"+sb+"+"+sc+"+"+sd+"=7")
elif (a+b+c-d==7):
    print(sa+"+"+sb+"+"+sc+"-"+sd+"=7")
elif (a+b-c+d==7):
    print(sa+"+"+sb+"-"+sc+"+"+sd+"=7")
elif(a-b+c+d==7):
    print(sa+"-"+sb+"+"+sc+"+"+sd+"=7")
elif(a-b-c+d==7):
    print(sa+"-"+sb+"-"+sc+"+"+sd+"=7")
elif(a-b+c-d==7):
    print(sa+"-"+sb+"+"+sc+"-"+sd+"=7")
elif(a+b-c-d==7):
    print(sa+"+"+sb+"-"+sc+"-"+sd+"=7")
elif(a-b-c-d==7):
    print(sa+"-"+sb+"-"+sc+"-"+sd+"=7")
else:
  print('none')
Problem p03946 (python)

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

min_num = 10 ** 9 + 7
diff = 0
count = 0
for i in range(N):
    min_num = min(min_num, A[i])
    if diff == A[i] - min_num:
        count += 1
    elif A[i] - min_num > diff:
        count = 1
        diff = A[i] - min_num
    else:
        continue

print(count)

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

dp = [[0] * (N + 1) for _ in range(N + 1)]

max_num = max(A)
max_index = A.index(max_num)

idx = 0
dfe = 0
count = 0
while True:
    print(idx)
    if idx >= len(A) - 1:
        break
    max_num = max(A[idx:])
    max_index = A.index(max_num)

    min_num = min(A[idx:max_index + 1])
    if dfe == max_num - min_num:
        count += 1
    elif dfe < max_num - min_num:
        dfe = max_num - min_num
        count = 1

    idx = max_index + 1

print(count)
Problem p04013 (python)

Fixed submission:
N,A = map(int,input().split())
ls1 = [0] + list(map(int,input().split()))

dp = [[[0 for k in range(2600)] for j in range(51) ] for i in range(51)]
for i in range(51):
    dp[i][0][0] = 1
for j in range(1,N+1):
    for k in range(1,j+1):
        for s in range(2600):
            if s < ls1[j]:
                dp[j][k][s] = dp[j-1][k][s]
            elif s >= ls1[j]:
                dp[j][k][s] = dp[j-1][k-1][s-ls1[j]] + dp[j-1][k][s]
ans = 0
for k in range(1,N+1):
    ans += dp[N][k][k*A]
print(ans)

Buggy submission (verdict: Runtime Error):
N, A = map(int, input().split())
X = [0] + list(map(int, input().split()))

max_X = max(X)
dp = [[[0 for k in range((N + 1) * max_X)]
       for j in range(N + 1)] for i in range(N + 1)]
for i in range(N + 1):
    dp[i][0][0] = 1

for j in range(1, N + 1):
    for k in range(1, j + 1):
        for s in range((N + 1) * max_X):
            if s < X[j]:
                dp[j][k][s] = dp[j - 1][k][s]
            elif s >= X[j]:
                dp[j][k][s] = dp[j - 1][k - 1][s - X[j]] + dp[j - 1][k][s]
ans = 0
for k in range(1, N + 1):
    ans += dp[N][k][k * A]
print(ans)

Buggy submission (verdict: Runtime Error):
N, A = map(int, input().split())
X = [0] + list(map(int, input().split()))

dp = [[[0 for k in range((N + 1) * max(X))]
       for j in range(N + 1)] for i in range(N + 1)]
for i in range(N + 1):
    dp[i][0][0] = 1

for j in range(1, N + 1):
    for k in range(1, j + 1):
        for s in range((N + 1) * max(X)):
            if s < X[j]:
                dp[j][k][s] = dp[j - 1][k][s]
            elif s >= X[j]:
                dp[j][k][s] = dp[j - 1][k - 1][s - X[j]] + dp[j - 1][k][s]
ans = 0
for k in range(1, N + 1):
    ans += dp[N][k][k * A]
print(ans)
Problem p04048 (python)

Fixed submission:
n, x = map(int, input().split())
a, b = max(n-x,x),min(n-x,x)
res = a+b
while b!=0:
    q = a//b
    r = a%b
    res += (b*2)*q
    if (r==0):
        res -= b
    a, b = b, r

print(res)

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


if (n%2 == 1):
    print((n-1)*3)
elif (n==2):
    print(3)
else:
    k=n/2
    if (x<k):
        if((n/2)%2==0):
            l = []
            for i in range(1,k-2):
                l.append(((n-1)*3)-3*(x-1))
            last = l[0]
            l.append(last)
            print(l[x-1])
        else:
            if (x%2==0):
                print((n-2)*3)
            else:
                print((n-1)*3)
    elif(x==k):
        print(int(k*3))
    else:
        p = n-x
        if (p<k):
            if((n/2)%2==0):
                l = []
                for i in range(1,k-2):
                    l.append(((n-1)*3)-3*(p-1))
                last = l[0]
                l.append(last)
                print(l[p-1])
            else:
                if (p%2==0):
                    print((n-2)*3)
                else:
                    print((n-1)*3)
Problem p02584 (python)

Fixed submission:
x,k,d = map(int,input().split())
x = abs(x)
div = min(x//d,k)
cnt = 0
k-=div
x -= div*d
if k%2 == 0:
  print(x)
else:
  print(abs(x-d))

Buggy submission (verdict: Runtime Error):
def isEven(num):
  if num%2 == 0:
  	return True
  return False

def isOdd(num):
  if num%2 == 1:
    return True
  return False

if __name__ == "__main__":
  x,k,d = map(int, input().split())
  div = x//d
  cmp = x
  defo = x
  if isOdd(k):
    if x > d:
      if k%div != 0:
        div = min(div,k%div)
      for i in [d,-d]:
        cmp = min(cmp,abs(defo+div*i))
      print(cmp)
    else:
      for i in [d,-d]:
        cmp = min(cmp,abs(defo+i))
      print(cmp)
  if isEven(k):
    div = x//(2*d)
    if x > d:
      div = min(div,k)
      for j in range(1,div)
        for i in [d,-d]:
          cmp = min(cmp,abs(defo+(2*j)*i))
      print(cmp)
    else:
      print(cmp)
Problem p02628 (python)

Fixed submission:
a,b = map(int,input().split())
c = list(map(int,input().split()))
c.sort()
print(sum(c[0:b]))

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
c = []
for _ in range(a):
	c.append(int(input()))
sort(c)
print(sum(c[0:b]))
Problem p02639 (python)

Fixed submission:
arr = list(map(int, input().split()))
for i in range(len(arr)):
  if (arr[i] == 0):
    print(i+1)

Buggy submission (verdict: Runtime Error):
arr = map(int, input().split())
for i in range(len(arr)):
  if (arr[i] == 0):
    print(i+1)
Problem p02658 (python)

Fixed submission:
def main():
    n = int(input())
    arr = list(map(int, input().split()))
    if 0 in arr:
        print(0)
        return
    prod = 1
    for x in arr:
        prod *= x
        if prod > int(1e18):
            print(-1)
            return
    print(prod)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main()
	n = int(input())
  	arr = list(map(input().split()))
    if 0 in arr:
        print(0)
        return
    prod = 1
    for x in arr:
        prod *= x
        if prod > int(1e18):
            print(-1)
            return
    print(prod)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main()
	n = input()
  	arr = list(map(input().split()))
    if 0 in arr:
        print(0)
        return
  	prod = 1
    for x in arr:
        prod *= x
        if prod > int(1e18):
            print(-1)
            return
    print(prod)

if __name__ = "__main__":
	main()

Buggy submission (verdict: Runtime Error):
def main()
	n = input()
  	arr = list(map(input().split()))
    if 0 in arr:
        return print(0)
  	prod = 1
    for x in arr:
        prod *= x
        if prod > int(1e18):
            return print(-1)
    print(prod)

if __name__ = "__main__":
	main()
Problem p02690 (python)

Fixed submission:
def main(x):
  for i in range(-120,120):
    for j in range(-120,120):
      if(i**5-j**5 == int(x)):
        print(str(i)+" "+str(j))
        return
 
if __name__ == '__main__':
  main(input())

Buggy submission (verdict: Runtime Error):
def main(x):
  for i in range(100):
    for j in range(100):
      if(i**5-j**5 == x):
        print(str(i)+" "+str(j))
        return

if __name__ = '__main__':
  main(input())

Buggy submission (verdict: Runtime Error):
x = input()
for i in range(100):
  for j in range(100):
    if(i**5-j**5 == x):
      print(str(i)+" "+str(j))
      return

Buggy submission (verdict: Runtime Error):
x = input()
for i in range(100):
  for j in range(100):
	if(i**5-j**5 == x):
      print(str(i)+" "+str(j))
Problem p02730 (python)

Fixed submission:
string = input()
mid = len(string)//2

gnirts = string[::-1]
if(string != gnirts or string[:mid] != gnirts[mid+1:] or string[mid+1:] != gnirts[:mid]):
  print("No")
  exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
string = input()
mid = len(s)//2

gnirts = reversed(string)
print(gnirts)
if(string != gnirts or string[:mid-1] != gnirts[mid+1:] or string[mid+1:] != gnirts[:mid-1]):
  print("No")
  exit()
print("Yes")
Problem p03273 (python)

Fixed submission:
a,b = list(map(int,input().split()))
A = []
AAA = 0
list = [["" for i in range(b)] for j in range(a)]
for i in range(a):
    n = input()
    if n.count(".") == b:
       pass 
    else:
        for j in range(b):
            list[i][j] = n[j]
for i in range(b):
    for j in range(a):
        A.append(list[j][i])
    if len(A) == A.count(".")+A.count(""):
        for k in range(a):
            list[k][i] = ""
    A = []
for i in range(a):
    for j in range(b):
        if list[i][j] != "":
            print(list[i][j],end="")
            AAA = 1
    if AAA == 1:
        print()
    AAA = 0

Buggy submission (verdict: Runtime Error):
a,b = list(map(int,input().split()))
A = []
list = [["" for i in range(b)] for j in range(a)]
for i in range(a):
    n = input()
    if n.count(".") == b:
       pass 
    else:
        for j in range(b):
            list[i][j] = n[j]
for i in range(b):
    for j in range(a):
        A.append(list[j][i])
    if len(A) == A.count(".")+A.count(""):
        for k in range(a):
            list[k][i] = ""
    A = []
for i in range(a):
    for j in range(b):
        if list[i][j] != "":
            print(list[i][j],end="")
            AAA = 1
    if AAA == 1:
        print()
    AAA = 0
Problem p02536 (python)

Fixed submission:
import sys

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()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

input = sys.stdin.readline
N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)

print(uf.group_count() - 1)

Buggy submission (verdict: Runtime Error):
import sys

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()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

input = sys.stdin.readline
N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
    a, b = map(int, input().split())
    uf.union(a, b)

print(uf.group_count() - 1)
Problem p02684 (python)

Fixed submission:
import sys
from collections import deque

N, K = map(int, sys.stdin.readline().strip().split())
tmp = list(map(int, sys.stdin.readline().strip().split()))

A = [a-1 for a in tmp]

visited = set()
loop = []

q = deque()
q.append(0)
start = float("inf")
end = float("inf")

count = 0
while q and count <= N:
    s_town = q.popleft()
    # ループを確認
    if s_town in visited:
        start = loop.index(s_town)
        end = len(loop)
        break
    visited.add(s_town)
    loop.append(s_town)
    n_town = A[s_town]
    q.append(n_town)
    count += 1

# print(start, end)
if start >= K:
    print(loop[K]+1)
else:
    res = K - start
    res %= (end - start)
    # print("res", res)
    print(loop[start + res]+1)

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

N, K = map(int, sys.stdin.readline().strip().split())
tmp = list(map(int, sys.stdin.readline().strip().split()))

A = [a-1 for a in tmp]

visited = set()
loop = []

q = deque()
q.append(0)
start = float("inf")
end = float("inf")

count = 0
while q and count < K:
    s_town = q.popleft()
    # ループを確認
    if s_town in visited:
        start = loop.index(s_town)
        end = len(loop)
        break
    visited.add(s_town)
    loop.append(s_town)
    n_town = A[s_town]
    q.append(n_town)
    count += 1

# print(start, end)
if start >= K:
    print(loop[K]+1)
else:
    res = K - start
    res %= (end - start)
    # print("res", res)
    print(loop[start + res]+1)