Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

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

    dp = [defaultdict(int) for i in range(num)]
    dp[0][data[0] % person_num] += 1

    ans = 0
    for i in range(1, num):
        now_data = data[i]
        ans += dp[i - 1][0]
        for key in dp[i - 1].keys():
            now_ind = (key + now_data) % person_num
            dp[i][now_ind] += dp[i - 1][key]
        dp[i][now_data % person_num] += 1

    ans += dp[num - 1][0]

    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:

from collections import defaultdict


def main():
    num_box, num_people = map(int, input().split())
    data = list(map(int, input().split()))

    dp = defaultdict(int)
    dp[0] += 1
    count = 0
    for i in range(num_box):
        count += data[i]
        count %= num_people
        dp[count] += 1

    ans = 0
    for ele in dp.values():
        if ele >= 2:
            ans += (ele - 1) * ele // 2

    print(ans)





if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):

from collections import defaultdict

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

    dp = [defaultdict(int) for i in range(num)]
    dp[0][data[0] % person_num] += 1

    ans = 0
    for i in range(1, num):
        now_data = data[i]
        ans += dp[i - 1][0]
        for key in dp[i - 1].keys():
            now_ind = (key + now_data) % person_num
            dp[i][now_ind] += dp[i - 1][key]
        dp[i][now_data % person_num] += 1

    ans += dp[num - 1][0]

    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:

from collections import defaultdict


def main():
    num_box, num_people = map(int, input().split())
    data = list(map(int, input().split()))

    dp = defaultdict(int)
    dp[0] += 1
    count = 0
    for i in range(num_box):
        count += data[i]
        count %= num_people
        dp[count] += 1

    ans = 0
    for ele in dp.values():
        if ele >= 2:
            ans += (ele - 1) * ele // 2

    print(ans)





if __name__ == '__main__':
    main()
Buggy python 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()


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 python submission (verdict: Time Limit Exceeded):



def main():
    data = list(input())
    # dp = [[0 for i in range(4)] for i in range(len(data) + 1)]
    # dp[len(data)][3] += 1

    dp = [0, 0, 0, 1]

    dic = {0:'A', 1:'B', 2:'C'}
    for i in range(len(data))[::-1]:
        element = data[i]
        for j in range(4):
            if j == 3:
                if element == '?':
                    dp[j] *= 3
            else:
                if dic[j] == element:
                    dp[j] += dp[j + 1]

                elif element == '?':
                    dp[j] = dp[j] * 3 + dp[j + 1]


    mod = 10 ** 9 + 7
    print(dp[0] % mod)





if __name__ == '__main__':
    main()


Fixed submission:



def main():
    data = list(input())
    # dp = [[0 for i in range(4)] for i in range(len(data) + 1)]
    # dp[len(data)][3] += 1

    dp = [0, 0, 0, 1]
    mod = 10 ** 9 + 7

    dic = {0:'A', 1:'B', 2:'C'}
    for i in range(len(data))[::-1]:
        element = data[i]
        for j in range(4):
            if j == 3:
                if element == '?':
                    dp[j] *= 3
            else:
                if dic[j] == element:
                    dp[j] += dp[j + 1]

                elif element == '?':
                    dp[j] = dp[j] * 3 + dp[j + 1]

            dp[j] %= mod



    print(dp[0] % mod)





if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):



def main():
    data = list(input())
    dp = [[0 for i in range(4)] for i in range(len(data) + 1)]
    dp[len(data)][3] += 1

    dic = {0:'A', 1:'B', 2:'C'}
    for i in range(len(data))[::-1]:
        element = data[i]
        for j in range(4):
            if j == 3:
                if element == '?':
                    dp[i][j] = dp[i + 1][j] * 3
                else:
                    dp[i][j] = dp[i + 1][j]
            else:
                if dic[j] == element or element == '?':
                    dp[i][j] += dp[i + 1][j + 1]

                if element == '?':
                    dp[i][j] += dp[i + 1][j] * 3
                else:
                    dp[i][j] += dp[i + 1][j]

    mod = 10 ** 9 + 7
    print(dp[0][0] % mod)





if __name__ == '__main__':
    main()


Fixed submission:



def main():
    data = list(input())
    # dp = [[0 for i in range(4)] for i in range(len(data) + 1)]
    # dp[len(data)][3] += 1

    dp = [0, 0, 0, 1]
    mod = 10 ** 9 + 7

    dic = {0:'A', 1:'B', 2:'C'}
    for i in range(len(data))[::-1]:
        element = data[i]
        for j in range(4):
            if j == 3:
                if element == '?':
                    dp[j] *= 3
            else:
                if dic[j] == element:
                    dp[j] += dp[j + 1]

                elif element == '?':
                    dp[j] = dp[j] * 3 + dp[j + 1]

            dp[j] %= mod



    print(dp[0] % mod)





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

def get_num_f(data, sum_data):
    left1, left2 = 0, sum_data
    for i in range(len(data)- 1):
        if left1 + data[i] >= left2 - data[i]:
            pre_d = abs(left1 - left2)
            now_d = abs((left1 + data[i]) - (left2 - data[i]))
            if now_d < pre_d:
                left1 += data[i]
                left2 -= data[i]
            break
        left1 += data[i]
        left2 -= data[i]
    return left1, left2




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

    sum_left, sum_righ = sum(data[:2]), sum(data[2:])
    left1, left2 = get_num_f(data[:2], sum_left)
    righ1, righ2 = get_num_f(data[2:], sum_righ)

    ans = max(left1, left2, righ1, righ2) - min(left1, left2, righ1, righ2)

    for i in range(2, num - 2):
        sum_left += data[i]
        sum_righ -= data[i]
        left1, left2 = get_num_f(data[:i + 1], sum_left)
        righ1, righ2 = get_num_f(data[i + 1:], sum_righ)
        ans_kari = max(left1, left2, righ1, righ2) - min(left1, left2, righ1, righ2)

        if ans_kari < ans:
            ans = ans_kari

    print(ans)



if __name__ == '__main__':
    main()

Fixed submission:

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

    l, c, r = 1, 2, 3
    P = sum(data[:l])
    Q = sum(data[l:c])
    R = sum(data[c:r])
    S = sum(data[r:])

    ans = max(P, Q, R, S) - min(P, Q, R, S)

    while c <= num-2:
        while True:
            if abs(P-Q) < abs((P+data[l])-(Q-data[l])):
                break

            if l == c-1:
                break

            P += data[l]
            Q -= data[l]
            l += 1

        while True:
            if abs(R-S) < abs((R+data[r])-(S-data[r])):
                break
            if r == num-1:
                break

            R += data[r]
            S -= data[r]
            r += 1

        ans = min(max(P,Q,R,S)- min(P,Q,R,S), ans)

        # centerについて調整
        Q += data[c]
        R -= data[c]
        c += 1

    print(ans)

if __name__ == '__main__':
    main()
Buggy python 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()



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



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 python submission (verdict: Time Limit Exceeded):

import bisect


from functools import reduce
from operator import mul

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under




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

    ans = 0
    ans_list = []

    for i in range(num - 1, num):
        left_ind = max(bisect.bisect_left(data, data[i] // 2) - 1, 0)
        if left_ind + 1 >= i:
            right_ind = left_ind
        else:
            right_ind = left_ind + 1
        ans_kari = cmb(data[i], data[left_ind])
        if ans < ans_kari:
            ans = ans_kari
            ans_list = [data[i], data[left_ind]]
        ans_kari = cmb(data[i], data[right_ind])
        if ans < ans_kari:
            ans = ans_kari
            ans_list = [data[i], data[right_ind]]

    print(ans_list[0], ans_list[1])






if __name__ == '__main__':
    main()



Fixed submission:

import bisect





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

    ans = 0
    ans_list = []

    for i in range(num - 1, num):
        left_ind = max(bisect.bisect_left(data, data[i] // 2) - 1, 0)
        if left_ind + 1 >= i:
            right_ind = left_ind
        else:
            right_ind = left_ind + 1

        ans_kari_1 = min(data[left_ind], data[i] - data[left_ind])
        ans_kari_2 = min(data[right_ind], data[i] - data[right_ind])


        if ans_kari_1 > ans_kari_2:
            ans_list = [data[i], data[left_ind]]
        else:
            ans_list = [data[i], data[right_ind]]

    print(ans_list[0], ans_list[1])






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


def check(goal, dist_data, start):
    dp = [[0 for i in range(17000)] for i in range(len(dist_data) + 1)]
    dp[0][start + 8500] = 1

    for i in range(1, len(dist_data) + 1):
        for j in range(len(dp[i - 1])):
            if dp[i - 1][j]:
                dp[i][j + dist_data[i - 1]] = 1
                dp[i][j - dist_data[i - 1]] = 1

    return dp[len(dist_data)][goal + 8500]


def main():
    data = input()
    goal = list(map(int, input().split()))
    data = data.split('T')
    move_dist = [len(ele) for ele in data]

    x_data = move_dist[2::2]
    y_data = move_dist[1::2]

    if check(goal[0], x_data, move_dist[0]) and check(goal[1], y_data, 0):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Fixed submission:


def check(goal, dist_data, start):
    dp_now = [0 for i in range(17000)]
    dp_now[start + 8500] = 1
    dp_next = [0 for i in range(17000)]

    for i in range(len(dist_data)):
        for j in range(len(dp_now)):
            if dp_now[j]:
                dp_next[j + dist_data[i]] = 1
                dp_next[j - dist_data[i]] = 1
        dp_now = dp_next
        dp_next = [0 for i in range(17000)]

    return dp_now[goal + 8500]


def main():
    data = input()
    goal = list(map(int, input().split()))
    data = data.split('T')
    move_dist = [len(ele) for ele in data]

    x_data = move_dist[2::2]
    y_data = move_dist[1::2]

    if check(goal[0], x_data, move_dist[0]) and check(goal[1], y_data, 0):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()
Buggy python 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()



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


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

Fixed submission:
import math


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





if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import itertools

def main():
    node_num, edge_num, visit_num = map(int, input().split())
    visit_place = list(map(int, input().split()))
    data = [list(map(int, input().split())) for i in range(edge_num)]

    hashi_set = defaultdict(set)
    kyori_data = [defaultdict(int) for i in range(node_num + 1)]
    for i in range(edge_num):
        a, b, c = data[i]
        hashi_set[a].add(b)
        hashi_set[b].add(a)
        kyori_data[a][b] = c
        kyori_data[b][a] = c

    saitan_data = [[-1 for i in range(node_num + 1)] for j in range(node_num + 1)]


    for i in range(1, node_num + 1):
        saitan_data[i][i] = 0
        done_data = set()
        done_data.add(i)
        for j in range(1, i):
            saitan_data[i][j] = saitan_data[j][i]
            done_data.add(j)

        while len(done_data) < node_num:
            node_add = -1
            kyori_add = 10 ** 10
            for now_ele in done_data:
                for next_ele in hashi_set[now_ele]:
                    if saitan_data[i][next_ele] != -1:
                        continue
                    kyori = saitan_data[i][now_ele] + kyori_data[now_ele][next_ele]
                    if kyori < kyori_add:
                        kyori_add = kyori
                        node_add = next_ele
            done_data.add(node_add)
            saitan_data[i][node_add] = kyori_add

    # for i in range(node_num + 1):
    #     print(saitan_data[i])

    ans = 10 ** 10
    for ikikata in list(itertools.permutations(visit_place, visit_num)):
        kari = 0
        for i in range(visit_num - 1):
            kari += saitan_data[ikikata[i]][ikikata[i + 1]]
        if kari < ans:
            ans = kari
    print(ans)





if __name__ == '__main__':
    main()

Fixed submission:
from collections import defaultdict
import itertools

def main():
    node_num, edge_num, visit_num = map(int, input().split())
    visit_place = list(map(int, input().split()))
    data = [list(map(int, input().split())) for i in range(edge_num)]

    hashi_set = defaultdict(set)
    kyori_data = [defaultdict(int) for i in range(node_num + 1)]

    saitan_data = [[10 ** 10 for i in range(node_num + 1)] for j in range(node_num + 1)]

    for i in range(edge_num):
        a, b, c = data[i]
        hashi_set[a].add(b)
        hashi_set[b].add(a)
        kyori_data[a][b] = c
        kyori_data[b][a] = c
        saitan_data[a][b] = c
        saitan_data[b][a] = c


    for k in range(1, node_num + 1):
        for i in range(1, node_num + 1):
            for j in range(1, node_num + 1):
                if i == j:
                    saitan_data[i][j] = 0
                    continue
                saitan_data[i][j] = min(saitan_data[i][j], saitan_data[i][k] + saitan_data[k][j])

    ans = 10 ** 10
    for ikikata in list(itertools.permutations(visit_place, visit_num)):
        kari = 0
        for i in range(visit_num - 1):
            kari += saitan_data[ikikata[i]][ikikata[i + 1]]
        if kari < ans:
            ans = kari
    print(ans)





if __name__ == '__main__':
    main()
Buggy python 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()




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