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

Fixed submission:
n = int(input())
txy = [[0,0,0]] + [[int(item) for item in input().split()] for _ in range(n)]

for i in range(n+1):
    if i == 0:
        continue
    t, x, y = txy[i-1]
    nt, nx, ny = txy[i]
    if abs(nx - x) + abs(ny - y) > nt - t:
        print("No")
        exit()
    if (abs(nx - x) + abs(ny - y)) % 2 != (nt - t) % 2:
        print("No")
        exit()
print("Yes")

Buggy submission (verdict: Runtime Error):
2
5 1 1
100 1 1
Problem p03475 (python)

Fixed submission:
n = int(input())
csf = [[int(item) for item in input().split()] for _ in range(n-1)]

for i in range(n):
    total_time = 0
    for c, s, f in csf[i:]:
        time = 0
        # wait for start
        if total_time < s:
            time += s - total_time
        # wait for next train
        else:
            time += (f - total_time % f) % f
        # take train
        time += c
        total_time += time
    print(total_time)

Buggy submission (verdict: Runtime Error):
n = int(input())
csf = [[int(item) for item in input().split()] for _ in range(n-1)]

for i in range(n):
    total_time = 0
    for c, s, f in csf[i:]:
        time = 0
        # wait for start
        if total_time < s:
            time += s - total_time
        # wait for next train
        else:
            time += total_time % f
        # take train
        time += c
        total_time += time
    print(total_time
Problem p03487 (python)

Fixed submission:
from collections import Counter

n = int(input())
a = [int(item) for item in input().split()]

count = Counter(a)
ans = 0
for i in count.keys():
    if count[i] < i:
        ans += count[i]
    else:
        ans += count[i] - i

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(item) for item in input().split()]

count = Counter(a)
ans = 0
for i in count.keys():
    if count[i] < i:
        ans += count[i]
    else:
        ans += count[i] - i

print(ans)
Problem p03524 (python)

Fixed submission:
from collections import Counter
s = input().rstrip()
n = len(s)
cnt = Counter(s)
a = list(cnt.values())
while len(a) < 3:
    a.append(0)
a.sort()
if a[2] - a[0] < 2:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
from collections import Counter
s = input().rstrip()
cnt = Counter(s)
a = list(cnt.values())
a.sort()
if (a[2] - a[0]) > 1:
    print("NO")
else:
    print("YES")
Problem p03599 (python)

Fixed submission:
import bisect
a, b, c, d, e, f = [int(item) for item in input().split()]

water = set()
for i in range(31):
    for j in range(31):
        w = i*a + j*b 
        if w <= f // 100:
            water.add(w)
water = sorted(water)
sugar = set()
for i in range(1501):
    j = 0
    while i*c + j*d <= 1500:
        sugar.add(i*c + j*d)
        j += 1
sugar = sorted(sugar)
ans = []
for w in water:
    sid = bisect.bisect_right(sugar, w*e) - 1
    while sugar[sid] + w*100 > f and sid > 0:
        sid -= 1
    if w != 0:
        total = w*100 + sugar[sid]
        ans.append([sugar[sid]/total, total, sugar[sid]])
ans.sort(key=lambda x:x[0])
print(ans[-1][1], ans[-1][2])

Buggy submission (verdict: Runtime Error):
import bisect
a, b, c, d, e, f = [int(item) for item in input().split()]

water = set()
for i in range(31):
    for j in range(31):
        w = i*a + j*b 
        if w <= f // 100:
            water.add(w)
sugar = set()
for i in range(1501):
    j = 0
    while i*c + j*d <= 1500:
        sugar.add(i*c + j*d)
        j += 1
sugar = sorted(sugar)
ans = []
for w in water:
    sid = bisect.bisect_left(sugar, w*e)
    while sugar[sid] + w*100 > f:
        sid -= 1
    if w != 0:
        total = w*100 + sugar[sid]
        ans.append([sugar[sid]/total, total, sugar[sid]])
ans.sort(key=lambda x:x[0])
print(ans[-1][1], ans[-1][2])
Problem p03633 (python)

Fixed submission:
import fractions
n = int(input())
t = []
for i in range(n):
    t.append(int(input()))

ans = t[0]
for i in range(1,n):
    ans = ans * t[i] // fractions.gcd(ans, t[i])
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
t = []
for i in range(n):
    t.append(int(input()))

ans = t[0]
for i in range(1,n):
    ans = ans * t[i] // math.gcd(ans, t[i])
print(ans)
Problem p03645 (python)

Fixed submission:
n, m = [int(item) for item in input().split()]
ab = [[int(item) for item in input().split()] for _ in range(m)]

way = [0] * (n + 1)
for a, b in ab:
    if a == 1:
        way[b] += 1
    if b == 1:
        way[a] += 1
    if a == n:
        way[b] += 1
    if b == n:
        way[a] += 1
if 2 in way:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
ab_a = sorted(ab)
ab_b = sorted(ab, key= lambda x:x[1])

way = [0] * (n + 1)
for a, b in ab:
    if a == 1:
        way[b] += 1
    if b == 1:
        way[a] += 1
    if a == n:
        way[b] += 1
    if b == n:
        way[a] += 1
if 2 in way:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Problem p03660 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
e = [[] for _ in range(n)]

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

shortest = []
def get_path(start, end, par):
    if end in e[start]:
        shortest.append(end)
        return True
    for item in e[start]:
        if item != par:
             if get_path(item, end, start):
                 shortest.append(item)
                 return True

def tree_count(start, par, a, b):
    count = 0
    for item in e[start]:
        if start == a and item == b:
            continue
        if start == b and item == a:
            continue
        if item != par:
            count += 1
            count += tree_count(item, start, a, b)
    return count

get_path(0, n-1, -1)
shortest.append(0)
shortest = shortest[::-1]
cut_l = (len(shortest)-1) // 2
p = tree_count(0, -1, shortest[cut_l], shortest[cut_l+1])
q = n - p - 2 
if p > q:
    print("Fennec")
else:
    print("Snuke")

Buggy submission (verdict: Runtime Error):
n = int(input())
ab = [[int(item) for item in input().split()] for _ in range(n-1)]

e = [[] for _ in range(n)]
for a, b in ab:
    e[a-1].append(b-1)
    e[b-1].append(a-1)

shortest = []
def get_path(start, end, par, path):
    global shortest
    if end in e[start]:
        shortest = path + [end]
        return shortest
    for item in e[start]:
        if item != par:
             get_path(item, end, start, path + [item])

def tree_count(start, par, a, b):
    count = 0
    for item in e[start]:
        if start == a and item == b:
            continue
        if start == b and item == a:
            continue
        if item != par:
            count += 1
            count += tree_count(item, start, a, b)
    return count

get_path(0, n-1, -1, [0])
cut_l = (len(shortest)-1) // 2
p = tree_count(0, -1, shortest[cut_l], shortest[cut_l+1])
q = tree_count(n-1, -1, shortest[cut_l], shortest[cut_l+1])

if p > q:
    print("Fennec")
else:
    print("Sunuke")
Problem p03677 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
from collections import Counter

n, m = [int(item) for item in input().split()]
a = [int(item) - 1 for item in input().split()]
cnt_t = [0] * m

ans = [0] * m
cnt_r = [0] * (m + 1)
for a1, a2 in zip(a, a[1:]):
    ans[0] += min((m + a2 - a1) % m, (m + a2 - 0) % m + 1)
    cnt_t[a2] += (m + a2 - a1) % m - 1
    if (m + a2 - a1) % m <= 1:
        continue
    add = (a1 + 2) % m
    sub = a2 + 1
    if add < sub:
        cnt_r[add] += 1
        cnt_r[sub] -= 1
    else:
        cnt_r[add] += 1
        cnt_r[sub] -= 1
        cnt_r[0] += 1
        cnt_r[m] -=1
for i in range(m):
    cnt_r[i+1] += cnt_r[i]

for i in range(1, m):
    ans[i] = ans[i - 1] - cnt_r[i] + cnt_t[i - 1]
print(min(ans))

Buggy submission (verdict: Runtime Error):
n, m = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]

def calc(l, m1, m2, r):
    val = [0] * 4
    for a1, a2 in zip(a, a[1:]):
        diff = (a2 - a1 + m) % m
        val[0] += min(diff, (a2 - l + m) % m + 1)
        val[1] += min(diff, (a2 - m1 + m) % m + 1)
        val[2] += min(diff, (a2 - m2 + m) % m + 1)
        val[3] += min(diff, (a2 - r + m) % m + 1)
    return val.index(min(val)), min(val)

l = 1; r = m
while r - l > 2:
    m1 = (l * 2 + r) // 3
    m2 = (l + r * 2) // 3
    ret, _ = calc(l, m1, m2, r)
    if ret == 0:
        r = m1
    elif ret == 1:
        r = m2
    elif ret == 2:
        l = m1
    else:
        l = m2
_, ans = calc(l, m1, m2, r)
print(ans)
Problem p03720 (python)

Fixed submission:
n, m = [int(item) for item in input().split()]
count = [0] * n
for i in range(m):
    a, b = [int(item) for item in input().split()]
    count[a-1] += 1
    count[b-1] += 1
for item in count:
    print(item)

Buggy submission (verdict: Runtime Error):
n, m = [int(item) for item in input().split()]
count = [0] * n
for i in range(n):
    a, b = [int(item) for item in input().split()]
    count[a-1] += 1
    count[b-1] += 1
for item in count:
    print(item)
Problem p03722 (python)

Fixed submission:
n, m = [int(item) for item in input().split()]
edge = []
inf =  2000 * 10**10
for i in range(m):
    a, b, c = [int(item) for item in input().split()]
    edge.append([a-1, b-1, -c])

def BellmanFord(start):
    dist = [inf for i in range(n)]
    dist[0] = 0
    for i in range(n):
        for u, v, c in edge:
            if dist[u] != inf and (dist[u] + c) < dist[v]:
                dist[v] = dist[u] + c
                if i == n-1 and v == n-1:
                    return "inf"
    return -dist[-1]

ret = BellmanFord(0)
print(ret)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

n, m = [int(item) for item in input().split()]
edge = [[] for _ in range(n+1)]
INF =  2000 * 10**10
for i in range(m):
    a, b, c = [int(item) for item in input().split()]
    edge[a-1].append([b-1,c])
edge[n-1].append([n, 0])

def dfs(prev, prev_c, v):
    if v == n:
        return 0
    max_cost = -INF
    for e in edge[v]:
        if e[0] == prev:
            if prev_c + e[1] > 0:
                max_cost = INF
            continue
        max_cost = max(max_cost, e[1] + dfs(v, e[1], e[0]))
    return max_cost

cost = dfs(-1, 0, 0)
if cost > INF // 2:
    print("inf")
else:
    print(cost)

Buggy submission (verdict: Runtime Error):
n, m = [int(item) for item in input().split()]
edge = [[] for _ in range(n+1)]
INF =  2000 * 10**9
for i in range(m):
    a, b, c = [int(item) for item in input().split()]
    edge[a-1].append([b-1,c])
edge[n-1].append([n, 0])

def dfs(prev, prev_c, v):
    if v == n:
        return 0
    max_cost = -INF
    for e in edge[v]:
        if e[0] == prev:
            if prev_c + e[1] > 0:
                max_cost = INF
            continue
        max_cost = max(max_cost, e[1] + dfs(v, e[1], e[0]))
    return max_cost

cost = dfs(-1, 0, 0)
if cost > INF // 2:
    print("inf")
else:
    print(cost)
Problem p03780 (python)

Fixed submission:
n, k = [int(item) for item in input().split()]
a = sorted([int(item) for item in input().split()], reverse=True)

count = 0
asum = 0
for item in a:
    if asum + item < k:
        asum += item
        count += 1
    else:
        count = 0

print(count)

Buggy submission (verdict: Runtime Error):
n, k = [int(item) for item in input().split()]
a = sorted([int(item) for item in input().split()], reverse=True)
max_k = min(sum(a), 5000)

def check_needed(index):
    memo = [[0] * (max_k + 1) for _ in range(n+1)]
    memo[0][0] = 1
    for i in range(n):
        for j in range(max_k + 1):
            if memo[i][j] == 1: 
                memo[i+1][j] = 1 
                if i != index:
                    memo[i+1][j+a[i]] = 1 
    return (1 in memo[n][max(k-a[index], 0):k])

l = -1
r = n
while r-l > 1:
    mid = (l+r) // 2
    if not check_needed(mid):
        r = mid
    else:
        l = mid
if sum(a) < k:
    print(n)
else:
    print(n - r)
Problem p03880 (python)

Fixed submission:
n = int(input())
xor = 0
rank = [0] * 35 
for i in range(n):
    a = int(input())
    LSB = (a & -a).bit_length()
    rank[LSB] += 1
    xor ^= a 

prev = False 
ans = 0
for i in range(33, -1, -1):
    bit = xor & (1 << i)
    if (bit > 0 and prev == 0) or (bit == 0 and prev > 0):
        if rank[i+1] == 0:
            print(-1)
            exit()
        else:
            ans += 1
    prev = bit
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
xor = 0
rank = [0] * 12 
for i in range(n):
    a = int(input())
    LSB = (a & -a).bit_length()
    rank[LSB] += 1
    xor ^= a 

prev = False 
ans = 0
for i in range(10, -1, -1):
    bit = xor & (1 << i)
    if bit ^ prev:
        if rank[i+1] == 0:
            print(-1)
            exit()
        else:
            ans += 1
    prev = bit
print(ans)
Problem p03952 (python)

Fixed submission:
n, x = [int(item) for item in input().split()]
if x == 1 or x == 2*n-1:
    print("No")
    exit()

if n == 2:
    print("Yes")
    print("1 2 3")
    exit()

ans = [0] * (2*n - 1)
used = [0] * (2*n - 1)
if x >= n:
    ans[n-1] = 2*n-1
    used[2*n-1-1] = 1
    ans[n] = x
    used[x-1] = 1
    ans[n+1] = x-1
    used[x-2] = 1
    ans[n-2] = x-2
    used[x-3] = 1
else:
    ans[n-1] = 1 
    used[0] = 1
    ans[n] = x
    used[x-1] = 1
    ans[n+1] = x+1
    used[x] = 1
    ans[n-2] = x+2
    used[x+1] = 1
it = 0
for i in range(2*n-1):
    if ans[i] == 0:
        while(used[it] != 0):
            it += 1
        ans[i] = it+1
        it += 1
print("Yes")
print(" ".join([str(item) for item in ans]))

Buggy submission (verdict: Runtime Error):
n, x = [int(item) for item in input().split()]
if n == 1 or n == 2*n-1:
    print("No")
else:
    ans = [0] * (2*n - 1)
    used = [0] * (2*n - 1)
    if x >= n:
        ans[n-1] = 2*n-1
        used[2*n-1-1] = 1
        ans[n] = x
        used[x-1] = 1
        ans[n+1] = x-1
        used[x-2] = 1
        ans[n-2] = x-2
        used[x-3] = 1
    else:
        ans[n-1] = 1 
        used[0] = 1
        ans[n] = x
        used[x-1] = 1
        ans[n+1] = x+1
        used[x] = 1
        ans[n-2] = x+2
        used[x+1] = 1
    it = 0
    for i in range(2*n-1):
        if ans[i] == 0:
            while(used[it] != 0):
                it += 1
            ans[i] = it+1
            it += 1
    print("Yes")
    print(" ".join([str(item) for item in ans]))
Problem p03997 (python)

Fixed submission:
a = int(input())
b = int(input())
h = int(input())
print((a + b) * h // 2)

Buggy submission (verdict: Runtime Error):
print((a + b) * h // 2)
Problem p04012 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

count = [0] * 26
w = input().rstrip()
for ch in w:
    count[ord(ch) - ord("a")] += 1
ok = True
for item in count:
    if item % 2 == 1:
        ok = False
print("Yes" if ok else "No")

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

count = [0] * 26
w = input()
for ch in w:
    count[ord(ch) - ord("a")] += 1
ok = True
for item in count:
    if item % 2 == 1:
        ok = False
print("Yes" if ok else "No")
Problem p02536 (python)

Fixed submission:
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = float('inf')

# ユニオンファインド木
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.rank = [0] * 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
        elif self.rank[x] > self.rank[y]:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
        else:
            self.parents[y] += self.parents[x]
            self.parents[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

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

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

N, M = list(map(int, input().split()))     # スペース区切り連続数字
AB = [list(map(int, input().split())) for _ in range(M)]     # スペース区切り連続数字(行列)

un = UnionFind(N)
for a, b in AB:
    un.union(a-1, b-1)

g = len(un.roots())

print("{}".format(g-1))

Buggy submission (verdict: Runtime Error):
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = float('inf')

# ユニオンファインド木
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        self.rank = [0] * 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
        elif self.rank[x] > self.rank[y]:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
        else:
            self.parents[y] += self.parents[x]
            self.parents[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

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

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

N, M = list(map(int, input().split()))     # スペース区切り連続数字
AB = [list(map(int, input().split())) for _ in range(M)]     # スペース区切り連続数字(行列)

un = UnionFind(N)
for a, b in AB:
    un.union(a, b)

g = len(un.roots())

print("{}".format(g-1))
Problem p02574 (python)

Fixed submission:
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = 10000000000

# 素数列挙
def primeNumList(n):
    d = [d for d in range(0, n+1)]
    if n < 2:
        return [[],d]
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
            d[j] = i
    return [[i for i in range(n + 1) if is_prime[i]], d]

def main():
    # ------ 入力 ------#
    n = int(input())    # 数字
    aList = list(map(int, input().split()))     # スペース区切り連続数字

    # ------ 処理 ------#
    amax = max(aList)
    pl = primeNumList(amax)
    countList = [0] * (amax+1)

    if pl[0] != []:
        for a in aList:
            at = a
            sl = []
            while at != 1:
                s = pl[1][at]
                sl.append(s)
                at = int(at / s)
            sl2 = list(set(sl))
            for s in sl2:
                countList[s] += 1
        m = max(countList)
    else:
        m = 0

    # ------ 出力 ------#
    if m == len(aList):
        print("not coprime")
    elif m >= 2:
        print("setwise coprime")
    else:
        print("pairwise coprime")


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = 10000000000

# 約数　倍数
def gcb(a, b):
    if b == 0:
        return a
    else:
        return gcb(b, a % b)

def lcm(a, b):
    d = gcb(a, b)
    return int(a / d * b)

def divisorList(a):
    l = []
    for i in range(1, int(a**0.5)+1):
        if a % i == 0:
            l.append(i)
            ii = a / i
            if i != ii:
                l.append(ii)
    return sorted(l)

def primeNumList(a):
    if a <= 1:
        return []
    else:
        multiple_list = [2]
        serial_number_list = [r for r in range(2, a + 1) if r % 2 != 0]

        # 5. 連番リストの先頭が、入力値の平方根以上で終了
        while len(serial_number_list) > 0:
            multiple_list.append(serial_number_list[0])
            for serial_number in range(serial_number_list[0], serial_number_list[- 1] + 1, serial_number_list[0]):
                if serial_number in serial_number_list:
                    serial_number_list.remove(serial_number)

        return multiple_list

def main():
    # ------ 入力 ------#
    n = int(input())    # 数字
    aList = list(map(int, input().split()))     # スペース区切り連続数字

    # ------ 処理 ------#
    amax = max(aList)
    pl = primeNumList(amax)
    countList = [0] * len(pl)
    for a in aList:
        for i in range(len(pl)):
            if a % pl[i] == 0:
                countList[i] += 1

    # ------ 出力 ------#
    m = max(countList)
    if m == len(aList):
        print("not coprime")
    elif m >= 2:
        print("setwise coprime")
    else:
        print("pairwise coprime")


if __name__ == '__main__':
    main()
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 i in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  uf.union(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 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 i in range(m):
  a,b=map(int,input().split())
  uf.union(a,b)
print(uf.group_count()-1)
Problem p02553 (python)

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

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
print(mac(max(a*c,a*d),max(b*c,b*d)))