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

Fixed submission:
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

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

def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if par[x] > par[y]:
        x, y = y, x
    par[x] += par[y]
    par[y] = x


N, M = map(int, input().split())
par = [-1 for i in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    unite(a - 1, b - 1)

print(-min(par))

Buggy submission (verdict: Runtime Error):
import copy

n, m = map(int, input().split())

frends = {}

for i in range(m):
  a,b = map(int, input().split())
  if a not in frends:
    frends[a] = set([a])
  if b not in frends:
    frends[b] = set([b])
  frends[a].add(b)
  frends[b].add(a)

group = copy.copy(frends) 
  
for i in frends:
  flag = False
  r = group[i]
  for j in r:
    if j > i:
      flag = True
      break
  if flag == True:
    group[max(r)].update(group.pop(i))

    
cnt = 0
for i in group:
  c = len(group[i])
  if c > cnt:
    cnt = c

print(cnt)

Buggy submission (verdict: Runtime Error):
import copy

n, m = map(int, input().split())

frends = {}

for i in range(m):
  a,b = map(int, input().split())
  if a not in frends:
    frends[a] = set()
  if b not in frends:
    frends[b] = set()
  frends[a].add(b)
  frends[b].add(a)

group = copy.copy(frends) 
  
for i in frends:
  flag = False
  r = group[i]
  for j in r:
    if j > i:
      flag = True
      break
  if flag == True:
    group[max(r)].update(group.pop(i))
    
cnt = 0
for i in group:
  c = len(group[i])
  if c > cnt:
    if i not in group[i]:
      c += 1
    cnt = c

print(cnt)
Problem p02630 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())

asum = sum(a)
adic = {}

for i in a:
  if i in adic:
    adic[i] += 1
  else:
    adic[i] = 1


for i in range(q):
  b, c = map(int, input().split())
  if b in adic:
    if c not in adic:
      adic[c] = 0
    cnt = adic.pop(b)
    adic[c] += cnt
    asum += (c-b) * cnt
  print(asum)

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

asum = sum(a)
adic = {}

for i in a:
  if i in adic:
    adic[i] += 1
  else:
    adic[i] = 1


for i in range(q):
  b, c = map(int, input().split())
  if b in adic:
    if c not in adic:
      adic[c] = 0
    cnt = adic.pop(b)
    adic[c] += cnt
  asum += (c-b) * cnt
  print(asum)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(input().split())
q = int(input())

adic = {}

for i in a:
  if i in adic:
    adic[i] += 1
  else:
    adic[i] = 1


for i in range(q):
  b, c = input().split()
  if b in adic:
    adic[c] += adic.pop(b)
  print( sum(int(j)*int(adic[j]) for j in adic)  )
Problem p02690 (python)

Fixed submission:
x = int(input())

a = 0
b = 0
flg = True

while True:
  a += 1
  for i in range(a):
    if a**5 - i**5 == x:
      a = a
      b = i
      flg = False
      break
    elif a**5 + i**5 == x:
      a = a
      b = -i
      flg = False
      break
  if flg == False:
    break
  
a = str(a)
b = str(b)
print(a+' '+b)

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

a = 0
b = -1

while True:
  b += 1
  a = (x + b**5)**0.2
  if a == int(a):
    a = int(a)
    break
  a = (x - b**5)**0.2
  if a == int(a):
    a = int(a)
    b = -b
    break

a = str(a)
b = str(b)
print(a + ' ' + b)
Problem p02911 (python)

Fixed submission:
n,k,q = map(int, input().split())


a = [0] * n

for i in range(q):
  A = int(input())
  a[A-1] += 1

for i in a:
  if i > q - k:
    print('Yes')
  else:
    print('No')

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

-----
nさんがc問正解したとき、勝ち抜けるには
q - c > k

-----

a = [0] * n

for i in range(q):
  A = int(input())
  a[A-1] += 1

for i in a:
  if q - i > k:
    print('Yes')
  else:
    print('No')
Problem p02923 (python)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))

higher = [0]
move = [0]

for i in range(1, n):
  if h[i-1] < h[i]:
    m = i - higher[len(higher) - 1] - 1
    move.append(m)
    higher.append(i)

move.append(len(h) - 1 - higher[len(higher) - 1])


print(max(move))

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

move = []
cnt = 0

for i in range(n-1):
  if h[i] >= h[i+1]:
    cnt += 1
    if i == n-2:
      move.append(cnt)
  else:
    move.append(cnt)
    cnt = 0

print(max(move))
Problem p02972 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

ball = [0 for i in range(n)]

for i in reversed(range(n)):
  if n//2 < i:
    ball[i] = a[i]
  else:
    if (sum(ball[i::(i+1)]) - a[i]) % 2 == 0:
      ball[i] = 0
    else:
      ball[i] = 1


num = [str(i+1) for i, x in enumerate(ball) if x == 1]

if len(num) == 0:
  print('0')
else:
  print(len(num))
  num = ' '.join(num)
  print(num)

Buggy submission (verdict: Runtime Error):
import sys
import math

n = int(input())
a = list(map(int, input().split()))
sosu = a[:]

for i in range(2, n//2):
  for j in range(2,n):
    if i*j > n:
      break
    else:
      sosu.remove(i*j) 

m = 0

for i in sosu:
  if i > n/2:
    m = sosu.index(i)
    break

del sosu[:(m-1)]

newa = [i for i in a if i not in sosu]

for i in newa:
  if i != newa[0]:
    print('-1')
    sys.exit()

num = [str(i+1) for i, x in enumerate(a) if x == 1]

if len(num) == 0:
  print('0')
else:
  print(len(num))
  num = ' '.join(num)
  print(num)
Problem p02983 (python)

Fixed submission:
from itertools import combinations

l,r = map(int, input().split())

if r//673 > (l-1)//673 and r//3 >(l-1)//3:
  print('0')

else:
    cmb = list(combinations(range(l, r+1), 2))
    mod = [(cmb[i][0] * cmb[i][1]) % 2019 for i in range(len(cmb))]
    print(min(mod))

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

if r//673 > (l-1)//673 and r-l = 2:
  print('0')

else:
    print((l%2019) * ((l+1)%2019))
Problem p03059 (python)

Fixed submission:
a,b,t = map(int, input().split())
n = int(t/a)
print(n*b)

Buggy submission (verdict: Runtime Error):
a,b,t = map(int(input().split()))
n = int(t/a)
print(n*b)
Problem p03060 (python)

Fixed submission:
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

m = 0

for i in range(len(v)):
  if v[i] > c[i]:
    m += v[i] - c[i]

print(m)

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

m = 0

for i in range(len(v)):
  if v[i] > c[i]:
    m += v[i] - c[i]

print(m)
Problem p03061 (python)

Fixed submission:
import math
from itertools import accumulate

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

fromright = list(accumulate(a, math.gcd))
a.reverse()
fromleft = list(accumulate(a, math.gcd))
fromleft.reverse()

gcd = []

gcd.append(fromleft[1])

for i in range(1, n-1):
  gcd.append(math.gcd(fromright[i-1], fromleft[i+1]))

gcd.append(fromright[n-2])

if n == 2:
  print(max(a))
else:
  print(max(gcd))

Buggy submission (verdict: Runtime Error):
import math
from itertools import accumulate

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

fromright = list(accumulate(a, math.gcd))
a.reverse()
fromleft = list(accumulate(a, math.gcd))
fromleft.reverse()

gcd = []

for i in range(1, n-1):
  gcd.append(math.gcd(fromright[i-1], fromleft[i+1]))

print(max(gcd))

Buggy submission (verdict: Runtime Error):
import math
from intertools import accumulate

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

g = []
gcd = []
gcd_u = np.frompyfunc(gcd, 2, 1)

for i in range(n):
  r = a[i]
  a.remove(r)
  gcd = accmulate(a, math.gcd)
  g.append(min(gcd))
  a.insert(i, r)

print(max(g))
Problem p03246 (python)

Fixed submission:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))

a = v[0::2]
b = v[1::2]

aa = Counter(a)
bb = Counter(b)

aaa = aa.most_common()
bbb = bb.most_common()

ans = 0

if aaa[0][0] != bbb[0][0]:
  ans = n - aaa[0][1] - bbb[0][1]

else:
  if len(aa) == len(bb) == 1:
    ans = min(aaa[0][1], bbb[0][1])
  else:
    aaa.append(('-', 0))
    bbb.append(('-', 0))
    ans = n - max(aaa[0][1]+bbb[1][1], aaa[1][1]+bbb[0][1])

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))

a = v[0::2]
b = v[1::2]

aa = Counter(a)
bb = Counter(b)

aaa = aa.most_common()
bbb = bb.most_common()

ans = 0

if aaa[0][0] != bbb[0][0]:
  ans = n - aaa[0][1] - bbb[0][1]

else:
  if len(aa) == len(bb) == 1:
    ans = min(aaa[0][1], bbb[0][1])
  else:
    aaa.append[('-', 0)]
    bbb.append[('-', 0)]
    ans = n - max(aaa[0][1]+bbb[1][1], aaa[1][1]+bbb[0][1])

print(ans)
Problem p03424 (python)

Fixed submission:
n = int(input())
s = input().split()
 
if 'Y' in s:
  print('Four')
else:
  print('Three')

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

if Y in s:
  print('Four')
else:
  print('Three')
Problem p03434 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

if n%2 != 0:
  a.append(0)
  n += 1
 
a.sort()
d = 0

for i in range(int(n/2)):
               d += a[2*i+1]-a[2*i]
           
print(d)

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

if n%2 != 0:
  a.append(0)
  n += 1
 
a.sort()
d = 0

for i in range(int(n/2):
               d += a[2*i+1]-a[2*i]
           
print(d)

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

if n%2 != 0:
  a.append(0)
  n += 1
 
a.sort()
d = 0

for i in range(int(n/2):
               d += a[2i+1]-a[2i]
           
print(d)

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

a = list(map(int, input().split()))
if len(a)%2 !=0:
  a.append(0)
  
a.sort()
d = 0

for i in range(n/2):
  d += a[2i+1] - a[2i]
 
print(d)

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

a = list(map(int, input().split()))
if len(a)%2 !=0:
  a.append(0)
  
a.sort()
d = 0

for i in range(n/2):
  d += a[2i+1] - a[2i]
 
pritn(d)
Problem p03470 (python)

Fixed submission:
n = int(input())
 
m = set()
 
for i in range(n):
  x = int(input())
  m.add(x)
  
print(len(m))

Buggy submission (verdict: Runtime Error):
n = int(input())
 
m = {}
 
for i in range(n):
  x = int(input())
  m.add(x)
  
print(len(m))

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

m = {}

for i in n:
  x = int(input())
  m.add(x)
  
print(len(m))
Problem p03485 (python)

Fixed submission:
a,b = map(int, input().split())

x = (a+b)/2
 
if x == int(x):
  print(int(x))
 
else:
  x += 1
  print(int(x))

Buggy submission (verdict: Runtime Error):
a,b = int(input().split())
 
x = (a+b)/2
 
if x == int(x):
  print(x)
 
else:
  x += 1
  print(int(x))

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
 
x = (a+b)/2
 
if x == int(x):
  print(x)
 
else:
  x += 1
  print(int(x))

Buggy submission (verdict: Runtime Error):
a,b = int(input().split())
 
x = a+b
 
if x == int(x):
  print(x)
 
else:
  x += 1
  print(int(x))

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
 
x = a+b
 
if x == int(x):
  print(x)
 
else:
  x += 1
  print(int(x))

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
 
x = a+b
 
if x == int(x):
  print(x)
 
else:
  print(int(x+1))

Buggy submission (verdict: Runtime Error):
a = input()
b = input()

x = a+b

if x == int(x):
  print(x)
 
else:
  print(int(x+1)
Problem p03494 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

t = True
x = -1

while t == True:
  x += 1
  for i in a:
    if i%2 == 0:
      continue
    else:
      t = False
  a = list(map(lambda x:x/2, a))  

      
print(x)

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

t = True
x = 0

while T == True:
  x +=1
  for i in a:
    if i%2 == 0:
      a = list(map(lambda x:x/2, a))
    else:
      t = False
      
print(x)
Problem p03502 (python)

Fixed submission:
x = input()
a = int(x)
b = list(str(x))
b = list(map(int,b))
b = sum(b)

if a%b == 0:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
x = input()
a = int(x)
b = list(x)
b = sum(b)

if a%b==0:
  print('Yes')
  
else:
  print('No')
Problem p03606 (python)

Fixed submission:
n = int(input())
p = 0
for i in range(n):
  l, r = map(int, input().split())
  p += r-l+1
 
print(p)

Buggy submission (verdict: Runtime Error):
n = int(input())
p = 0
for in in range(n):
  l, r = map(int, input().split())
  p += r-l+1
 
print(n)
Problem p03720 (python)

Fixed submission:
n, m = map(int, input().split())
 
a = []
 
for i in range(m):
  a1, a2 = map(int, input().split())
  a.append(a1)
  a.append(a2)
 
for s in range(n):
  print(a.count(s+1))

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

a = []

for i in m:
  a1, a2 = map(int, input().split())
  a.append(a1)
  a.append(a2)

for s in n:
  print(a.count(s))
Problem p02554 (python)

Fixed submission:
n = int(input())
m=int(1e9+7)
print((pow(10,n,m)+pow(8,n,m)-2*pow(9,n,m))%m)

Buggy submission (verdict: Runtime Error):
n = int(input())
m=int(1e9+7)
print(((pow(10,n,m)+pow(8,n,m)-2*pow(9,n,m))%m)
Problem p02612 (python)

Fixed submission:
import sys
import math
# sys.stdin=open('input.txt','r')
# sys.stdout=open('output2.txt','w')
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007

n=ii1()
ans=1000*(1+ n//1000)
if n%1000==0:
    print(0)
else:
    print(ans-n)

Buggy submission (verdict: Runtime Error):
import sys
import math
# sys.stdin=open('input.txt','r')
# sys.stdout=open('output2.txt','w')
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007

n=ii1()
arr=iia()
arr.sort(reverse=True)
ans=0
for i in range(1,n):
    ans+=arr[i//2]
print(ans)

Buggy submission (verdict: Runtime Error):
# cook your dish here
import sys
import math
# sys.stdin=open('input.txt','r')
# sys.stdout=open('output2.txt','w')
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007
# print('hi')
n,m,k=iia()
arr=[input()for i in range(n)]
res=0
for i in range(2**n):
    for j in range(2**m):
        ans=0
        for ii in range(n):
            for jj in range(m):
                if i>>ii & 1 and j>>jj &1 and arr[ii][jj]=='#':
                    ans+=1
        if ans==k:
            res+=1
print(res)
Problem p02640 (python)

Fixed submission:
from sys import stdin,stdout
import math
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007
ani,total = iia()
if total>4*ani:
    print('No')
elif total % 2==0:
    crane=(4*ani - total)
    tor = total-2*ani
    if crane%2==0 or tor%2==0:
        if 0<=crane//2<=ani and 0<=tor//2<=ani:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007
ani,total = iia()
if 0<=(4*ani-total)<=2*ani:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
from sys import stdin,stdout
import math
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007
ani,total = iia()
if 0<=(4*ani-total)<=2*ani:
    print('Yes')
else:
    print('No'
Problem p02657 (python)

Fixed submission:
a,b=map(int,input().split())
print(a*b)

Buggy submission (verdict: Runtime Error):
from sys import stdin,stdout
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007
n = ii1()
m = int(n**0.5)+1
count = 0
flag=0
for i in range(2,m):
    if n%i == 0:
        flag=1
        count+=1
        n=n//i
if flag == 1:
    print(1)
else:
    print(count)
Problem p02536 (python)

Fixed submission:
class UnionFind():
    def __init__(self, N):
        self.N = N
        self.parents = [-1] * N

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

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return False
        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.root(x)]

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

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

n, m = map(int, input().split())

uf = UnionFind(n)

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.unite(a, b)


print(uf.group_count() - 1)

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

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

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return False
        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.root(x)]

n, m = map(int, input().split())

uf = UnionFind(n)

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.unite(a, b)

ans = 0
for i in range(n):
    ans = max(ans, uf.size(i))

print(n - str(ans))
Problem p03478 (python)

Fixed submission:
n, a, b = map(int, input().split())
ans = 0

for i in range(1, n+1):
    s = 0
    num = i
    while num > 0:
        s = s + num % 10
        num = num // 10
    if a <= s <= b:
        ans = ans + i
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = int(input())
b = int(input())
ans = 0

for i in range(1, n+1):
    s = 0
    num = i
    while num > 0:
        s = s + num % 10
        num = num // 10
    if a <= s <= b:
        ans = ans + i
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = int(input())
b = int(input())
ans = 0

for i in range(1, n+1):
    s = 0
    num = i
    while num > 0:
        s = s + num % 10
        num = num // 10
    if a <= s <= b:
        ans = ans + i
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = int(input())
b = int(input())
ans = 0

for i in range(1, n+1):
    s = 0
    num = i
    while num > 0:
        s = s + num % 10
        num = num // 10
    if a <= s and s <= b:
        ans = ans + i
print(ans)
Problem p02536 (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 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 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)
for _ in range(M):
  a,b = map(int,input().split())
  uf.union(a,b)
  
print(uf.group_count() - 1)
Problem p02602 (python)

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

for i in range(N-K):
  if A[i]<A[i+K]:
    print('Yes')
  else:
    print('No')

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

for i in range(K):
  if A[i]<A[i+3]:
    print('Yes')
  else:
    print('No')
Problem p02603 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
M = 1000
S = 0
for i in range(N-1):
  M+=S*A[i]
  S = 0
  if A[i+1]>=A[i]:
    tmp=M//A[i]
    M -= tmp*A[i]
    S+=tmp
M+=S*A[-1]
S = 0
print(M)

Buggy submission (verdict: Runtime Error):
N = int(input().split())
A = list(map(int,input().split()))
M = 1000
S = 0
for i in range(N-1):
  M+=S*A[i]
  S = 0
  if A[i+1]>=A[i]:
    tmp=M//A[i]
    M = tmp*A[i]
    S+=tmp
M+=S*A[i]
S = 0
print(M)