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

Fixed submission:
def main():
    length, sum_num, subarray_sum = map(int, input().split())
    answer = [subarray_sum] * sum_num
    if subarray_sum == 10 ** 9:
        answer += [1] * (length - sum_num)
    else:
        answer += [subarray_sum + 1] * (length - sum_num)
    print(" ".join(map(str, answer)))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from math import ceil


def main():
    length, sum_num, subarray_sum = map(int, input().split())
    base_length = ceil(length / sum_num)
    base_array = [subarray_sum]
    base_array += [10 ** 9 if subarray_sum < 10 ** 9 else 1] * (base_length - 1)
    print(" ".join(map(str, (base_array * (length // base_length + 1))[:length])))


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

Fixed submission:
def main():
    target = int(input())
    answer = False
    for i in range(1, 1001):
        if i * 100 <= target <= i * 105:
            answer = True
            break
    print(1 if answer else 0)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    target = int(input())
    cost = [101, 102, 103, 104, 105]
    answer = False
    for i in range(32):
        choice = bin(i)[2:].zfill(5)
        result = 0
        for j in range(5):
            result += cost[j] * int(choice[j])
        if (result % 100) % (target % 100) == 0 and result <= target:
            answer = True
            break
    print(1 if answer else 0)


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

Fixed submission:
from collections import deque


def main():
    vertex = int(input())
    tree = [[] for _ in range(vertex + 1)]
    color = [0] * (vertex + 1)
    parent = [0] * (vertex + 1)
    order = []
    ab = []
    for i in range(vertex - 1):
        a, b = map(int, input().split())
        tree[a].append(b)
        tree[b].append(a)
        ab.append([a, b])
    queue = deque([1])

    # 木の親を決める
    while queue:
        now = queue.popleft()
        order.append(now)
        for t in tree[now]:
            if not t == parent[now]:
                parent[t] = now
                queue.append(t)

    # 色番号を割り当てる
    for ord in order:
        ng = color[ord]
        color_num = 1
        for t in tree[ord]:
            if not t == parent[ord]:
                if color_num == ng:
                    color_num += 1
                color[t] = color_num
                color_num += 1

    print(max(color))
    for a, b in ab:
        if a == parent[b]:
            print(color[b])
        else:
            print(color[a])


if __name__ == '__main__':
    main()

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


def main():
    vertex = int(input())
    tree = [[] for _ in range(vertex + 1)]
    color = [0] * (vertex + 1)
    for i in range(1, vertex):
        a, b = map(int, input().split())
        tree[a].append((b, i))
        tree[b].append((a, i))
    max_deg = 0
    root = 0
    for i in range(1, vertex):
        if max_deg < len(tree[i]):
            root = i
            max_deg = len(tree[i])
    queue = deque([root])
    while not queue == deque():
        color_list = [i for i in range(1, max_deg + 1)]
        now = queue.pop()
        for i, n in enumerate(tree[now]):
            if color[n[0]] == 0:
                color[n[0]] = color_list[0]
                queue.append(n[1])
                color_list.pop(0)
            else:
                color_list.remove(color[n[0]])
    print(max_deg)
    for c in color[2:]:
        print(c)


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

Fixed submission:
from bisect import bisect_left


def main():
    N = int(input())
    L = list(map(int, input().split(" ")))
    L.sort()
    result = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = bisect_left(L, L[i] + L[j])
            result += k - j - 1
    print(result)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def triangle(a, b, c):
    return (a < b + c) and (b < a + c) and (c < a + b)


def main():
    N = int(input())
    ll = input().split(" ")
    ll.sort()
    ll.reverse()
    L = []
    M = []
    tmp = ''
    for l in ll:
        if tmp != l:
            L.append(int(l))
            tmp = l
        else:
            M.append(int(l))
    result = 0
    # 3辺相異なるとき
    for i in range(len(L)):
        for j in range(i + 1, len(L)):
            a = L[i]
            b = L[j]
            for k in range(j + 1, len(L)):
                c = L[k]
                if triangle(a, b, c):
                    result += 1

    # 二等辺(正三角形含む)
    tmp = False
    for i in range(len(M)):
        a = M[i]
        for j in range(i + 1, len(M)):
            b = j[i]
            if a == b and tmp:
                tmp = True
                result += 1
            elif a == b and not tmp:
                continue
            elif triangle(a, a, b):
                tmp = False
                result += 1
            else:
                continue

    print(result)


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

Fixed submission:
from fractions import gcd


def main():
    A, B = map(int, input().split(" "))
    g = gcd(A, B)
    answer = [1]
    while not g % 2:
        g //= 2
        answer.append(2)
    i = 3
    while i * i <= g:
        if not g % i:
            g //= i
            answer.append(i)
        else:
            i += 2
    if not g == 1:
        answer.append(g)
    print(len(set(answer)))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from math import gcd


def main():
    A, B = map(int, input().split(" "))
    g = gcd(A, B)
    answer = [1]
    while not g % 2:
        g //= 2
        answer.append(2)
    i = 3
    while i * i <= g:
        if not g % i:
            g //= i
            answer.append(i)
        else:
            i += 2
    if not g == 1:
        answer.append(g)
    print(len(set(answer)))


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

Fixed submission:
def main():
    N = int(input())
    flag = True
    tascs = []
    for _ in range(N):
        a, b = map(int, input().split(" "))
        tmp = [a, b]
        tascs.append(tuple(tmp))
    tascs.sort(key=lambda x: x[1])
    passed_time = 0
    for tasc in tascs:
        passed_time += tasc[0]
        if passed_time > tasc[1]:
            flag = False
            break
    if flag:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = []
    B = []
    b_max = 0
    for _ in range(N):
        a, b = map(int, input().split(" "))
        A.append(a)
        B.append(b)
        if b_max < b:
            b_max = b
    tasks = [0] * (b_max + 1)
    for i in range(N):
        tasks[B[i]] += A[i]
    time = 0
    flag = True
    for i, task in enumerate(tasks):
        if i == 0:
            continue
        time += task
        if time > i:
            flag = False
            break
    if flag:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = []
    B = []
    b_max = 0
    for _ in range(N):
        a, b = map(int, input().split(" "))
        A.append(a)
        B.append(b)
        if b_max < b:
            b_max = b
    tasks = [0] * (b_max + 1)
    for i in range(N):
        tasks[B[i]] += A[i]
    time = 0
    flag = True
    for i, task in enumerate(tasks):
        if i == 0 or task == 0:
            continue
        time += task
        if time > i:
            flag = False
            break
    if flag:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = []
    B = []
    for _ in range(N):
        a, b = map(int, input().split(" "))
        A.append(a)
        B.append(b)
    tasks = [0] * (max(B) + 1)
    for i in range(N):
        tasks[B[i]] += A[i]
    time = 0
    flag = True
    for i, task in enumerate(tasks):
        if i == 0 or task == 0:
            continue
        time += task
        if time > i:
            flag = False
            break
    if flag:
        print("Yes")
    else:
        print("No")


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

Fixed submission:
def main():
    N, Q = map(int, input().split(" "))
    S = input()
    result = [0] * (N + 1)
    for i in range(1, N + 1):
        if S[i-1:i+1] == "AC":
            result[i] = result[i - 1] + 1
        else:
            result[i] = result[i - 1]
    for _ in range(Q):
        l, r = map(int, input().split(" "))
        print(result[r - 1] - result[l - 1])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N, Q = map(int, input().split(" "))
    S = input()
    result = [0] * (N + 1)
    for i in range(1, Q + 1):
        if S[i-1:i+1] == "AC":
            result[i] = result[i - 1] + 1
        else:
            result[i] = result[i - 1]
    for _ in range(Q):
        l, r = map(int, input().split(" "))
        print(result[l] - result[r - 1])


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

Fixed submission:
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)


def main():
    n, m = map(int, input().split())
    graph = [[] for _ in range(n)]
    for _ in range(m):
        x, y = map(lambda x: int(x) - 1, input().split())
        graph[x].append(y)
    dp = [-1 for _ in range(n)]
    # dp[i] := iから距離が最も長い頂点への距離

    def solve(v):
        if dp[v] != -1:
            return dp[v]
        res = 0
        for next_v in graph[v]:
            res = max(res, solve(next_v) + 1)
        dp[v] = res
        return dp[v]

    ans = 0
    for i in range(n):
        ans = max(ans, solve(i))
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, m = map(int, input().split())
    graph = [[] for _ in range(n)]
    for _ in range(m):
        x, y = map(lambda x: int(x) - 1, input().split())
        graph[x].append(y)
    dp = [-1 for _ in range(n)]
    # dp[i] := iから距離が最も長い頂点への距離

    def solve(v):
        if dp[v] != -1:
            return dp[v]
        res = 0
        for next_v in graph[v]:
            res = max(res, solve(next_v) + 1)
        dp[v] = res
        return dp[v]

    ans = 0
    for i in range(n):
        ans = max(ans, solve(i))
    print(ans)


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

Fixed submission:
def solve(n):
    k = 1
    while k * (k + 1) < 2 * n:
        k += 1
    if k * (k + 1) != 2 * n:
        return False, [], -1
    ans = [[] for _ in range(1000)]
    add_num = 1
    ans[1].append(add_num)
    ans[0].append(add_num)
    for i in range(2, k + 1):
        for j in range(i):
            add_num += 1
            ans[i].append(add_num)
            ans[i - j - 1].append(add_num)
    return True, ans, k


def main():
    n = int(input())
    res, ans, k = solve(n)
    if res:
        print("Yes")
        print(k + 1)
        for a in ans:
            if a:
                print(len(a), " ".join(map(str, a)))
            else:
                break
    else:
        print("No")


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def solve(n):
    k = 1
    while k * (k + 1) < 2 * n:
        k += 1
    if k * (k + 1) != 2 * n:
        return False, []
    ans = [[] for _ in range(1000)]
    add_num = 1
    ans[1].append(add_num)
    ans[0].append(add_num)
    for i in range(2, k + 1):
        for j in range(i):
            add_num += 1
            ans[i].append(add_num)
            ans[i - j - 1].append(add_num)
    return True, ans, k


def main():
    n = int(input())
    res, ans, k = solve(n)
    if res:
        print("Yes")
        print(k + 1)
        for a in ans:
            if a:
                print(len(a), " ".join(map(str, a)))
            else:
                break
    else:
        print("No")


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

Fixed submission:
def main():
    all_s = input()
    k = int(input())
    substr = set()
    for i in range(len(all_s)):
        for j in range(1, k + 1):
            substr.add(all_s[i:i + j])
    substr = list(substr)
    substr.sort()
    print(substr[k - 1])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from string import ascii_lowercase


def main():
    all_s = input()
    k = int(input())
    ind = {a: [] for a in ascii_lowercase}
    if len(all_s) == 1:
        print(all_s)
    else:
        for i in range(len(all_s)):
            ind[all_s[i]].append(i)
        for s, index in ind.items():
            if not index:
                continue
            else:
                substr = {s}
                i = 1
                all_substr = len(all_s) * len(index) - sum(index) - 1
                if all_substr < k:
                    k -= all_substr
                    continue
                before_len = 0
                while len(substr) != before_len:
                    before_len = len(substr)
                    for j in index:
                        substr.add(all_s[j:i + j + 1])
                    i += 1
                substr = list(substr)
                substr.sort()
                print(substr[k - 1])
                break


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

Fixed submission:
from fractions import gcd
from functools import reduce


def main():
    n = int(input())
    numbers_gcd = reduce(gcd, list(map(int, input().split())))
    answer = 0
    while numbers_gcd > 0:
        if numbers_gcd % 2:
            break
        else:
            numbers_gcd //= 2
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from math import gcd
from functools import reduce


def main():
    n = int(input())
    numbers_gcd = reduce(gcd, list(map(int, input().split())))
    answer = 0
    while numbers_gcd > 0:
        if numbers_gcd % 2:
            break
        else:
            numbers_gcd //= 2
            answer += 1
    print(answer)


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

Fixed submission:
def main():
    N = int(input())
    permutation = list(map(int, input().split()))
    answer = 0
    for i in range(N):
        if permutation[i] == i + 1:
            if permutation[i] == N:
                permutation[i], permutation[i - 1] = permutation[i - 1], permutation[i]
            else:
                permutation[i], permutation[i + 1] = permutation[i + 1], permutation[i]
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    permutation = list(map(int, input().split()))
    answer = 0
    for i in range(N):
        if permutation[i] == i + 1:
            permutation[i], permutation[i + 1] = permutation[i + 1], permutation[i]
            answer += 1
    print(answer)


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

Fixed submission:
def n_pow(a, n):
    if n <= 0:
        return 0
    return pow(a, n)


def main():
    bags, remainder = map(int, input().split())
    biscuits = list(map(int, input().split()))
    count = [0, 0]
    for b in biscuits:
        count[b % 2] += 1
    if remainder == 1 and count[1] == 0:
        print(0)
    elif count[1] == 0:
        print(pow(2, bags))
    else:
        print(n_pow(2, bags - 1))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def n_pow(a, n):
    if n <= 0:
        return 0
    return pow(a, n)


def main():
    bags, remainder = map(int, input().split())
    biscuits = list(map(int, input().split()))
    count = [0, 0]
    for b in biscuits:
        count[b % 2] += 1
    if remainder == 0:
        print(n_pow(2, count[0]) + n_pow(2, count[1] - 1))
    else:
        print(n_pow(2, count[0] + count[1] - 1, 0))


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

Fixed submission:
from string import ascii_lowercase


def main():
    word = input()
    target_list = list(ascii_lowercase)
    answer = float("inf")
    for target in target_list:
        now_ans = 0
        now_word = word
        while len(set(now_word)) > 1:
            tmp = ""
            for i in range(len(now_word) - 1):
                if now_word[i] == target or now_word[i + 1] == target:
                    tmp += target
                else:
                    tmp += now_word[i]
            now_word = tmp
            now_ans += 1
        answer = min(answer, now_ans)
    print(answer)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    word = input()
    count = {}
    for w in word:
        if w in count:
            count[w] += 1
        else:
            count[w] = 1
    count = sorted(count.items(), key=lambda x: x[1])
    target_list = []
    if count[-1][1] == 1:
        target_list.append(word[len(word) // 2])
    else:
        for i in range(-1, -len(word) - 1, -1):
            if count[i][1] == count[-1][1]:
                target_list.append(count[i][0])
            else:
                break
    answer = float("inf")
    for target in target_list:
        now_ans = 0
        now_word = word
        while len(set(now_word)) > 1:
            tmp = ""
            for i in range(len(now_word) - 1):
                if now_word[i] == target or now_word[i + 1] == target:
                    tmp += target
                else:
                    tmp += now_word[i]
            now_word = tmp
            now_ans += 1
        answer = min(answer, now_ans)
    print(answer)


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

Fixed submission:
def main():
    people_num = int(input())
    information = sorted(list(map(int, input().split())))
    unique = len(set(information))
    answer = 0
    if unique * 2 == people_num + people_num % 2:
        if people_num > 1 and information[1] > 0:
            answer = 2 ** (unique - people_num % 2)
        elif people_num == 1 and information[0] == 0:
            answer = 1
    print(answer % (10 ** 9 + 7))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    people_num = int(input())
    information = sorted(list(map(int, input().split())))
    unique = len(set(information))
    answer = 0
    if information[1] > 0 and unique * 2 == people_num + people_num % 2:
        answer = (unique - people_num % 2) ** 2
    print(answer)


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

Fixed submission:
def main():
    target = input()
    string = ["eraser", "dreamer", "erase", "dream"]
    for i in range(len(target)):
        for s in string:
            if target[-len(s):] == s:
                target = target[:-len(s)]
        if target == "":
            break
    print("YES" if target == "" else "NO")


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    target = input()
    string = ["eraser", "dreamer", "erase", "dream"]
    for i in range(len(target)):
        for s in string:
            if target[i - len(s):] == s:
                target = target[:i - len(s)]
                break
        print(target)
    print("YES" if target == "" else "NO")


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

Fixed submission:
def main():
    word = list(input())
    operation = int(input())
    cost = {}
    for i in range(26):
        cost[chr(ord("a") + i)] = ord("z") - ord("a") - i + 1
    for i in range(len(word)):
        if cost[word[i]] <= operation and word[i] != "a":
            operation -= cost[word[i]]
            word[i] = "a"
        else:
            continue
    if 0 < operation:
        word[-1] = chr((ord(word[-1]) - ord("a") + operation % 26) % 26 + ord("a"))
    print("".join(word))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    word = list(input())
    operation = int(input())
    cost = {}
    for i in range(26):
        cost[chr(ord("a") + i)] = ord("z") - ord("a") - i + 1
    for i in range(len(word)):
        if cost[word[i]] <= operation:
            operation -= cost[word[i]]
            word[i] = "a"
        else:
            continue
    if 0 < operation:
        for i in range(-1, -len(word)-1, -1):
            word[i] = chr(ord(word[i]) + operation)
            operation = 0
            break
    print("".join(word))


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

Fixed submission:
s=input()

if s[1]=='B':
  print('ARC')
else:
  print('ABC')

Buggy submission (verdict: Runtime Error):
s=input()
if s[1]=='B':
  s[1]='R'
else:
  s[1]='B'
print(s)

Buggy submission (verdict: Runtime Error):
s=input()
if s[1]=='B':
  s[1]='R'
else:
  s[1]='B';
print(s)
Problem p03588 (python)

Fixed submission:
N = int(input())

maxi = -1
sc = 0

for i in range(N):
	A, B = map(int, input().split())
	if A > maxi:
		maxi = A
		sc = B
print(maxi + sc)

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

maxi = -1
sc = 0

for i in range(N):
	A, B = map(int, input().split())
	if A > mini:
		mini = A
		sc = B
print(mini + sc)
Problem p02609 (python)

Fixed submission:
n = int(input())
x = input()
ones = 0
for i in x:
    if i=='1':
        ones += 1
mods = [0, 0]
for i in range(n):
    if x[n-i-1]=='1':
        if ones>1:
            mods[0] += pow(2, i, ones-1)
        mods[1] += pow(2, i, ones+1)
if ones>1:
    mods[0] %= ones-1
mods[1] %= ones+1
def f(x):
    if x==0:
        return 1
    cnt = 1
    while x>0:
        p = bin(x).count('1')
        x %= p
        cnt += 1
    return cnt
for i in range(n-1, -1, -1):
    if x[n-i-1]=='1' and ones==1:
        print(0)
        continue
    if x[n-i-1]=='1':
        init = (mods[0] - pow(2, i, ones-1))%(ones-1)
    else:
        init = (mods[1] + pow(2, i, ones+1))%(ones+1)
    print(f(init))

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()
ones = 0
for i in x:
    if i=='1':
        ones += 1
mods = [0, 0]
for i in range(n):
    if x[n-i-1]=='1':
        if ones-1>0:
            mods[0] += pow(2, i, ones-1)
        mods[1] += pow(2, i, ones+1)
mods[0] %= ones-1
mods[1] %= ones+1
def f(x):
    if x==0:
        return 1
    cnt = 1
    while x>0:
        p = bin(x).count('1')
        x %= p
        cnt += 1
    return cnt
for i in range(n-1, -1, -1):
    if x[n-i-1]=='1':
        init = (mods[0] - pow(2, i, ones-1))%(ones-1)
    else:
        init = (mods[1] + pow(2, i, ones+1))%(ones+1)
    if x[n-i-1]=='1' and ones==1:
        print(0)
    else:
        print(f(init))

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()
ones = 0
for i in x:
    if i=='1':
        ones += 1
mods = [0, 0]
for i in range(n):
    if x[n-i-1]=='1':
        if ones>0:
            mods[0] += pow(2, i, ones-1)
        if ones<n:
            mods[1] += pow(2, i, ones+1)
mods[0] %= ones-1
mods[1] %= ones+1
def f(x):
    if x==0:
        return 1
    cnt = 1
    while x>0:
        p = bin(x).count('1')
        x %= p
        cnt += 1
    return cnt
for i in range(n-1, -1, -1):
    if x[n-i-1]=='1':
        init = (mods[0] - pow(2, i, ones-1))%(ones-1)
    else:
        init = (mods[1] + pow(2, i, ones+1))%(ones+1)
    if x[n-i-1]=='1' and ones==1:
        print(0)
    else:
        print(f(init))

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()
ones = 0
for i in x:
    if i=='1':
        ones += 1
mods = [0, 0]
for i in range(n):
    if x[n-i-1]=='1':
        mods[0] += pow(2, i, ones-1)
        mods[1] += pow(2, i, ones+1)
mods[0] %= ones-1
mods[1] %= ones+1
def f(x):
    if x==0:
        return 1
    cnt = 1
    while x>0:
        p = bin(x).count('1')
        x %= p
        cnt += 1
    return cnt
for i in range(n-1, -1, -1):
    if x[n-i-1]=='1':
        init = (mods[0] - pow(2, i, ones-1))%(ones-1)
    else:
        init = (mods[1] + pow(2, i, ones+1))%(ones+1)
    print(f(init))