Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):


def remove_data(data, ind_pre, ind_after):
    if ind_pre == 0:
        data_pre = ''
    else:
        data_pre = data[:ind_pre]
    if ind_after == len(data) - 1:
        data_after = ''
    else:
        data_after = data[ind_after + 1:]
    data_remove = data_pre + data_after
    return data_remove


def calc_data(data):
    flg = 1
    while flg:
        flg = 0
        for i in range(len(data) - 1):
            if data[i] != data[i + 1]:
                data = remove_data(data, i, i+1)
                flg = 1
                break
    return len(data)

def main():
    data = input()
    length = len(data)
    final_length = calc_data(data)
    print(length - final_length)


if __name__ == '__main__':
    main()

Fixed submission:

def calc_data(data):
    count = 0
    c_0, c_1 = 0, 0
    for i in range(len(data)):
        if data[i] == '0':
            if c_1 > 0:
                count += 2
                c_1 -= 1
            else:
                c_0 += 1
        if data[i] == '1':
            if c_0 > 0:
                count += 2
                c_0 -= 1
            else:
                c_1 += 1
    print(count)

def main():
    data = input()
    calc_data(data)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):

length = 0
ans = 0

def remove_data(data, ind_pre, ind_after):
    if ind_pre == 0:
        data_pre = ''
    else:
        data_pre = data[:ind_pre]
    if ind_after == len(data) - 1:
        data_after = ''
    else:
        data_after = data[ind_after + 1:]
    data_remove = data_pre + data_after
    return data_remove

def calc_ans(data):
    global length, ans
    ans_kari = length - len(data)
    if ans_kari > ans:
        ans = ans_kari


def calc_data(data):
    for i in range(len(data) - 1):
        if data[i] != data[i + 1]:
            data_remove = remove_data(data, i, i+1)
            calc_data(data_remove)
    calc_ans(data)

def main():
    global length, ans
    data = input()
    length = len(data)
    calc_data(data)
    print(ans)


if __name__ == '__main__':
    main()

Fixed submission:

def calc_data(data):
    count = 0
    c_0, c_1 = 0, 0
    for i in range(len(data)):
        if data[i] == '0':
            if c_1 > 0:
                count += 2
                c_1 -= 1
            else:
                c_0 += 1
        if data[i] == '1':
            if c_0 > 0:
                count += 2
                c_0 -= 1
            else:
                c_1 += 1
    print(count)

def main():
    data = input()
    calc_data(data)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import math

def process(number_list):
    left, point = number_list[0], number_list[-2]
    if left == 1:
        print(1)
        return 0
    yojo = number_list[-1] % left
    point -= yojo
    right = left * (math.ceil(point / left) - 1) + yojo
    if right == 0:
        number_list.pop(-1)
        if len(number_list) == 1:
            print(number_list[0])
            return 0
    else:
        number_list[-1] = right
        number_list.sort()
    return number_list

def main():
    num = int(input())
    number_list = list(map(int, input().split()))
    number_list.sort()
    while 1:
        number_list = process(number_list)
        if number_list == 0:
            break


if __name__ == '__main__':
    main()

Fixed submission:
import math

def process(number_list):
    left, point = number_list[0], number_list[-2]
    if left == 1:
        print(1)
        return 0
    right = number_list[-1] % left
    number_list.pop(-1)
    if right == 0:
        if len(number_list) == 1:
            print(number_list[0])
            return 0
    else:
        number_list.insert(0, right)
    return number_list

def main():
    num = int(input())
    number_list = list(map(int, input().split()))
    number_list.sort()
    while 1:
        number_list = process(number_list)
        if number_list == 0:
            break


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):

def get_match_list(num_list, num_num):
    match_num_list = set()
    match_dic = [2,5,5,4,5,6,3,7,6]
    for num in num_list:
        match_num_list.add(match_dic[num-1])
    match_num_list = list(match_num_list)
    match_num_list.sort()
    return match_num_list

def get_dp(use_match_list, match_nun):
    dp = [-1 for i in range(match_nun + 1)]
    dp[0] = 0
    for i in range(2, match_nun + 1):
        for macth_bar in use_match_list:
            if dp[i-macth_bar] >= 0:
                dp[i] = dp[i-macth_bar] + 1
                break
    return dp

def print_ans(dp, match_nun, num_list):
    match_dic = [2, 5, 5, 4, 5, 6, 3, 7, 6]
    max_ketasuu = dp[match_nun]
    ans = ''
    while match_nun > 0:
        for num in num_list:
            use_match_num = match_dic[num - 1]
            if dp[match_nun - use_match_num] == max_ketasuu - 1:
                ans += str(num)
                match_nun -= use_match_num
                max_ketasuu -= 1
                break
    print(ans)



def main():
    match_nun, num_num = map(int, input().split())
    num_list = list(map(int, input().split()))
    num_list.sort(reverse=True)
    use_match_list = get_match_list(num_list, num_num)
    dp = get_dp(use_match_list, match_nun)
    print_ans(dp, match_nun, num_list)


if __name__ == '__main__':
    main()

Fixed submission:

def get_match_list(num_list, num_num):
    match_num_list = set()
    match_dic = [2,5,5,4,5,6,3,7,6]
    for num in num_list:
        match_num_list.add(match_dic[num-1])
    match_num_list = list(match_num_list)
    match_num_list.sort()
    return match_num_list

def get_dp(use_match_list, match_nun):
    dp = [-1 for i in range(match_nun + 1)]
    dp[0] = 0
    for i in range(2, match_nun + 1):
        for macth_bar in use_match_list:
            if dp[i-macth_bar] >= 0:
                dp[i] = dp[i-macth_bar] + 1
                break
    return dp

def print_ans(dp, match_nun, num_list):
    match_dic = [2, 5, 5, 4, 5, 6, 3, 7, 6]
    max_ketasuu = dp[match_nun]
    ans = ''
    while match_nun > 0:
        for num in num_list:
            use_match_num = match_dic[num - 1]
            if match_nun - use_match_num < 0:
                continue
            if dp[match_nun - use_match_num] == max_ketasuu - 1:
                ans += str(num)
                match_nun -= use_match_num
                max_ketasuu -= 1
                break
    print(ans)



def main():
    match_nun, num_num = map(int, input().split())
    num_list = list(map(int, input().split()))
    num_list.sort(reverse=True)
    use_match_list = get_match_list(num_list, num_num)
    dp = get_dp(use_match_list, match_nun)
    print_ans(dp, match_nun, num_list)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
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():
    node_num, edge_num = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(node_num - 1 + edge_num)]

    parent_node = [0 for i in range(node_num + 1)]
    root_node = [1 for i in range(node_num + 1)]
    root_node[0] = 0
    graph_data = defaultdict(set)

    for i in range(node_num - 1 + edge_num):
        a, b = data[i]
        graph_data[a].add(b)
        root_node[b] = 0

    root = -1
    for i in range(node_num + 1):
        if root_node[i]:
            root = i

    now_set = set()
    next_set = set()
    now_set.add(root)

    while len(now_set):
        for now_node in now_set:
            for next_node in graph_data[now_node]:
                parent_node[next_node] = now_node
                next_set.add(next_node)
        now_set = next_set
        next_set = set()

    for i in range(1, node_num + 1):
        print(parent_node[i])


if __name__ == '__main__':
    main()


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():
    node_num, edge_num = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(node_num - 1 + edge_num)]

    parent_node = [0 for i in range(node_num + 1)]
    graph_data = defaultdict(set)
    nyuuji = [0 for i in range(node_num + 1)]

    for i in range(node_num - 1 + edge_num):
        a, b = data[i]
        graph_data[a].add(b)
        nyuuji[b] += 1

    root = -1
    for i in range(1, node_num + 1):
        if nyuuji[i] == 0:
            root = i

    now_set = set()
    next_set = set()
    now_set.add(root)

    while len(now_set):
        for now_node in now_set:
            for next_node in graph_data[now_node]:
                nyuuji[next_node] -= 1
                if nyuuji[next_node] == 0:
                    next_set.add(next_node)
                    parent_node[next_node] = now_node

        now_set = next_set
        next_set = set()

    for i in range(1, node_num + 1):
        print(parent_node[i])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
ans = 0

def calc_final_data(suhsi_data, eat_data, sushi_num):
    global ans
    ans_kari = 0
    neta_hist = set()
    for i in range(sushi_num):
        if eat_data[i]:
            neta_hist.add(str(suhsi_data[i][0]))
            ans_kari += suhsi_data[i][1]
    ans_kari += len(neta_hist) * len(neta_hist)
    if ans_kari > ans:
        ans = ans_kari

def eat_sushi(suhsi_data, max_eat, eat_data_kari, index, eat_flg, sushi_num):
    eat_data = eat_data_kari.copy()
    if index == sushi_num or eat_data.count(1) == max_eat:
        calc_final_data(suhsi_data, eat_data, sushi_num)
        return
    if eat_flg:
        eat_data[index] = 1
    eat_sushi(suhsi_data, max_eat, eat_data, index+1, 0, sushi_num)
    eat_sushi(suhsi_data, max_eat, eat_data, index+1, 1, sushi_num)


def calc_eat(suhsi_data, max_eat, eat_data, sushi_num):
    eat_sushi(suhsi_data, max_eat, eat_data, 0, 0, sushi_num)
    eat_sushi(suhsi_data, max_eat, eat_data, 0, 1, sushi_num)

def print_ans():
    global ans
    print(ans)

def main():
    sushi_num, max_eat = list(map(int, input().split()))
    suhsi_data = [list(map(int, input().split())) for i in range(sushi_num)]
    eat_data = [0 for i in range(sushi_num)]
    calc_eat(suhsi_data, max_eat, eat_data, sushi_num)
    print_ans()

if __name__ == '__main__':
    main()

Fixed submission:

import heapq


def main():
    num_sushi, chose_num = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num_sushi)]

    data.sort(key=lambda x: -x[1])
    delicious_heap = []
    count_d, count_n = 0, 0
    neta_data = [0 for i in range(num_sushi + 1)]

    for i in range(chose_num):
        neta, oishisa = data[i]

        if neta_data[neta]:
            heapq.heappush(delicious_heap, oishisa)
        else:
            neta_data[neta] = 1
            count_n += 1

        count_d += oishisa

    ans = count_d + count_n ** 2

    for i in range(chose_num, num_sushi):
        if len(delicious_heap) == 0:
            break
        neta, oishisa = data[i]

        if neta_data[neta]:
            continue
        neta_data[neta] = 1
        count_n += 1
        pop_oishisa = heapq.heappop(delicious_heap)
        count_d += oishisa - pop_oishisa

        ans = max(ans, count_d + count_n ** 2)

    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import numpy as np

def main():
    num, weigh = map(int, input().split())
    dp = np.zeros((num + 1, weigh + 1), dtype=int)

    for i in range(1, num + 1):
        now_weigh, now_value = map(int, input().split())
        dp[i, :now_weigh] = dp[i - 1, :now_weigh]
        dp[i, now_weigh:] = np.maximum(dp[i - 1, :weigh - now_weigh + 1] + now_value, dp[i - 1, now_weigh:])

    print(dp[-1][-1])


if __name__ == '__main__':
    main()



Fixed submission:
from collections import defaultdict

def main():
    num, weigh = map(int, input().split())
    dp = [defaultdict(int) for i in range(num + 1)]
    dp[0][0] = 0

    for i in range(1, num + 1):
        data = list(map(int, input().split()))
        for pre_value in dp[i - 1].keys():
            dp[i][pre_value] = max(dp[i - 1][pre_value], dp[i][pre_value])
            if pre_value + data[0] <= weigh:
                dp[i][pre_value + data[0]] = max(dp[i - 1][pre_value] + data[1], dp[i][pre_value + data[0]])

    print(max(list(dp[-1].values())))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):


if __name__ == '__main__':
    num = int(input())
    # data = [int(input()) for i in range(num)]
    
    ans = 0
    for i in range(num):
        data = input()
        if int(data[-1]) % 2 == 1:
            ans += 1

    if ans+1 % 2 == 0:
        print('second')
    else:
        print('first')

Fixed submission:
print(input().count('2'))

Buggy python 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, n):
        # print(pow(i, length),  n)
        # if pow(i, length) > n:
        #     break
        if i > n or n == 1:
            break
        print(n, i)
        # 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)

Fixed submission:
print(input().count('2'))

Buggy python submission (verdict: Runtime Error):

import collections

def prime_factor(n, length):
    ass = collections.defaultdict(int)
    # break_num = pow()
    for i in range(2,int(n**0.5)+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()))

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

Fixed submission:
print(input().count('2'))
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

number_str = '999999999'
number_int = int(number_str)

count = 0


length = len(number_str)



def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def calc_pre(leng_pre):
    global count
    count += pow(3, leng_pre) + 3 -  3 * pow(2, leng_pre)

def calc_all(length):
    global count
    l = ['3', '5', '7']
    pre_data = set()
    for v in itertools.combinations_with_replacement(l, length):
        # print(v)
        if'3' in v and '5' in v and '7' in v:
            for vv in itertools.permutations(list(v), length):
                aaa = int(''.join(list(vv)))
                if aaa < number_int:
                    if aaa not in pre_data:
                        # print(aaa)
                        count += 1
                        pre_data.add(aaa)
                else:
                    break

if length > 3:
    for i in range(3, length):
        calc_pre(i)

calc_all(length)

print(count)

# print(pow(2, 3))


Fixed submission:

ans = 0

def check(num_str):
    for i in ['7', '5', '3']:
        if i not in num_str:
            return 0
    return 1

def make_data(num, num_str):
    global ans
    if num < int(num_str):
        return
    if check(num_str):
        ans += 1

    make_data(num, num_str + '7')
    make_data(num, num_str + '5')
    make_data(num, num_str + '3')


def main():
    num = int(input())
    make_data(num, '0')

    global ans
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

number_str = '999999999'
number_int = int(number_str)

count = 0


length = len(number_str)



def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def calc_pre(leng_pre):
    global count
    count += pow(3, leng_pre) + 3 -  3 * pow(2, leng_pre)

def calc_all(length):
    global count
    l = ['3', '5', '7']
    pre_data = set()
    for v in itertools.combinations_with_replacement(l, length):
        # print(v)
        if'3' in v and '5' in v and '7' in v:
            for vv in itertools.permutations(list(v), length):
                aaa = int(''.join(list(vv)))
                if aaa < number_int:
                    if aaa not in pre_data:
                        # print(aaa)
                        count += 1
                        pre_data.add(aaa)
                else:
                    break

if length > 3:
    for i in range(3, length):
        calc_pre(i)

calc_all(length)

print(count)

# print(pow(2, 3))

Fixed submission:

ans = 0

def check(num_str):
    for i in ['7', '5', '3']:
        if i not in num_str:
            return 0
    return 1

def make_data(num, num_str):
    global ans
    if num < int(num_str):
        return
    if check(num_str):
        ans += 1

    make_data(num, num_str + '7')
    make_data(num, num_str + '5')
    make_data(num, num_str + '3')


def main():
    num = int(input())
    make_data(num, '0')

    global ans
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):


if __name__ == '__main__':
    ken_num, city_num = list(map(int, input().split()))
    data = []
    for i in range(city_num):
        element = list(map(int, input().split())).append(i)
        data.append(element)
    # data = [list(map(int, input().split())).append(i) for i in range(city_num)]

    # ken_num, city_num = 2, 3
    # data = [[1,32,0], [2,63,1],[1,12,2]]

    data = sorted(data, key=lambda x: (x[0], x[1]))

    count = 1
    ken_num = 1
    ans_data = {}

    for i in range(city_num):
        number = data[i][2]
        if data[i][0] != ken_num:
            count = 1
            ken_num = data[i][0]
        chr = "{0:06d}".format(ken_num) + "{0:06d}".format(count)
        ans_data.update({number:chr})
        count += 1

    for i in range(city_num):
        print(ans_data[i])

Fixed submission:
a, b = list(map(int, input().split()))
print(a+int(b/2))
Buggy python submission (verdict: Runtime Error):


if __name__ == '__main__':
    ken_num, city_num = list(map(int, input().split()))
    data = [list(map(int, input().split())).append(i) for i in range(city_num)]

    # ken_num, city_num = 2, 3
    # data = [[1,32,0], [2,63,1],[1,12,2]]

    data = sorted(data, key=lambda x: (x[0], x[1]))

    count = 1
    ken_num = 1
    ans_data = {}

    for i in range(city_num):
        number = data[i][2]
        if data[i][0] != ken_num:
            count = 1
            ken_num = data[i][0]
        chr = "{0:06d}".format(ken_num) + "{0:06d}".format(count)
        ans_data.update({number:chr})
        count += 1

    for i in range(city_num):
        print(ans_data[i])

Fixed submission:

if __name__ == '__main__':
    ken_num, city_num = list(map(int, input().split()))
    data = []
    for i in range(city_num):
        element = list(map(int, input().split()))
        element.append(i)
        data.append(element)

    data = sorted(data, key=lambda x: (x[0], x[1]))

    count = 1
    ken_num = 1
    ans_data = {}

    for i in range(city_num):
        number = data[i][2]
        if data[i][0] != ken_num:
            count = 1
            ken_num = data[i][0]
        chr = "{0:06d}".format(ken_num) + "{0:06d}".format(count)
        ans_data.update({number:chr})
        count += 1

    for i in range(city_num):
        print(ans_data[i])
Buggy python submission (verdict: Runtime Error):
num, time_lim = list(map(int, input().spli()))
ans = 'TLE'
for i in range(num):
  cost, time_data = list(map(int, input().spli()))
  if time_data > time_lim:
    continue
  if ans == 'TLE':
    ans = cost
  if ans > cost:
    ans = cost
print(ans)

Fixed submission:
num, time_lim = list(map(int, input().split()))
ans = 'TLE'
for i in range(num):
  cost, time_data = list(map(int, input().split()))
  if time_data > time_lim:
    continue
  if ans == 'TLE':
    ans = cost
  if ans > cost:
    ans = cost
print(ans)
Buggy python 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()

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()