Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())

ans = 0
if x*H == W*y:
    ans = 1
    print(x*H, ans)
    exit()
S = max(min(H*x, H*(W-x)), min(W*y, W*(H-y)))

xp = x*H/y
yp = y*W/x

if xp <= W:
    if S <= xp*H/2:
        S = xp*H/2
        ans = 1
if yp <= H:
    if S <= yp*W/2:
        S = yp*W/2
        ans = 1

print(S, ans)


Fixed submission:
W, H, x, y = map(int, input().split())
print(W*H/2, int((x+x==W and y+y==H)))

Buggy python submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())

ans = 0
if x*H == W*y:
    ans = 1
    print(x*H, ans)
    exit()
S = max(min(H*x, H*(W-x)), min(W*y, W*(H-y)))

xp = (x/y)*H
yp = (y/x)*W

if xp <= W:
    if S <= xp*H/2:
        S = xp*H/2
        ans = 1
if yp <= H:
    if S <= yp*W/2:
        S = yp*W/2
        ans = 1

print(S, ans)


Fixed submission:
W, H, x, y = map(int, input().split())
print(W*H/2, int((x+x==W and y+y==H)))
Buggy python submission (verdict: Runtime Error):
N, A, B, C, D = map(int, input().split())
N-=1
A-=1
B-=1
C-=1
D-=1
S = input()

massesExist = True
overtakeFlag = False if C > D else True
proceedableFlag = True

if max(A, B, C, D) > N:
    massesExist = False

for i in range(B, D+1):
    if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
        overtakeFlag = True

for i in range(A, max(C, D)-1):
    if S[i]=="#" and S[i+1]=="#":
        proceedableFlag = False

if overtakeFlag and proceedableFlag and massesExist:
    print("Yes")
else:
    print("No")


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

massesExist = True
overtakeFlag = False if C > D else True
proceedableFlag = True

if max(A, B, C, D) > N:
    massesExist = False

if not overtakeFlag:
    for i in range(B, D+1):
        if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
            overtakeFlag = True

for i in range(A, max(C, D)-1):
    if S[i]=="#" and S[i+1]=="#":
        proceedableFlag = False

if overtakeFlag and proceedableFlag and massesExist:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

ans = 0
for r in range(N//R+1):
    for g in range(N//G+1):
        b = (N - r*R - g*G)//B
        if r*R + g*G + b*B == N and b >= 0:
            ans += 1
print(ans)

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

ans = 0
b = 0
for r in range(N+1):
    for g in range(N+1):
        b = (N - r*R - g*G)//B
        if r*R + g*G + b*B == N and b >= 0:
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
class UnionFind:
    __slots__ = ["_data_size", "_roots"]

    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size

    def __getitem__(self, x: int) -> int:
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def is_connected(self, x: int, y: int) -> bool:
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x


import sys

read = sys.stdin.read

N, _, *X = map(int, readline().split())
tree = UnionFind(N)
res = []
for t, u, v in zip(*[iter(X)] * 3):
    if t:
        res.append(int(tree.is_connected(u, v)))
    else:
        tree.unite(u, v)
print("\n".join(map(str, res)))


Fixed submission:
from typing import Set


class UnionFind:
    """Union-Find: O(α(N))"""

    __slots__ = ["_data_size", "_first_idx", "_parents"]

    def __init__(self, data_size: int, is_zero_origin: bool = True) -> None:
        self._data_size = data_size
        self._first_idx = 0 if is_zero_origin else 1
        self._parents = [-1] * (data_size + self._first_idx)

    def __getitem__(self, x: int) -> int:
        """Find the group (root) of vertex x."""
        if self._parents[x] < 0:
            return x
        self._parents[x] = self[self._parents[x]]
        return self._parents[x]

    def __len__(self) -> int:
        """Count the number of groups (roots)."""
        return len(self.groups)

    @property
    def groups(self) -> Set[int]:
        """Return the set of groups (roots)."""
        return {
            self[x] for x in range(self._first_idx, self._data_size + self._first_idx)
        }

    def is_connected(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are connected or not."""
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y."""
        x, y = self[x], self[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 unite_all(self, *vertices: int) -> None:
        """Unite the groups of all of the given vertices."""
        x = vertices[0]
        for y in vertices[1:]:
            self.unite(x, y)

    def get_size(self, x: int) -> int:
        """Return the size of the group vertex x belongs."""
        return -self._parents[self[x]]


def unionfind():
    # https://judge.yosupo.jp/problem/unionfind
    N, Q, *TUV = map(int, open(0).read().split())
    tree = UnionFind(N)
    res = []
    for t, u, v in zip(*[iter(TUV)] * 3):
        if t:
            res.append(int(tree.is_connected(u, v)))
        else:
            tree.unite(u, v)
    print("\n".join(map(str, res)))


if __name__ == "__main__":
    unionfind()
Buggy python submission (verdict: Time Limit Exceeded):
# C - Marks
from functools import reduce
from operator import mul


def main():
    N, K, *A = map(int, open(0).read().split())
    top_idx, prev_score = 0, reduce(mul, A[:K])
    res = []
    for top, cur in zip(A, A[K:]):
        cur_score = prev_score // top * cur
        res.append("Yes" if cur_score > prev_score else "No")
        prev_score = cur_score
    print("\n".join(res))


if __name__ == "__main__":
    main()


Fixed submission:
# C - Marks
def main():
    N, K, *A = map(int, open(0).read().split())
    res = ["Yes" if tail > top else "No" for top, tail in zip(A, A[K:])]
    print("\n".join(res))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# C - Marks
from functools import reduce
from operator import mul


def main():
    N, K, *A = map(int, open(0).read().split())
    top_idx, prev_score = 0, reduce(mul, A[:K])
    res = []
    for top, cur in zip(A, A[K:]):
        cur_score = prev_score // top * cur
        res.append("Yes" if cur_score > prev_score else "No")
        prev_score = cur_score
    print("\n".join(res))


if __name__ == "__main__":
    main()


Fixed submission:
# C - Marks
def main():
    N, K, *A = map(int, open(0).read().split())
    res = ["Yes" if tail > top else "No" for top, tail in zip(A, A[K:])]
    print("\n".join(res))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# D - Sum of Divisors
from numba import njit


@njit
def solve(N):
    res = 0
    for a in range(1, N + 1):
        for b in range(1, N // a + 1):
            res += a * b
    return res


def main():
    N = int(input())
    print(solve(N))


if __name__ == "__main__":
    main()


Fixed submission:
# C - Tsundoku
from bisect import bisect
from itertools import accumulate


def main():
    N, M, K, *AB = map(int, open(0).read().split())
    cum_A, cum_B = tuple(accumulate(AB[:N])), tuple(accumulate(AB[N:]))
    candidates = []
    for cum_x, cum_y in ((cum_A, cum_B), (cum_B, cum_A)):
        for i, x_time in enumerate(cum_x, 1):
            if x_time > K:
                candidates.append(0)
                break
            y_time = K - x_time
            candidates.append(i + bisect(cum_y, y_time))
    print(max(candidates))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# D - Sum of Divisors
def main():
    N = int(input())
    res = 0
    for a in range(1, N + 1):
        for b in range(1, N // a + 1):
            res += a * b
    print(res)


if __name__ == "__main__":
    main()


Fixed submission:
# D - Sum of Divisors
def main():
    N = int(input())
    res = 0
    for a in range(1, N + 1):
        for b in range(1, N // a + 1):
            res += a * b
    print(res)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
# D - Sum of Divisors
from numba import njit


@njit
def main():
    N = int(input())
    res = 0
    for a in range(1, N + 1):
        for b in range(1, N // a + 1):
            res += a * b
    print(res)


if __name__ == "__main__":
    main()


Fixed submission:
# D - Sum of Divisors
def main():
    N = int(input())
    res = 0
    for a in range(1, N + 1):
        for b in range(1, N // a + 1):
            res += a * b
    print(res)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# B - Multiplication 2
from functools import reduce
from operator import mul


def main():
    _, *A = map(int, open(0).read().split())
    prod = reduce(mul, A)
    print(prod if prod <= 10 ** 18 else -1)


if __name__ == "__main__":
    main()


Fixed submission:
# B - Multiplication 2
def main():
    _, *A = map(int, open(0).read().split())
    if 0 in A:
        print(0)
        return 
    prod = 1
    LIM = 10 ** 18
    for i in A:
        prod *= i
        if prod > LIM:
            print(-1)
            return
    print(prod)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# A - Registration
def main():
    S, T = map(int, open(0).read().split())
    print("Yes" if T[:-1] == S else "No")


if __name__ == "__main__":
    main()


Fixed submission:
# A - Registration
def main():
    S, T = open(0).read().split()
    print("Yes" if T[:-1] == S else "No")


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
# A - Registration
def main():
    S, T = input().rstrip().split()
    print("Yes" if T[:-1] == S else "No")


if __name__ == "__main__":
    main()


Fixed submission:
# A - Registration
def main():
    S, T = open(0).read().split()
    print("Yes" if T[:-1] == S else "No")


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# D - RGB Triplets
def main():
    _ = int(input())
    S = input().rstrip()
    cnt = 0
    for j, b in enumerate(S[1:-1], 1):
        for i, a in enumerate(S[:j]):
            for k, c in enumerate(S[j + 1 :], j + 1):
                if a == b or a == c or b == c:
                    continue
                elif j - i == k - j:
                    continue
                cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()


Fixed submission:
# D - RGB Triplets
from collections import defaultdict


def main():
    _ = int(input())
    S = input().rstrip()
    indices = defaultdict(set)
    for i, c in enumerate(S):
        indices[c].add(i)
    cnt = len(indices["R"]) * len(indices["G"]) * len(indices["B"])
    for c1, c2, c3 in ["RGB", "GBR", "BRG"]:
        cnt -= sum(
            (i + j) % 2 == 0 and (i + j) // 2 in indices[c3]
            for i in indices[c1]
            for j in indices[c2]
        )
    print(cnt)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# E - Yutori
from typing import List


def find_workdays(
    total_days: int, workdays_length: int, days_off_length: int, schedule: List[bool]
) -> List[int]:
    if days_off_length == 0:
        workdays = [i for i, can_work in enumerate(schedule, 1) if can_work]
        return workdays if len(workdays) <= workdays_length else []

    workdays_left, workdays_right = [], []

    for workdays, gen in [
        (workdays_left, enumerate(schedule, 1)),
        (workdays_right, ((total_days - i, x) for i, x in enumerate(schedule[::-1]))),
    ]:
        days_off = 0
        for i, can_work in gen:
            if days_off:
                days_off -= 1
                continue
            if can_work:
                workdays.append(i)
                days_off = days_off_length
                if len(workdays) == workdays_length:
                    break

    return [l for l, r in zip(workdays_left, workdays_right[::-1]) if l == r]


def main():
    N, K, C = map(int, input().split())
    S = input().rstrip()
    workdays = find_workdays(N, K, C, [s == "o" for s in S])
    print("\n".join(map(str, workdays)))


if __name__ == "__main__":
    main()


Fixed submission:
# E - Yutori


def find_workdays(
    total_days: int, workdays_length: int, days_off_length: int, schedule: list
) -> list:
    if days_off_length == 0:
        workdays = [i for i, can_work in enumerate(schedule, 1) if can_work]
        return workdays if len(workdays) <= workdays_length else []

    workdays_left, workdays_right = set(), set()

    cur_days_off = 0
    for i, can_work in enumerate(schedule, 1):
        if cur_days_off:
            cur_days_off -= 1
            continue
        if can_work:
            workdays_left.add(i)
            cur_days_off = days_off_length
            if len(workdays_left) == workdays_length:
                break

    cur_days_off = 0
    for i, can_work in enumerate(schedule[::-1]):
        if cur_days_off:
            cur_days_off -= 1
            continue
        if can_work:
            workdays_right.add(total_days - i)
            cur_days_off = days_off_length
            if len(workdays_right) == workdays_length:
                break

    return sorted(workdays_left & workdays_right)


def main():
    N, K, C = map(int, input().split())
    S = input().rstrip()
    workdays = find_workdays(N, K, C, [s == "o" for s in S])
    print("\n".join(map(str, workdays)))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# C - Tax Increase
from math import floor


def calc(a: int, b: int) -> int:
    for i in range(1, 1010):
        if floor(i * 0.08) == a and floor(i * 0.1) == b:
            return i
    return -1


def main():
    A, B = map(int, input().split())
    print(calc(A, B))


if __name__ == "__main__":
    main()


Fixed submission:
# B - Count Balls
def main():
    N, A, B = map(int, input().split())
    ans = N // (A + B) * A + min(A, N % (A + B))
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
/* 
 * Created by solzard on 2020-03-05.
 * 
 */
#include <iostream>
#include <vector>
#include <unordered_set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

bool is_bingo(int player) {
  std::unordered_set<int> winnable_conditions
      {0b111000000, 0b000111000, 0b000000111, 0b100100100, 0b010010010, 0b001001001, 0b100010001, 0b001010100};
  for (const auto &condition : winnable_conditions) {
    if ((player & condition) == condition) return true;
  }
  return false;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);

  std::vector<int> sheet;
  std::unordered_set<int> bingo;
  int a, n, b;
  rep(_, 9) {
    std::cin >> a;
    sheet.emplace_back(a);
  }
  std::cin >> n;
  rep(_, n) {
    std::cin >> b;
    bingo.emplace(b);
  }
  int player = 0;
  rep(i, 9) {
    if (bingo.find(sheet[i]) != bingo.end()) {
      player |= 1 << i;
    }
  }
  std::cout << (is_bingo(player) ? "Yes" : "No") << "\n";
}


Fixed submission:
# B - Bingo
def is_winnable(player: int) -> bool:
    winnable_conditions = \
        {0b111000000, 0b000111000, 0b000000111, 0b100100100, 0b010010010, 0b001001001, 0b100010001, 0b001010100}
    return any(player & condition == condition for condition in winnable_conditions)


def main():
    *ANB, = map(int, open(0).read().split())
    A, B = ANB[:9], set(ANB[10:])
    player = 0b000000000
    for i, a in enumerate(A):
        if a in B:
            player |= 1 << i
    print("Yes" if is_winnable(player) else "No")


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
/* 
 * Created by solzard on 2020-03-05.
 * 
 */
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

bool is_bingo(int player) {
  std::unordered_set<int> winnable_conditions
      {0b111000000, 0b000111000, 0b000000111, 0b100100100, 0b010010010, 0b001001001, 0b100010001, 0b001010100};
  for (const auto &condition : winnable_conditions) {
    if ((player & condition) == condition) return true;
  }
  return false;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);

  std::vector<int> sheet;
  std::unordered_set<int> bingo;
  int a, n, b;
  rep(_, 9) {
    std::cin >> a;
    sheet.emplace_back(a);
  }
  std::cin >> n;
  rep(_, n) {
    std::cin >> b;
    bingo.emplace(b);
  }
  int player = 0;
  rep(i, 9) {
    if (bingo.find(sheet[i]) != std::end(bingo)) {
      player |= 1 << i;
    }
  }
  std::cout << (is_bingo(player) ? "Yes" : "No") << "\n";
}



Fixed submission:
# B - Bingo
def is_winnable(player: int) -> bool:
    winnable_conditions = \
        {0b111000000, 0b000111000, 0b000000111, 0b100100100, 0b010010010, 0b001001001, 0b100010001, 0b001010100}
    return any(player & condition == condition for condition in winnable_conditions)


def main():
    *ANB, = map(int, open(0).read().split())
    A, B = ANB[:9], set(ANB[10:])
    player = 0b000000000
    for i, a in enumerate(A):
        if a in B:
            player |= 1 << i
    print("Yes" if is_winnable(player) else "No")


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# C - Guess The Number
def guess_number(N: int, M: int, conditions: list) -> int:
    if N == 1:
        digit, num = conditions[0]
        if len(set(conditions)) == 1 and digit == 1:
            return num
        return -1

    if any(cond == (1, 0) for cond in conditions):  # 1st digit mustn't be 0
        return -1

    result = [0] * N
    for digit, num in conditions:
        if result[-digit] not in (0, num):
            return -1
        result[-digit] = num
    return sum(x * (10 ** i) for i, x in enumerate(result))


def main():
    N, M, *SC = map(int, open(0).read().split())
    conditions = list(zip(*[iter(SC)] * 2))
    ans = guess_number(N, M, conditions)
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
# C - Guess The Number
def guess_number(N: int, conditions: list) -> int:
    if N > 1 and any(cond == (1, 0) for cond in conditions):  # 1st digit mustn't be 0 if N > 1
        return -1
    result = [-1] * N
    for digit, num in conditions:
        if result[-digit] >= 0 and result[-digit] != num:
            return -1
        result[-digit] = num
    if result[-1] == -1:  # 1st digit must be 1 if N > 1 (no leading zeros)
        result[-1] = 1 if N > 1 else 0
    return sum(x * (10 ** i) if x != -1 else 0 for i, x in enumerate(result))


def main():
    N, M, *SC = map(int, open(0).read().split())
    conditions = list(zip(*[iter(SC)] * 2))
    ans = guess_number(N, conditions)
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
# C - Guess The Number
def guess_number(N: int, M: int, conditions: list) -> int:
    if N == 1:
        digit, num = conditions[0]
        if M != 1 or digit != 1:
            return -1
        return num

    if any(cond == (1, 0) for cond in conditions):  # 1st digit mustn't be 0
        return -1

    result = [0] * N
    for digit, num in conditions:
        if result[-digit] not in (0, num):
            return -1
        result[-digit] = num
    return sum(x * (10 ** i) for i, x in enumerate(result))


def main():
    N, M, *SC = map(int, open(0).read().split())
    conditions = list(zip(*[iter(SC)] * 2))
    ans = guess_number(N, M, conditions)
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
# C - Guess The Number
def guess_number(N: int, conditions: list) -> int:
    if N > 1 and any(cond == (1, 0) for cond in conditions):  # 1st digit mustn't be 0 if N > 1
        return -1
    result = [-1] * N
    for digit, num in conditions:
        if result[-digit] >= 0 and result[-digit] != num:
            return -1
        result[-digit] = num
    if result[-1] == -1:  # 1st digit must be 1 if N > 1 (no leading zeros)
        result[-1] = 1 if N > 1 else 0
    return sum(x * (10 ** i) if x != -1 else 0 for i, x in enumerate(result))


def main():
    N, M, *SC = map(int, open(0).read().split())
    conditions = list(zip(*[iter(SC)] * 2))
    ans = guess_number(N, conditions)
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# F - Many Many Paths
def get_factorials(lim: int, MOD: int) -> list:
    """Compute a table of factorials (1-indexed)."""
    factorials = [1] * (lim + 1)
    x = 1
    for i in range(1, lim + 1):
        x *= i % MOD
        factorials[i] = x
    return factorials


def mod_comb_with_pow(n: int, k: int, MOD: int) -> int:
    """Compute nCr % MOD using pow(), not an inverse factorial table."""
    return fact[n] * pow(fact[k], MOD - 2, MOD) * pow(fact[n - k], MOD - 2, MOD) % MOD


def main():
    global fact
    MOD = 10 ** 9 + 7
    R1, C1, R2, C2 = map(int, input().split())
    fact = get_factorials(2 * 10 ** 6 + 10, MOD)
    f = lambda x, y: mod_comb_with_pow(x, y, MOD)
    ans = (f(C1 + R1, R1) - f(C1 + R2 + 1, R2 + 1) - f(C2 + R1 + 1, R1) + f(C2 + R2 + 2, R2 + 1)) % MOD
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
# F - Many Many Paths
def get_factorials(lim: int, MOD: int) -> list:
    """Compute a table of factorials (1-indexed)."""
    factorials = [1] * (lim + 1)
    x = 1
    for i in range(1, lim + 1):
        x = (x * i) % MOD
        factorials[i] = x
    return factorials


def mod_comb_with_pow(n: int, k: int, MOD: int) -> int:
    """Compute nCr % MOD using pow(), not an inverse factorial table."""
    return fact[n] * pow(fact[k], MOD - 2, MOD) * pow(fact[n - k], MOD - 2, MOD) % MOD


def main():
    global fact
    MOD = 10 ** 9 + 7
    R1, C1, R2, C2 = map(int, input().split())
    fact = get_factorials(2 * 10 ** 6 + 10, MOD)
    f = lambda x, y: mod_comb_with_pow(x, y, MOD)
    ans = (f(C1 + R1, R1) - f(C1 + R2 + 1, R2 + 1) - f(C2 + R1 + 1, R1) + f(C2 + R2 + 2, R2 + 1)) % MOD
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
# A - Painting
import sys

debug = lambda message: sys.stderr.write(message)


def main():
    H, W, N = map(int, open(0))
    debug(max(H, W))
    print((N + max(H, W) - 1) // max(H, W))


if __name__ == "__main__":
    main()


Fixed submission:
# A - Painting
import sys

debug = lambda message: print("DEBUG:", message, file=sys.stderr)


def main():
    H, W, N = map(int, open(0))
    debug(max(H, W))
    print((N + max(H, W) - 1) // max(H, W))


if __name__ == "__main__":
    main()