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

Fixed submission:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)


def kouyakusuu(kyori, num):
    ans = kyori[0]
    pre = kyori[0]
    for i in range(num - 1):
        now_point = kyori[i + 1]
        while now_point:
            pre, now_point = now_point, pre % now_point
        if pre < ans:
            ans = pre
        pre = kyori[i + 1]
    return ans


def main():
    num, start = map(int, input().split())
    data = list(map(int, input().split()))
    kyori = [0 for i in range(num)]

    for i in range(num):
        kyori[i] = abs(data[i] - start)

    ans = kouyakusuu(kyori, num)

    print(ans)





if __name__ == '__main__':
    main()

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

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)


def main():
    num, start = map(int, input().split())
    data = list(map(int, input().split()))
    kyori = [0 for i in range(num)]

    for i in range(num):
        kyori[i] = abs(data[i] - start)

    ans = gcd(*kyori)

    print(ans)





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

Fixed submission:
import math


def main():

    num, goal = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num)]

    ans = 10 ** 10

    for i in range(2 ** num):
        toku_flg = list(map(int, list(bin(i)[2:])))
        toku_flg = [0 for i in range(num - len(toku_flg))] + toku_flg

        now_score = 0
        now_mondai = 0
        for i in range(num):
            if toku_flg[i] == 1:
                now_score += (i + 1) * 100 * data[i][0] + data[i][1]
                now_mondai += data[i][0]

        if now_score < goal:
            for i in range(num)[::-1]:
                if toku_flg[i] == 0:
                    if now_score + (i + 1) * 100 * (data[i][0] - 1) < goal:
                        break
                    nokori = goal - now_score
                    add_num = math.ceil(nokori / ((i + 1) * 100))
                    now_score += (i + 1) * 100 * add_num
                    now_mondai += add_num
                    break

        if now_score >= goal:
            if now_mondai < ans:
                ans = now_mondai

    print(ans)





if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

import math

def main():
    num, goal = map(int, input().split())
    data = [0] + [list(map(int, input().split())) for i in range(num)]

    ans_num = 1000

    for i in range(num ** 2):
        bin_str = bin(i)
        bin_list = list(bin_str[2:])
        bin_list = ['0' for i in range(num - len(bin_list))] + bin_list
        bin_list.reverse()

        sum_value = 0
        now_num = 0

        for j in range(len(bin_list)):
            if bin_list[j] == '1':
                sum_value += data[j+1][0] * (j + 1) * 100 + data[j+1][1]
                now_num += data[j+1][0]

        if sum_value < goal:
            for j in range(len(bin_list))[::-1]:
                if bin_list[j] == '1':
                    continue
                honsuu = math.ceil((goal - sum_value) / ((j + 1) * 100))
                sum_value += min(honsuu, data[j+1][0] - 1) * (j + 1) * 100
                now_num += min(honsuu, data[j+1][0] - 1)
                break

        if sum_value >= goal:
            if now_num < ans_num:
                ans_num = now_num

    print(ans_num)





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

Fixed submission:

def main():
    num = int(input())
    data = list(map(int, input().split()))
    data_kari = data.copy()
    data_kari.sort()
    # print(data_kari)
    min_chuou = data_kari[(num // 2) - 1]
    max_chuou = data_kari[num // 2]

    # print(min_chuou, max_chuou)

    # print(data)

    for i in range(num):
        if data[i] <= min_chuou:
            print(max_chuou)
        elif data[i] >= max_chuou:
            print(min_chuou)






if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):


def main():
    num = int(input())
    data = list(map(int, input().split()))
    data_kari = data.copy()
    data_kari.sort()
    # print(data_kari)
    min_chuou = data_kari[(num // 2) - 1]
    max_chuou = data_kari[num // 2]

    # print(min_chuou, max_chuou)

    # print(data)

    for i in range(num):
        if data[i] <= min_chuou:
            print(max_chuou)
        elif data[i] >= max_chuou:
            print(min_chuou)






if __name__ == '__main__':
    main()

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


def kari():
    map(int, input().split())
    list(map(int, input().split()))
    math.ceil()

def main():
    num = int(input())
    data = list(map(int, input().split()))
    data_kari = data.copy()
    data_kari.sort()
    # print(data_kari)
    min_chuou = data_kari[(num // 2) - 1]
    max_chuou = data_kari[num // 2]

    # print(min_chuou, max_chuou)

    # print(data)

    for i in range(num):
        if data[i] <= min_chuou:
            print(max_chuou)
        elif data[i] >= max_chuou:
            print(min_chuou)






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

Fixed submission:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque


def main():
    s = input()

    aa = ['AKIHABARA', 'AKIHABAR', 'AKIHABRA', 'AKIHABR', 'AKIHBARA', 'AKIHBAR', 'AKIHBRA', 'AKIHBR']
    bb = ['KIHABARA', 'KIHABAR', 'KIHABRA', 'KIHABR', 'KIHBARA', 'KIHBAR', 'KIHBRA', 'KIHBR']

    if s in aa or s in bb:
        print('YES')
    else:
        print('NO')





if __name__ == '__main__':
    main()
    # test()

Buggy submission (verdict: Runtime Error):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque


def main():
    s = list(input())
    t = list('AKIHABARA')

    ind = 0
    for i in range(len(s)):
        if s[i] != t[ind]:
            while s[i] != t[ind]:
                if ind >= len(t) - 1:
                    break
                ind += 1
            if s[i] != t[ind]:
                print('NO')
                sys.exit()
        ind += 1
    print('YES')






if __name__ == '__main__':
    main()
    # test()
Problem p03555 (python)

Fixed submission:


def main():
    a = [list(input()) for i in range(2)]
    b = [a[1][::-1], a[0][::-1]]

    # print(a, b)

    if a == b:
        print('YES')
    else:
        print('NO')



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

def main():
    num = int(input())
    data_a = list(map(int, input().split()))
    data_a.sort()
    data_b = list(map(int, input().split()))
    data_b.sort()
    data_c = list(map(int, input().split()))
    data_c.sort()

    shita_b = [0 for i in range(num)]

    ind = 0
    for i in range(num):
        now_b = data_b[i]
        while data_c[ind] <= now_b:
            ind += 1
            if ind >= num:
                ind = num
                break
        if ind == num:
            break
        shita_b[i] = num - ind


    ans = 0
    tasu_now = sum(shita_b)
    ind = 0
    for i in range(num):
        now_a = data_a[i]
        while now_a >= data_b[ind]:
            tasu_now -= shita_b[ind]
            ind += 1
            if ind >= num:
                ind = num
                break
        if ind == num:
            break
        ans += tasu_now

    print(ans)



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

Fixed submission:
import math


def main():
    a = int(input())
    b = int(input())
    print(a ** 2 - b)





if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

import collections

def get_lim(n):
    # for i in range(n):
    #     if i * i > n:
    #         return i + 1
    return pow(10, int((len(str(n)) / 2)))

def prime_factor(n, length):
    ass = collections.defaultdict(int)
    # break_num = pow()
    # for i in range(2,int(n**0.5)+1):
    lim = get_lim(n)
    for i in range(2, lim + 1):
        # print(pow(i, length),  n)
        # if pow(i, length) > n:
        #     break
        if i > n or n == 1:
            break
        # i = pow(i, num)
        while n % i==0:
            ass[i] += 1
            n = n//i

    if n != 1:
        ass[n] += 1
    return ass

if __name__ == '__main__':
    length, num = list(map(int, input().split()))

    if length == 1:
        print(num)
    else:

        soinnsuu = prime_factor(num, length)
        ans = 1
        # print(soinnsuu)
        for data in soinnsuu.keys():
            if soinnsuu[data] >= length:
               ans *= data
        print(ans)
Problem p03625 (python)

Fixed submission:
from collections import Counter

def main():
    num = int(input())
    data = Counter(list(map(int, input().split())))
    score_sorted = sorted(data.items(), key=lambda x: -x[0])

    ans = []
    for ele, kosuu in score_sorted:
        if kosuu >= 2:
            if len(ans) == 0 and kosuu >= 4:
                ans = [ele, ele]
                break
            else:
                ans.append(ele)
                if len(ans) == 2:
                    break
    if len(ans) == 2:
        print(ans[0] * ans[1])
    else:
        print(0)



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

from collections import Counter

def main():
    num = int(input())
    data = Counter(list(map(int, input().split())))
    score_sorted = sorted(data.items(), key=lambda x: -x[0])

    ans = []
    for ele, kosuu in score_sorted:
        if kosuu >= 2:
            if len(ans) == 0 and kosuu >= 4:
                ans = [ele, ele]
                break
            else:
                ans.append(ele)
                if len(ans) == 2:
                    break
    print(ans[0] * ans[1])



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

Fixed submission:
from collections import defaultdict

import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline

parent_node = []

def get_parent(ind):
    global parent_node
    if ind != parent_node[ind]:
        parent_node[ind] = get_parent(parent_node[ind])
    return parent_node[ind]



def main():
    num = int(input())

    data = defaultdict(tuple)

    for i in range(num):
        x, y = map(int, input().split())
        data[i] = (x, y)

    data_sort = sorted(data.items(), key=lambda x: x[1][0])
    data_x = [ele for ele, ele2 in data_sort]
    data_sort = sorted(data.items(), key=lambda x: x[1][1])
    data_y = [ele for ele, ele2 in data_sort]

    cost_data = [0 for i in range((num - 1) * 2)]
    for i in range(len(data_x) - 1):
        a, b = data_x[i], data_x[i + 1]
        cost = abs(data[a][0] - data[b][0])
        cost_data[i] = a, b, cost
    for i in range(len(data_y) - 1):
        a, b = data_y[i], data_y[i + 1]
        cost = abs(data[a][1] - data[b][1])
        cost_data[i + len(data_x) - 1] = a, b, cost

    cost_data.sort(key=lambda x: x[2])
    global parent_node
    parent_node = [i for i in range(num)]

    ans = 0
    for i in range(len(cost_data)):
        a, b, cost = cost_data[i]
        a_parent = get_parent(a)
        b_parent = get_parent(b)
        if a_parent != b_parent:
            ans += cost
            parent_node[min(a_parent, b_parent)] = max(a_parent, b_parent)

    print(ans)





if __name__ == '__main__':
    main()

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

import sys
input = sys.stdin.readline

parent_node = []

def get_parent(ind):
    global parent_node
    if ind != parent_node[ind]:
        parent_node[ind] = get_parent(parent_node[ind])
    return parent_node[ind]



def main():
    num = int(input())

    data = defaultdict(tuple)

    for i in range(num):
        x, y = map(int, input().split())
        data[i] = (x, y)

    data_sort = sorted(data.items(), key=lambda x: x[1][0])
    data_x = [ele for ele, ele2 in data_sort]
    data_sort = sorted(data.items(), key=lambda x: x[1][1])
    data_y = [ele for ele, ele2 in data_sort]

    cost_data = [0 for i in range((num - 1) * 2)]
    for i in range(len(data_x) - 1):
        a, b = data_x[i], data_x[i + 1]
        cost = abs(data[a][0] - data[b][0])
        cost_data[i] = a, b, cost
    for i in range(len(data_y) - 1):
        a, b = data_y[i], data_y[i + 1]
        cost = abs(data[a][1] - data[b][1])
        cost_data[i + len(data_x) - 1] = a, b, cost

    cost_data.sort(key=lambda x: x[2])
    global parent_node
    parent_node = [i for i in range(num)]

    ans = 0
    for i in range(len(cost_data)):
        a, b, cost = cost_data[i]
        a_parent = get_parent(a)
        b_parent = get_parent(b)
        if a_parent != b_parent:
            ans += cost
            parent_node[min(a_parent, b_parent)] = max(a_parent, b_parent)

    print(ans)





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

Fixed submission:
from collections import defaultdict, Counter

def main():
    num = int(input())
    hajime = list(input())

    ans = Counter(hajime)

    for i in range(num - 1):
        aaa = Counter(list(input()))
        ans_kari = defaultdict(int)
        for ele in ans.keys():
            if ele in aaa.keys():
                ans_kari[ele] = min(ans[ele], aaa[ele])
        ans = ans_kari

    for i in range(26):
        for j in range(ans[chr(97 + i)]):
            print(chr(97 + i), end='')

    print()



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

from collections import defaultdict, Counter

def main():
    num = int(input())
    ans_dic = Counter(list(input()))
    for i in range(num - 1):
        aaa = Counter(list(input()))
        ans = defaultdict(int)
        for ele in ans_dic.keys():
            if ele in aaa.keys():
                ans[ele] += min(ans_dic[ele], aaa[ele])

    ans = sorted(ans.items(), key=lambda x: -x[1])

    for moji, kosuu in ans:
        for i in range(kosuu):
            print(moji, end='')

    print()



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

Fixed submission:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial



def main():
    if input() in ['a', 'e', 'i', 'o', 'u']:
        print('vowel')
    else:
        print('consonant')






if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial



def union_r(node):
    global road_union
    if road_union[node] != node:
        road_union[node] = union_r(road_union[node])
    return road_union[node]

def union_t(node):
    global train_union
    if train_union[node] != node:
        train_union[node] = union_t(train_union[node])
    return train_union[node]


road_union, train_union = [], []


def main():
    node_num, road_num, train_num = map(int, input().split())

    global road_union
    road_union = [i for i in range(node_num + 1)]
    for i in range(road_num):
        a, b = map(int, input().split())
        parent_a = union_r(a)
        parent_b = union_r(b)
        road_union[min(parent_a, parent_b)] = max(parent_a, parent_b)
        # print(road_union)

    global train_union
    train_union = [i for i in range(node_num + 1)]
    for i in range(train_num):
        a, b = map(int, input().split())
        parent_a = union_t(a)
        parent_b = union_t(b)
        train_union[min(parent_a, parent_b)] = max(parent_a, parent_b)

    # print(train_union, road_union)

    ryouhou = [0 for i in range(node_num + 1)]
    for i in range(1, node_num + 1):
        parent_r = union_r(i)
        parent_t = union_t(i)
        ryouhou[i] = (parent_r, parent_t)

    # print(train_union, road_union, 'uuu')

    count_d = Counter(ryouhou)

    for i in range(1, node_num + 1):
        now_flg = ryouhou[i]
        print(count_d[now_flg], end=' ')
    print()





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

Fixed submission:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




def main():
    s = list(input())
    num = int(input())

    for i in range(len(s)):
        now_ind = ord(s[i])
        if now_ind == 97:
            continue
        if now_ind + num > 122:
            num -= 123 - now_ind
            s[i] = 'a'

    last_ind = ord(s[-1]) - 97
    last_ind = (last_ind + num) % 26 + 97
    s[-1] = chr(last_ind)

    print(''.join(s))



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




def main():
    s = list(input())
    num = int(input())

    for i in range(len(s)):
        now_ind = ord(s[i])
        if now_ind + num > 122:
            num -= 123 - now_ind
            s[i] = 'a'

    last_ind = ord(s[-1])
    if last_ind + num <= 122:
        last_ind += num
    else:
        last_ind = last_ind + num - 27
    s[-1] = chr(last_ind)

    print(''.join(s))



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

Fixed submission:
from  collections import Counter

def main():
    num, avg = map(int, input().split())
    data = list(map(int, input().split()))

    dp = [[[0 for i in range(6000)] for j in range(num + 1)] for k in range(num + 1)]
    dp[0][0][0] = 1

    for i in range(1, num + 1):
        now_card = data[i - 1]
        for j in range(num + 1):
            for k in range(6000):
                # print(i, j, k)
                dp[i][j][k] += dp[i - 1][j][k]
                if k - now_card >= 0 and j - 1 >= 0:
                    dp[i][j][k] += dp[i - 1][j - 1][k - now_card]
        # print(dp[i][j])

    ans = 0
    for i in range(1, num + 1):
        ans += dp[num][i][i * avg]
    print(ans)





if __name__ == '__main__':
    main()

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

def main():
    num, avg = map(int, input().split())
    data = list(map(int, input().split()))

    dp = [[[0 for i in range(max(num, avg) * max(data) + 1)] for j in range(num + 1)] for k in range(num + 1)]
    dp[0][0][0] = 1

    for i in range(1, num + 1):
        now_card = data[i - 1]
        for j in range(num + 1):
            for k in range(max(num, avg) * max(data) + 1):
                # print(i, j, k)
                dp[i][j][k] += dp[i - 1][j][k]
                if k - now_card >= 0 and j - 1 >= 0:
                    dp[i][j][k] += dp[i - 1][j - 1][k - now_card]
        # print(dp[i][j])

    ans = 0
    for i in range(1, num + 1):
        ans += dp[num][i][i * avg]
    print(ans)





if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

from  collections import Counter

def main():
    num, avg = map(int, input().split())
    data = list(map(int, input().split()))

    dp = [[[0 for i in range(num * max(data) + 1)] for j in range(num + 1)] for k in range(num + 1)]
    dp[0][0][0] = 1

    for i in range(1, num + 1):
        now_card = data[i - 1]
        for j in range(num + 1):
            for k in range(num * max(data) + 1):
                # print(i, j, k)
                dp[i][j][k] += dp[i - 1][j][k]
                if k - now_card >= 0 and j - 1 >= 0:
                    dp[i][j][k] += dp[i - 1][j - 1][k - now_card]
        # print(dp[i][j])

    ans = 0
    for i in range(1, num + 1):
        ans += dp[num][i][i * avg]
    print(ans)





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

Fixed submission:

import sys


def check(num, s, b):
    sum_keta = 0
    while num > 0:
        sum_keta += num % b
        num //= b
    if sum_keta == s:
        return 1
    else:
        return 0


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

    if num < s:
        print(-1)
        sys.exit()

    if num == s:
        print(num + 1)
        sys.exit()

    if num == 1:
        print(-1)
        sys.exit()

    for b in range(2, int(num ** 0.5) + 2):
        if check(num, s, b):
            print(b)
            sys.exit()

    for p in range(1, int(num ** 0.5) + 2)[::-1]:
        b = (num - s) // p + 1
        if b <= 1:
            continue
        if check(num, s, b):
            print(b)
            sys.exit()

    print(-1)






if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

import sys


def check(num, s, b):
    sum_keta = 0
    while num > 0:
        sum_keta += num % b
        num //= b
    if sum_keta == s:
        return 1
    else:
        return 0


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

    if num == s:
        print(num + 1)
        sys.exit()

    for b in range(2, int(num ** 0.5) + 2):
        if check(num, s, b):
            print(b)
            sys.exit()

    for p in range(1, int(num ** 0.5) + 2):
        b = (num - s) // p + 1
        if check(num, s, b):
            print(b)
            sys.exit()

    print(-1)






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

Fixed submission:
S = input()
T = input()
if(T[0:len(T)-1] == S):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N = input()
if (N[-1] == str(3)):
    print('bon')
elif(int(N[-1]) == 0 or int(N[-1]) == 1 or int(N[-1]) == 6 or int(N[-1]) == 8 ):
    print('pon')
else:
    print('hon')
Problem p02641 (python)

Fixed submission:
import bisect

X, N = map(int, input().split())
P = set(map(int, input().split()))

A = {i for i in range(102)}

S = list(A - P)

T = bisect.bisect_left(S, X)

if T == 0:
    print(S[0])
elif X - S[T-1] > S[T] - X:
    print(S[T])
else:
    print(S[T-1])

Buggy submission (verdict: Runtime Error):
import bisect

X, N = map(int, input().split())
P = set(map(int, input().split()))

A = {i for i in range(1,101)}

S = list(A - P)

T = bisect.bisect_left(S, X)

if T == 0:
    print(S[0])
elif X - S[T-1] > S[T] - X:
    print(S[T])
else:
    print(S[T-1])
Problem p02573 (python)

Fixed submission:
class UnionFind():
    def __init__(self, N):
        self.N = N
        self.par = [n for n in range(N)]
        self.rank = [1] * N
        
    def find(self, u):
        if self.par[u] == u:
            return u
        else:
            return self.find(self.par[u])
    
    def union(self, u, v):

        pu = self.find(u)
        pv = self.find(v)

        if pu == pv: 
            return

        if self.rank[pu] < self.rank[pv]:
            self.par[pu] = pv
            self.rank[pv] += self.rank[pu]

        else: # self.rank[pu] > self.rank[pv]
            self.par[pv] = pu
            self.rank[pu] += self.rank[pv]
 
N, M = map(int, input().split())
UF = UnionFind(N)
for _ in range(M):
    A, B = map(int, input().split())
    A, B = A-1, B-1
    UF.union(A, B)


ret = 0

for n in range(N):
    ret = max(ret, UF.rank[n])

print(ret)

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

N, M = map(int, input().split())
F = defaultdict(list)

max_size = 0


for _ in range(M):

    A, B = map(int, input().split())

    if B not in F[A]:
        F[A].append(B)
    if A not in F[B]:
        F[B].append(A)

def dfs(i):
    vis.append(i)
    size = 0
    for j in F[i]:
        if j not in vis:
            size += dfs(j)
    return size + 1


vis = list()

ret = 0

for i in range(N):
    if i+1 not in vis:
        size = dfs(i+1)
        if size > ret:
            ret = size

print('{}'.format(ret))