Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
input_word = input()
input_list = input_word.split(" ")
N = int(input_list[0])
K = int(input_list[1])
input_word = input()
tmp_list = input_word.split(" ")
input_list = [ int(i) for i in tmp_list ]

while True:
  flag = 0
  for i in range(1,N):
    number = input_list.index(i)
    number_1 = input_list.index(i+1)
    if number - number_1 >= K:
        input_list[number_1],input_list[number] = input_list[number],input_list[number_1]
        flag = 1
        break
  if flag == 0:
    break

for i in input_list:
  print(i)
      

Fixed submission:
input_word = input()
N = int(input_word)
input_word = input()
tmp_list = input_word.split(" ")
input_list = [ int(i) for i in tmp_list ]
input_list.sort()
output = 0
for i in range(N):
  output += input_list[2*i]
print(output)

Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)



N,k = map(int,raw_input().split())
#k = int(raw_input())
#A = map(int, raw_input().split())
ans = gcd(N,k)
print 3*(N - ans)

Fixed submission:
N = int(raw_input())
A = map(int, raw_input().split())
sum = 0
A.sort()
B = A[::2]
x = 0
for i in B:
    x = x + i
    pass
print x

Buggy python submission (verdict: Runtime Error):
N = int(raw_input())
A = map(int, raw_input().split())
sum = 0
A.sort()
A = A[::2]
print sum(A)


Fixed submission:
N = int(raw_input())
A = map(int, raw_input().split())
sum = 0
A.sort()
B = A[::2]
x = 0
for i in B:
    x = x + i
    pass
print x
Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)



N = int(raw_input())
k = int(raw_input())
#A = map(int, raw_input().split())
ans = gcd(N,k)
print 3*(N - ans)

Fixed submission:
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)



N,k = map(int,raw_input().split())
#k = int(raw_input())
#A = map(int, raw_input().split())
ans = gcd(N,k)
print 3*(N - ans)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
N, X = list(map(int, input().split()))
sum_ = X
prev = X
next = N - X
i = 0
while True:
    num = prev // next
    if i == 0:
        sum_ += 2 * num * next
    elif i % 2 == 1:
        sum_ += 2 * num * next - next
    else:
        sum_ += 2 * num * next - next
    mod_ = prev % next
    if mod_ == 0:
        break
    sum_ += next
    prev = next
    next = mod_
    i += 1
print(sum_)

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
Ls = list(map(int, input().split()))
sorted_ = sorted(Ls)
list_ = []
for i, x in enumerate(sorted_):
    if i % 2 == 0:
        list_.append(x)
sum_ = sum(list_)
print(sum_)

Buggy python submission (verdict: Runtime Error):
N, X = map(int, raw_input().split())
ans = 0
if N%2 ==0:
    d = min(X, N-X)
    ans = (N-d)*3
else:
    ans = (N-1)*3

print(ans)

Fixed submission:
import numpy as np

N = int(raw_input())
data = np.array(map(int, raw_input().split()))
data = np.sort(data)
idx = np.array([True, False]*N)

ans = sum(data[idx])

print(ans)

Buggy python submission (verdict: Runtime Error):
N, X = map(int, raw_input().strip().split())
print N + (N-X)*2 -1

Fixed submission:
N = int(raw_input())
length_list = sorted(map(int, raw_input().strip().split()))

total = 0
for i in xrange(0, 2*N, 2):
    total += length_list[i]
print total

Buggy python submission (verdict: Runtime Error):
def bbq():
    n = int(input())
    a = input()
    tmp = a.split()
    l = [int(x) for x in tmp]
    l.sort()
    n = 0
    i = 0
    while(i<n:
        n += l[i]
        i += 2
    print (n)

if __name__ == "__main__":
    bbq()

Fixed submission:
def bbq():
    n = int(input())
    a = input()
    tmp = a.split()
    l = [int(x) for x in tmp]
    l.sort()
    n = 0
    i = 0
    while(i<len(l)):
        n += l[i]
        i += 2
    print (n)

if __name__ == "__main__":
    bbq()

Buggy python submission (verdict: Runtime Error):
N=raw_input()
up=raw_input()
up=up.split()

up=map(int,up)
up.sort()
count=0
for i in range(N):
    count+=up[i*2]
print count

Fixed submission:
N=raw_input()
up=raw_input()
up=up.split()

up=map(int,up)
up.sort()
count=0
for i in range(int(N)):
    count+=up[i*2]
print count

Buggy python submission (verdict: Runtime Error):
N=raw_input()
up=raw_input().split()

up=map(int,up)
up.sort()
count=0
for i in range(N):
    count+=up[i*2]
print count

Fixed submission:
N=raw_input()
up=raw_input()
up=up.split()

up=map(int,up)
up.sort()
count=0
for i in range(int(N)):
    count+=up[i*2]
print count

Buggy python submission (verdict: Runtime Error):
N=raw_input()
up=raw_input().split()

up=up.sort()
count=0
for i in range(N):
    count+=int(up[i*2])
print count

Fixed submission:
N=raw_input()
up=raw_input()
up=up.split()

up=map(int,up)
up.sort()
count=0
for i in range(int(N)):
    count+=up[i*2]
print count
Buggy python submission (verdict: Runtime Error):
N = int(input()
if N%1000==0:
  print(0)
else:
  print(1000-(N%1000))

Fixed submission:
N = int(input())
if N%1000==0:
  print(0)
else:
  print(1000-(N%1000))
Buggy python submission (verdict: Runtime Error):
mport math
 
a,b,c = map(int,input().split())
 
if c > a+b+2*math.sqrt(a*b):
  print("Yes")
else:
  print("No")

Fixed submission:
import math

a,b,c = map(int,input().split())

if c-a-b>0 and 4*a*b < (c-a-b)*(c-a-b):
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
import math
 
a,b,c = map(int,input().split())
 
if c > a+b+2*math.sqrt(a*b)
  print("Yes")
else:
  print("No")

Fixed submission:
import math

a,b,c = map(int,input().split())

if c-a-b>0 and 4*a*b < (c-a-b)*(c-a-b):
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
l = input().split

a = l[0]
b = l[1]
c = l[2]

if (a == b and a != c )or (c == b and a != c )or (a == c and b != c ):
    print("Yes")
else:
    print("No")

Fixed submission:
l = str(input()).split()
 
a = l[0]
b = l[1]
c = l[2]
 
if (a == b and a != c )or (c == b and a != c )or (a == c and b != c ):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N = input()
l = input().split()
 
flag = "APPROVED"
for n in l:
  if n % 2 == 0 and n%3 != 0 and n%5 != 0:
    flag = "DENIED"
    
print(flag)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))  # 入力のときに N を使う必要はありません

flag = "APPROVED"
for n in A:
  if n % 2 == 0 and n%3 != 0 and n%5 != 0:
    flag = "DENIED"
    
print(flag)

Buggy python submission (verdict: Runtime Error):
l = input()
l = input().split()
l = l[1:]
 
flag = "APPROVED"
for n in l:
  if n % 2 == 0 and n%3 != 0 and n%5 != 0:
    flag = "DENIED"
    
print(flag)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))  # 入力のときに N を使う必要はありません

flag = "APPROVED"
for n in A:
  if n % 2 == 0 and n%3 != 0 and n%5 != 0:
    flag = "DENIED"
    
print(flag)
Buggy python submission (verdict: Runtime Error):
N = int(input())

dic = set()
for i in range(N):
    dic.add(str(input()))

dic.sort()

for i in list(dic):
    print(i)

Fixed submission:
N = int(input())


inin = []
for i in range(N):
    inin.append(str(input()))
    
dic = {}
for i in inin:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] = dic[i]+1

l = dic.items()
max = 0
for i in l:
    if i[1] > max:
        max = i[1]

result = []
for i in l:
    if i[1] == max:
        result.append(i[0])

result.sort()

for i in result:
    print(i)
Buggy python submission (verdict: Runtime Error):
color = input().split()
number = input().split()
choice = str(input())

for i in [0,1]:
  if choice == color[i]:
    number[i] -= 1
    
print(number[0],number[1])

Fixed submission:
color = input().split()
number = list(map(int,input().split()))
choice = str(input())
 
for i in [0,1]:
  if choice == color[i]:
    number[i] -= 1
    
print(number[0],number[1])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
l = list(map(int,input().split()))

max = 0
for i in range(N-K+1):
  temp = 0
  for j in range(i,i+K):
    temp += l[j]
  if temp > max:
    max = temp

print((max+K)/2)

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

m = 0
pre = 0
for j in range(K):
    pre += l[j]
m = pre

if K>1 and N>K:
  for i in range(N-K):
    temp = pre
    temp += l[i+K]
    temp -= l[i]
    if temp > m:
      m = temp
    pre = temp

if K==1:
  for i in range(N):
    if l[i] > m:
      m = l[i]


print((m+K)/2)
Buggy python submission (verdict: Runtime Error):
#L, R = map(int,input().split())
H,N = map(int,input().split())
A = list(map(int,input().split()))
 
a = 0
for i in A:
  a += i
  
if a>=H:
  print("Yes")
else:
  print("No")

Fixed submission:
#L, R = map(int,input().split())
H,A = map(int,input().split())

r = H % A
if r == 0:
  ans = H/A
else:
  ans = (H-r)/A+1

print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H,W = map(int,input().split())

N = H*W

data = ["#" * (W+2)]
for i in range(H):
  data.append("#"+input()+"#")
data.append("#" * (W+2))

offsets = [(0,1),(0,-1),(1,0),(-1,0),]

tree = {}
for i in range(1,H+1):
  for j in range(1,W+1):
    if data[i][j] != ".":
      pass
    else:
      tree[(i,j)] = []
      for o in offsets:
        i_ = i+o[0]
        j_ = j+o[1]
        if data[i_][j_] == "." :
          tree[(i,j)].append((i_,j_))

nodes = list(tree.keys())
  
FARTHEST = 0

for start_node in nodes:
  flag = set()
  # キューを作成して初期ノード(root)を入れる
  q = deque()
  q.append((start_node,0))
  farthest = None

  # キューが空になるまで繰り返す
  while len(q) > 0:
      # キューの先頭（左端）からnodeを取り出す
      data = q.popleft()
      node = data[0]
      distance = data[1]
      if node is not None:
          farthest = (node,distance)
          flag.add(node)
          childs = tree[node]
          for child in childs:
            if child not in flag:
              q.append((child,distance+1))

      if FARTHEST < farthest[1]:
        FARTHEST = farthest[1]

print(FARTHEST)

Fixed submission:
from collections import deque

INF = float("inf")

H,W = map(int,input().split())

N = H*W

data = ["#" * (W+2)]
for i in range(H):
  data.append("#"+input()+"#")
data.append("#" * (W+2))

offsets = [(0,1),(0,-1),(1,0),(-1,0),]

nodes = []
for i in range(1,H+1):
  for j in range(1,W+1):
    if data[i][j] == ".":
      nodes.append((i,j))

FARTHEST = 0

for start_node in nodes:
  i = start_node[0]
  j = start_node[1]
  d = [[INF]*(W+2) for i in range(H+2)]
  d[i][j] = 0
  q = deque([(i,j)])
  res = 0
  while q:
    x,y = q.popleft()
    nd = d[x][y]+1
    for o in offsets:
      nx, ny = x+o[0], y+o[1]
      if data[nx][ny] == "#":
        continue
      if nd < d[nx][ny]:
        d[nx][ny] = nd
        q.append((nx,ny))
        res = nd
  if res > FARTHEST:
    FARTHEST = res

print(FARTHEST)
Buggy python submission (verdict: Runtime Error):
import math
import itertools

N = int(input())
l = [tuple(map(int,input().split())) for _ in range(N)]

if N == 2:
  x1,y1 = l[0]
  x2,y2 = l[1]
  print( 0.5 * math.hypot(x1-x2,y1-y2))
  
else:
  ans = float("INF")
  l_ = itertools.combinations(l,3)
  for points in l_:
    a,b = points[0]
    c,d = points[1]
    e,f = points[2]
    
    if (e-a)*(b-d) == (c-a)*(b-f):
      r = 0.5 * max(math.hypot(c-a,b-d),math.hypot(e-a,b-f),math.hypot(c-e,f-d))
      
    else:
      aa = a * a
      bb = b * b
      cc = c * c
      dd = d * d
      ee = e * e
      ff = f * f

      py = ((e - a) * (aa + bb - cc - dd) - (c - a) * (aa + bb - ee- ff)) / (2 * (e - a)*(b - d) - 2 * (c - a) * (b - f))

      px = (2 * (b - f) * py - aa - bb + ee + ff) / (2 * (e - a)) \
          if (c == a) else (2 * (b - d) * py - aa - bb + cc + dd) / (2 * (c - a))

      r = math.hypot(px - a, py - b)
    flag = 1
    for point in l:
      if flag:
        s,t = point
        if math.hypot(px - s, py - t) > r:
          flag = 0
    if flag:
      ans = min(r,ans)
    
  print(ans)

Fixed submission:
import math
import itertools

N = int(input())
l = [tuple(map(int,input().split())) for _ in range(N)]

if N == 2:
  x1,y1 = l[0]
  x2,y2 = l[1]
  print( 0.5 * math.hypot(x1-x2,y1-y2))
  
else:
  ans = float("INF")
  l_ = itertools.combinations(l,3)
  for points in l_:
    a,b = points[0]
    c,d = points[1]
    e,f = points[2]
    
    if (e-a)*(b-d) == (c-a)*(b-f):
      continue
    else:
      aa = a * a
      bb = b * b
      cc = c * c
      dd = d * d
      ee = e * e
      ff = f * f

      py = ((e - a) * (aa + bb - cc - dd) - (c - a) * (aa + bb - ee- ff)) / (2 * (e - a)*(b - d) - 2 * (c - a) * (b - f))

      px = (2 * (b - f) * py - aa - bb + ee + ff) / (2 * (e - a)) \
          if (c == a) else (2 * (b - d) * py - aa - bb + cc + dd) / (2 * (c - a))

      r = math.hypot(px - a, py - b) + 10**(-7)
    flag = 1
    for point in l:
      if flag:
        s,t = point
        if math.hypot(px - s, py - t) > r:
          flag = 0
    if flag:
      ans = min(r,ans)
      
  l_ = itertools.combinations(l,2)
  for points in l_:
    a,b = points[0]
    c,d = points[1]
    
    
    px,py = (a+c)/2,(b+d)/2

    r = math.hypot(px - a, py - b) + 10**(-7)
    flag = 1
    for point in l:
      if flag:
        s,t = point
        if math.hypot(px - s, py - t) > r:
          flag = 0
    if flag:
      ans = min(r,ans)
    
  print(ans)
Buggy python submission (verdict: Runtime Error):
K,X = map(int,input())

if K*500>=X:
  print("Yes")
else:
  print("No")

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

if K*500>=X:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
s = list(input())

ans = 0
for i in len(s-2):
  if s[i]=="A" and s[i+1] == "B" and s[i+2] ==  "C":
    ans += 1
    
print(ans)

Fixed submission:
N = input()
s = list(input())

ans = 0
for i in range(len(s)-2):
  if s[i]=="A" and s[i+1] == "B" and s[i+2] ==  "C":
    ans += 1
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd

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

if len(set([i&-i for i in a])) != 1:
  print(0)
else:
  x = a[0]/2
  for i in range(1, len(a)):
      x = x*(a[i]/2//gcd(x,a[i]/2))

  print(int(((M//x)+1)//2))

Fixed submission:
from fractions import gcd

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

if len(set([i&-i for i in a])) != 1:
  print(0)
else:
  x = a[0]//2
  for i in range(1, len(a)):
      x = x*(a[i]//2//gcd(x,a[i]//2))

  print(M//x-M//(2*x))
Buggy python submission (verdict: Runtime Error):
print(int(int(input())*int(input())))

Fixed submission:
r = int(input())
print(r*r)

Buggy python submission (verdict: Runtime Error):
print(int(input())*int(input()))

Fixed submission:
r = int(input())
print(r*r)
Buggy python submission (verdict: Runtime Error):
N = int(input())

ans = INF
for i in range(1,1e6+1):
  if N%i == 0:
    ans = min(ans,i+N//i-2)
    
print(ans)

Fixed submission:
N = int(input())

ans = 10000000000000000000
for i in range(1,1000001):
  if N%i == 0:
    ans = min(ans,i+N//i-2)
    
print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()

if s=="A":
  print(T)
if s=="T":
  print(A)
if s=="C":
  print(G)
if s=="G":
  print(C)


Fixed submission:
s = input()

if s=="A":
  print("T")
if s=="T":
  print("A")
if s=="C":
  print("G")
if s=="G":
  print("C")
Buggy python submission (verdict: Runtime Error):
n = input()

if n==1:
  print("Hello World")
else:
  print(int(input())+int(input()))

Fixed submission:
n = int(input())

if n==1:
  print("Hello World")
else:
  print(int(input())+int(input()))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def luca(N):
  if N>=2:
    return luca(N-2)+luca(N-1)
  if N==1:
    return 1
  if N==0:
    return 2
  
print(luca(N))


Fixed submission:
from functools import lru_cache

N = int(input())

@lru_cache(maxsize=None)
def luca(N):
  if N>=2:
    return luca(N-2)+luca(N-1)
  if N==1:
    return 1
  if N==0:
    return 2
  
print(luca(N))

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

def luca(N):
  if N>=2:
    return luca(N-2)+luca(N-1)
  if N==1:
    return 1
  if N==0:
    return 2
  
print(luca(N))

Fixed submission:
from functools import lru_cache

N = int(input())

@lru_cache(maxsize=None)
def luca(N):
  if N>=2:
    return luca(N-2)+luca(N-1)
  if N==1:
    return 1
  if N==0:
    return 2
  
print(luca(N))
Buggy python submission (verdict: Runtime Error):
s = list(input())

if input[0]=="9" or  input[1]=="9":
  print("Yes")
else:
  print("No")


Fixed submission:
s = input()

if s[0]=="9" or  s[1]=="9":
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
s = input()

if input[0]=="9" or  input[1]=="9":
  print("Yes")
else:
  print("No")

Fixed submission:
s = input()

if s[0]=="9" or  s[1]=="9":
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
s = input()

if s = "D D" or "H H":
  print("H")
else:
  print("D")

Fixed submission:
s = input()

if s == "D D" or s == "H H":
  print("H")
else:
  print("D")
Buggy python submission (verdict: Time Limit Exceeded):
mod = 1000000007
size = 50
f = []
invf = []
def inv(n):
  global mod,size
  if n == 1:
    return 1
  k = [0 for i in range(size)]
  a,b,u = mod,n,size
  for i in range(size):
    k[i],a,b = a//b,b,a%b
    if b == 0:
      u = i
      break
  y0,y1 = 1,-k[0]
  for i in range(1,u):
    y0,y1 = y1,y0-k[i]*y1
  while y1 < 0:
    y1 += mod
  return y1%mod
def comb(n,k):
  global mod,f,invf
  if k < 0 or k > n:
    return 0
  if n == 0 and k == 0:
    return 1
  if n == 0:
    return 0
  return (f[n]*((invf[k]*invf[n-k])%mod))%mod
def init(n):
  global mod,f,invf
  f = [0 for i in range(n+1)]
  invf = [0 for i in range(n+1)]
  f[0],invf[0] = 1,1
  for i in range(1,n+1):
    f[i] = (f[i-1]*i)%mod
    invf[i] = inv(f[i])
  
n,a,b,c = map(int,input().rstrip().split())
init(2*n)
m = 0
for k in range(n):
  m = (m+comb(n+k,n)*(pow(a,n,mod)*pow(b,k,mod)+pow(a,k,mod)*pow(b,n,mod))*inv(pow(100-c,n+k+1,mod)))%mod
print((m*n*100)%mod)

Fixed submission:
mod = 1000000007
size = 50
f = []
invf = []
def inv(n):
  global mod,size
  if n == 1:
    return 1
  k = [0 for i in range(size)]
  a,b,u = mod,n,size
  for i in range(size):
    k[i],a,b = a//b,b,a%b
    if b == 0:
      u = i
      break
  y0,y1 = 1,-k[0]
  for i in range(1,u):
    y0,y1 = y1,y0-k[i]*y1
  while y1 < 0:
    y1 += mod
  return y1%mod
def comb(n,k):
  global mod,f,invf
  if k < 0 or k > n:
    return 0
  if n == 0 and k == 0:
    return 1
  if n == 0:
    return 0
  return (f[n]*((invf[k]*invf[n-k])%mod))%mod
def init(n):
  global mod,f,invf
  f = [0 for i in range(n+1)]
  invf = [0 for i in range(n+1)]
  f[0],invf[0] = 1,1
  for i in range(1,n+1):
    f[i] = (f[i-1]*i)%mod
    invf[i] = inv(f[i])
  
n,a,b,c = map(int,input().rstrip().split())
init(2*n)
m = 0
for k in range(n):
  m = (m+comb(n+k,n)*(pow(a,n,mod)*pow(b,k,mod)+pow(a,k,mod)*pow(b,n,mod))*inv(pow(100-c,n+k+1,mod)))%mod
print((m*n*100)%mod)
Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial as f
n,m,k=map(int,input().strip().split())
print((f(n*m-2)//(f(k-2)*f(n*m-k))*(m*m*(n**3-n)+n*n*(m**3-m))//6)%(10**9+7))

Fixed submission:
from math import factorial as f
n,m,k=map(int,input().strip().split())
print((f(n*m-2)//(f(k-2)*f(n*m-k))*(m*m*(n**3-n)+n*n*(m**3-m))//6)%(10**9+7))
Buggy python 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()}

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

n,m=map(int,input().split())
uf=UnionFind(n)
G=[[] for _ in range(n)]
for _ in range(m):
  a,b=map(int,input().split())
  uf.union(a,b)
  
print(uf.group_count()-1)

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

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 python submission (verdict: Time Limit Exceeded):
#E

import math

INF=float('inf')
ans1='pairwise coprime'
ans2='setwise coprime'
ans3='not coprime'

n=int(input())
A=list(map(int,input().split()))

g=math.gcd(A[0],A[1])
for i in range(2,n):
  g=math.gcd(g,A[i])

if g!=1:
  print(ans3)
else:
  for i in range(n):
    for j in range(n):
      if i==j:
        continue
      if math.gcd(A[i],A[j])!=1:
        print(ans2)
        exit()
  print(ans1)

Fixed submission:
import math

INF=float('inf')
ans1='pairwise coprime'
ans2='setwise coprime'
ans3='not coprime'

n=int(input())
A=list(map(int,input().split()))

P=[0]*(10**6+1)
for i in A:
  P[i]+=1

pairwise=True
for i in range(2,10**6+1):
  cnt=0
  for j in range(i,10**6+1,i):
    cnt+=P[j]
  if cnt>1:
    pairwise=False
    break

if pairwise:
  print(ans1)
  exit()
  
g=math.gcd(A[0],A[1])
for i in A:
  g=math.gcd(g,i)

if g==1:
  print(ans2)
else:
  print(ans3)
Buggy python submission (verdict: Time Limit Exceeded):
x,k,d=map(int,input().split())
m=0
p=0
eo=k
ans=x
for i in range(1,k+1):
  m,p=abs(ans-d),abs(ans+d)
  ans=min(m,p)
  if ans<=d:
    eo=i
    break
if (k-eo)%2==0 and eo<k:
  print(ans)
elif (k-eo)%2==1 and eo<k:
  print(abs(ans-d))
else:
   print(ans)

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