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

Fixed submission:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
INF = float("inf")
import sys
sys.setrecursionlimit(10000)


def solve(N, S):
    if "Y" in S:
        return "Four"
    else:
        return "Three"


def main():
    N = int(input())
    S = list(input().split())
    print(solve(N, S))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def main():
    N = int(input())
    S = list(map(int, input().split()))

    if "Y" in S:
        print("Four")
    else:
        print("Three")

if __name__ == '__main__':
    main()
Problem p03489 (python)

Fixed submission:
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def ceil(a, b): return (a + b - 1) // b


def main():
    N = int(input())
    a = Counter(list(map(int, input().split())))

    ans = 0
    for k, v in a.items():
        if k == v:
            continue
        elif k < v:
            ans += v - k
        else:
            ans += v
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def ceil(a, b): return (a + b - 1) // b

YES = "Yes"
NO = "No"


def check(x, nums):
    x = abs(x)
    dp = [False] * (x + 1)
    dp[0] = True
    for y in nums:
        tmp = [False] * (x + 1)
        for i in range(len(dp)):
            if i + y < len(tmp):
                tmp[i + y] |= dp[i]
            if i - y >= 0:
                tmp[i - y] |= dp[i]
        dp = tmp
    return dp[x]


def solve(s, x, y):
    type_num = [(k, len(list(g))) for k, g in groupby(s)]
    if s[0] == "F":
        x -= type_num[0][1]
        type_num.pop(0)

    h, v = [], []
    now = 0
    for t, n in type_num:
        if t == "F":
            if now == 0:
                h.append(n)
            else:
                v.append(n)
        else:
            if n % 2 != 0:
                now = (now + 1) % 2
    return YES if check(x, h) and check(y, v) else NO


def main():
    s = input()
    x, y = map(int, input().split())

    print(solve(s, x, y))

if __name__ == '__main__':
    main()
Problem p03503 (python)

Fixed submission:
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    N = int(input())
    F = [[0] * 10 for _ in range(N)]
    for i in range(N):
        s = input().split()
        for j in range(10):
            F[i][j] = int(s[j])
    P = [[0] * 11 for _ in range(N)]
    for i in range(N):
        s = input().split()
        for j in range(11):
            P[i][j] = int(s[j])

    ans = -INF
    # 2 ^ nの組み合わせの全列挙
    for b in range(1, 2 ** 10):
        o = [0] * 10
        for i in range(10):
            if b & 1 << i:
                o[i] = 1

        total = 0
        for i in range(N):
            c = 0
            for j in range(10):
                if o[j] == 1 and F[i][j] == 1:
                    c += 1
            total += P[i][c]
        ans = max(ans, total)
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    N = int(input())
    F = [[0] * 10 for _ in range(N)]
    for i in range(N):
        s = input().split()
        for j in range(10):
            F[i][j] = int(s[j])
    P = [[0] * 10 for _ in range(N)]
    for i in range(N):
        s = input().split()
        for j in range(10):
            P[i][j] = int(s[j])

    ans = -INF
    # 2 ^ nの組み合わせの全列挙
    for b in range(1, 2 ** 10):
        o = [0] * 10
        for i in range(10):
            if b & 1 << i:
                o[i] = 1

        total = 0
        for i in range(N):
            c = 0
            for j in range(10):
                if o[j] == 1 and F[i][j] == 1:
                    c += 1
            total += P[i][c]
        ans = max(ans, total)
    print(ans)


if __name__ == '__main__':
    main()
Problem p03559 (python)

Fixed submission:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")

from bisect import bisect, bisect_left, bisect_right



# Find rightmost value less than x
def find_lt(a, x):
    i = bisect_left(a, x)
    if i:
        return i
    return 0


# Find leftmost value greater than x'
def find_gt(a, x):
    i = bisect_right(a, x)
    if i != len(a):
        return i
    return len(a)


def main():
    N = int(input())
    A = list(sorted(list(map(int, input().split()))))
    B = list(sorted(list(map(int, input().split()))))
    C = list(sorted(list(map(int, input().split()))))

    ans = 0
    for b in B:
        a = find_lt(A, b)
        b = N - find_gt(C, b)
        ans += a * b
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")

from bisect import bisect, bisect_left, bisect_right



# Find rightmost value less than x
def find_lt(a, x):
    i = bisect_left(a, x)
    if i:
        return i
    raise ValueError



# Find leftmost value greater than x'
def find_gt(a, x):
    i = bisect_right(a, x)
    if i != len(a):
        return i
    raise ValueError




def main():
    N = int(input())
    A = list(sorted(list(map(int, input().split()))))
    B = list(sorted(list(map(int, input().split()))))
    C = list(sorted(list(map(int, input().split()))))

    ans = 0
    for b in B:
        a = find_lt(A, b)
        b = N - find_gt(C, b)
        ans += a * b
    print(ans)


if __name__ == '__main__':
    main()
Problem p03573 (python)

Fixed submission:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    A, B, C = map(int, input().split())
    if A == B:
        print(C)
    elif A == C:
        print(B)
    elif B == C:
        print(A)



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


memo1 = {}
memo2 = {}

def ok(y1, y2, x1, x2, yd, yd2, xd, xd2, K):
    global memo1, memo2
    if (y1, y2) in memo1:
        a, b = memo1[(y1, y2)]
    else:
        a = yd2[y1]
        b = yd[y2]
        memo1[(y1, y2)] = (a, b)
    y = b.difference(a)

    if (x1, x2) in memo2:
        c, d =memo2[(x1, x2)]
    else:
        c = xd2[x1]
        d = xd[x2]
        memo2[(x1, x2)] = (c, d)

    x = d.difference(c)
    # print(a, b, c, d)
    # print(y, x)

    n = len(y & x)

    return n >= K


def main():
    N, K = map(int, input().split())
    f = []
    ys, xs = [], []
    for i in range(N):
        x, y = map(int, input().split())
        f.append((y, x))
        ys.append((y, i))
        xs.append((x, i))

    ys.sort()
    yd = defaultdict(set)
    yd2 = defaultdict(set)
    old = set()
    for y, i in ys:
        yd2[y] = old.copy()
        old.add(i)
        yd[y] = old.copy()

    xs.sort()
    xd = defaultdict(set)
    xd2 = defaultdict(set)
    old = set()
    for x, i in xs:
        xd2[x] = old.copy()
        old.add(i)
        xd[x] = old.copy()

    ans = INF

    # print(yd)
    # print(xd)
    #
    # print(ok(1, 4, 1, 8, yd, yd2, xd, xd2, K))
    for i, j in combinations(range(N), 2):
        for k, l in combinations(range(N), 2):
            a, b, c, d = ys[i], ys[j], xs[k], xs[l]
            y1 = min([a[0], b[0]])
            y2 = max([a[0], b[0]])

            x1 = min([c[0], d[0]])
            x2 = max([c[0], d[0]])

            # print(i, j)
            # print(x1, x2, abs(x1 - x2))
            # print(y1, y2, abs(y1 - y2))
            # print(ok(y1, y2, x1, x2, yd, yd2, xd, xd2, K))
            if ok(y1, y2, x1, x2, yd, yd2, xd, xd2, K):
                ans = min(ans, abs(x1 - x2) * abs(y1 - y2))

    print(ans)


if __name__ == '__main__':
    main()
Problem p03633 (python)

Fixed submission:
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a // g * b


def main():
    N = int(input())
    t_list = list(sorted([int(input()) for _ in range(N)]))
    ans = 1
    for t in t_list:
        ans = lcm(ans, t)

    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, gcd
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def lcm(a, b):
    g = gcd(a, b)
    return a // g * b


def main():
    N = int(input())
    T = []
    for _ in range(N):
        T.append(int(input()))

    ans = 1
    for t in T:
        ans = lcm(ans, t)
    print(ans)


if __name__ == '__main__':
    main()
Problem p03671 (python)

Fixed submission:
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    a = list(map(int, input().split()))
    print(sum(a) - max(a))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    n = int(input())
    a_list = list(map(int, input().split()))

    a_list = [1] * (2 * 10 ** 5)
    ans = []
    for i in range(1, len(a_list), 2):
        ans.append(a_list[i])
    ans = ans[::-1]
    for i in range(0, len(a_list), 2):
        ans.append(a_list[i])

    if n % 2 != 0:
        ans = ans[::-1]
    print(*ans)


if __name__ == '__main__':
    main()
Problem p03683 (python)

Fixed submission:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, factorial
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10
MOD = 10 ** 9 + 7

def main():
    N, M = map(int, input().split())
    diff = abs(N - M)
    if diff > 1:
        print(0)
        return

    ans = 2 if diff == 0 else 1
    for i in range(1, N + 1):
        ans = (ans * i) % MOD
    for i in range(1, M + 1):
        ans = (ans * i) % MOD
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, gcd, factorial
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10
MOD = 10 ** 9 + 7

def main():
    N, M = map(int, input().split())
    diff = abs(N - M)
    if diff > 1:
        print(0)
        return

    ans = 2 if diff == 0 else 1
    for i in range(1, N + 1):
        ans = (ans * i) % MOD
    for i in range(1, M + 1):
        ans = (ans * i) % MOD
    print(ans)


if __name__ == '__main__':
    main()
Problem p03813 (python)

Fixed submission:
x = int(input())
if x < 1200:
    print("ABC")
else:
    print("ARC")

Buggy submission (verdict: Runtime Error):
from collections import defaultdict


def main():
    n = int(input())
    card_list = list(map(int, input().split()))

    ans = len(set(card_list))

    d = defaultdict(int)
    for card in card_list:
        d[card] += 1

    one, two = 0, 0
    for card, num in d.items():
        if num % 2 == 1:
            one += 1
        else:
            two += 1

    print(ans - two % 2)


if __name__ == '__main__':
    main()
Problem p03855 (python)

Fixed submission:
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 5 + 1)


class UnionFind:
    def __init__(self, size):
        self.parent = list(range(size))

    def is_same_set(self, x: int, y: int) -> bool:
        return self.find_root(x) == self.find_root(y)

    def union_set(self, x: int, y: int):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return

        self.parent[x] = y

    def find_root(self, x: int):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find_root(self.parent[x])
            return self.parent[x]


def main():
    N, K, L = map(int, input().split())
    uf1 = UnionFind(N)
    for _ in range(K):
        p, q = map(int, input().split())
        p -= 1
        q -= 1
        uf1.union_set(p, q)

    uf2 = UnionFind(N)
    for _ in range(L):
        r, s = map(int, input().split())
        r -= 1
        s -= 1
        uf2.union_set(r, s)

    groups = [(uf1.find_root(i), uf2.find_root(i)) for i in range(N)]
    c = Counter(groups)

    print(*(c[g] for g in groups))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict


class UnionFind:
    def __init__(self, size):
        self.parent = list(range(size + 1))

    def is_same_set(self, x: int, y: int) -> bool:
        return self.find_root(x) == self.find_root(y)

    def union_set(self, x: int, y: int):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return

        self.parent[x] = y

    def find_root(self, x: int):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find_root(self.parent[x])
            return self.parent[x]


def dfs(n, used, edges, uf: UnionFind):
    used[n] = True
    for a in edges[n]:
        if not used[a]:
            uf.union_set(n, a)
            dfs(a, used, edges, uf)


def main():
    N, K, L = map(int, input().split())
    d1 = defaultdict(list)
    for _ in range(K):
        p, q = map(int, input().split())
        p -= 1
        q -= 1
        d1[p].append(q)
        d1[q].append(p)

    d2 = defaultdict(list)
    for _ in range(L):
        r, s = map(int, input().split())
        r -= 1
        s -= 1
        d2[r].append(s)
        d2[s].append(r)

    uf1 = UnionFind(N)
    used1 = [False] * N
    for n in range(N):
        if not used1[n]:
            dfs(n, used1, d1, uf1)

    uf2 = UnionFind(N)
    used2 = [False] * N
    for n in range(N):
        if not used2[n]:
            dfs(n, used2, d2, uf2)

    used3 = [False] * N
    ans = [0] * N
    for n1 in range(N):
        if used3[n1]:
            continue
        num = 1
        l = [n1]
        for n2 in range(n1 + 1, N):
            if not used3[n2]:
                if uf1.is_same_set(n1, n2) and uf2.is_same_set(n1, n2):
                    used3[n2] = True
                    l.append(n2)
                    num += 1
        for n in l:
            ans[n] = num

    print(" ".join(map(str, ans)))


if __name__ == '__main__':
    main()
Problem p03999 (python)

Fixed submission:


# all_split("abc") -> [['abc'], ['ab', 'c'], ['a', 'bc'], ['a', 'b', 'c']]
def all_split(s):
    if len(s) == 1:
        return [s]
    
    ans = []
    for i in range(2 ** (len(s) - 1)):
        b = list(map(int, format(i, "0" + str(len(s) - 1) + "b")))
        ans.append(split(s, b))
    return ans


def split(s, split_positions):
    assert len(s) - 1 == len(split_positions)

    ans = []
    pre = 0
    for i, is_split in enumerate(split_positions, start=1):
        if is_split:
            ans.append(s[pre:i])
            pre = i

    ans.append(s[pre:])
    return ans


def main():
    s = input()
    ans = 0
    for a in all_split(s):
        ans += eval("+".join(a))
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):


# all_split("abc") -> [['abc'], ['ab', 'c'], ['a', 'bc'], ['a', 'b', 'c']]
def all_split(s):
    ans = []
    for i in range(2 ** (len(s) - 1)):
        b = list(map(int, format(i, "0" + str(len(s) - 1) + "b")))
        ans.append(split(s, b))
    return ans


def split(s, split_positions):
    assert len(s) - 1 == len(split_positions)

    ans = []
    pre = 0
    for i, is_split in enumerate(split_positions, start=1):
        if is_split:
            ans.append(s[pre:i])
            pre = i

    ans.append(s[pre:])
    return ans


def main():
    s = input()
    ans = 0
    for a in all_split(s):
        ans += eval("+".join(a))
    print(ans)


if __name__ == '__main__':
    main()
Problem p04014 (python)

Fixed submission:
from math import floor, sqrt
INF = 10 ** 20


def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n // b) + (n % b)


def main():
    n = int(input())
    s = int(input())

    ans = INF
    # 1桁
    if n == s:
        ans = min(ans, n + 1)

    # 2桁
    for p in range(1, int(sqrt(n)) + 1):
        q = s - p
        b = (n - q) // p
        if 2 <= b and f(b, n) == s:
            ans = min(ans, b)

    # 3桁以上
    for b in range(2, int(sqrt(n)) + 1):
        if f(b, n) == s:
            ans = min(ans, b)

    print(-1 if ans == INF else ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def f(b, n):
    if n < b:
        return n
    return f(b, n // b) + n % b


def main():
    N = int(input())
    S = int(input())

    if N < S:
        print(-1)
        return

    ans = INF
    for b in range(2, int(sqrt(N)) + 1):
        if f(b, N) == S:
            ans = min(ans, b)

    bs = set()
    t = N - S
    for i in range(1, int(sqrt(t)) + 5):
        if t % i == 0:
            bs.add(i)
            bs.add(t // i)
    bs.add(N)
    bs.add(N + 1)

    for b in bs:
        if b == 1:
            continue
        if f(b, N) == S:
            ans = min(ans, b)

    if ans == INF:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()
Problem p02641 (python)

Fixed submission:
import bisect
def main():
  X, N = map(int, input().split())
  if N == 0:
    print(X)
    return
  P = set(map(int, input().split()))

  NP = sorted(list(set(range(102)) - P))
  right = bisect.bisect(NP, X)
  left = right - 1
  if left == -1 or abs(X - NP[left]) > abs(X - NP[right]):
    print(NP[right])
  else:
    print(NP[left])

main()

Buggy submission (verdict: Runtime Error):
import bisect
def main():
  X, N = map(int, input().split())
  if N == 0:
    print(X)
    return
  P = set(map(int, input().split()))

  NP = sorted(list(set(range(101)) - P))
  right = bisect.bisect(NP, X)
  left = right - 1
  if abs(X - NP[left]) <= abs(X - NP[right]):
    print(NP[left])
  else:
    print(NP[right])
    
main()
Problem p02658 (python)

Fixed submission:
def solve():
  ans = 1
  if 0 in A:
    return 0
  for i in A:
    ans *= i
    if ans > 1e18:
      return -1
  return ans


N = int(input())
A = list(map(int, input().split()))
print(solve())

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
ans = 1
for i in A:
  ans *= i
  if ans > 1e18:
  	print(-1)
    return
  
if ans > 1e18:
  print(-1)
else:
  print(ans)