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

Fixed submission:
from fractions import gcd

A, B, K = list(map(int, input().split(" ")))

d = gcd(A, B)

def divisor(n):
    #for i in range(1,int(n**0.5)+1):
    ass = [i for i in range(1, n+1) if n % i == 0]
    return ass

ass = divisor(d)
#print(ass)
out = ass[-K]
print(out)

Buggy submission (verdict: Runtime Error):
import math

A, B, K = list(map(int, input().split(" ")))

d = math.gcd(A, B)

def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            ass.append(n//i)
    return ass

ass = list(set(divisor(d)))
#print(ass)
out = ass[-K]
print(out)
Problem p03145 (python)

Fixed submission:
inputs=  sorted(list(map(int, input().split(" "))))

out = inputs[0] * inputs[1] // 2

print(out)

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())
h_list = list(map(int, input().split(" ")))

h_dict = {}
for elm_i, elm in enumerate(h_list):
    try:
        h_dict[elm].append(elm_i)
    except:
        h_dict[elm] = [elm_i]

h_list = np.asarray(h_list)


def calc(group, past_out, group_start):
    out = 0
    while True:
        #print("group", group)
        min_val = min(group)
        group -= min_val
        out += min_val
        #zero_list = np.where(group == 0)[0]
        #print("outs", past_out, out, group)
        #print("zero0", zero_list)
        zero_list = h_dict[past_out + out]
        #print("zero_all", zero_list, group_start)
        zero_list = [elm_i - group_start for elm_i in zero_list if elm_i >= group_start and elm_i < group_start + len(group)]
        #print("zero", zero_list)

        cond1 = group.shape[0] - 1 in zero_list
        cond2 = 0 in zero_list

        if group.shape[0] == 1:
            #assert group[0] == 0
            break
        else:
            if cond1: 
                zero_list = zero_list[:-1]
                group = group[:-1]
            if cond2:
                group_start += 1
                zero_list = zero_list[1:]
                group = group[1:]

            if not cond1 and not cond2:
                break

            if group.shape[0] == 0:
                break


    if group.shape[0] <= 1:
        pass
    else:
        start_i = -1
        past_out = out
        for end_i in zero_list:
            child_group = group[start_i+1: end_i]
            #print("child_group", child_group)
            out += calc(child_group, past_out, group_start+start_i+1)
            start_i = end_i

        child_group = group[start_i+1:]
        if child_group.shape[0] >= 1:
            #print("child_group", child_group)
            out += calc(child_group, past_out, group_start+start_i+1)

    return out

out = calc(h_list, 0, 0)
print(out)
Problem p03149 (python)

Fixed submission:
inp = sorted(list(map(int, input().split(" "))))

s = [1, 4, 7, 9]

if inp == s:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
import numpy as np

N, M = list(map(int, input().split(" ")))
A_list = np.sort(np.asarray(list(map(int, input().split(" ")))))[::-1]
B_list = np.sort(np.asarray(list(map(int, input().split(" ")))))[::-1]

out = 1
a_next_i = 0
b_next_i = 0
for x in range(N*M, 1, -1):
    cond1 = a_next_i < N and x == A_list[a_next_i]
    cond2 = b_next_i < M and x == B_list[b_next_i]
    if cond1 and cond2:
        kosuu = 1
        a_next_i += 1
        b_next_i += 1
    elif cond1:
        kosuu = b_next_i
        a_next_i += 1
    elif cond2:
        kosuu = a_next_i
        b_next_i += 1
    else:
        kosuu = a_next_i * b_next_i - (N * M - x)
    out *= kosuu
    out = out % 1000000007
   
print(out)
Problem p03152 (python)

Fixed submission:
import numpy as np

N, M = list(map(int, input().split(" ")))
A_list = np.sort(np.asarray(list(map(int, input().split(" ")))))[::-1]
B_list = np.sort(np.asarray(list(map(int, input().split(" ")))))[::-1]

out = 1
a_next_i = 0
b_next_i = 0
for x in range(N*M, 1, -1):
    #if x in A_list and x in B_list:
    if a_next_i < N and x == A_list[a_next_i] and b_next_i < M and x == B_list[b_next_i]:
        kosuu = 1
        a_next_i += 1
        b_next_i += 1
    #elif x in A_list:
    elif a_next_i < N and x == A_list[a_next_i]:
        #kosuu = np.sum(B_list >= x)
        kosuu = b_next_i
        a_next_i += 1
    #elif x in B_list:
    elif b_next_i < M and x == B_list[b_next_i]:
        #kosuu = np.sum(A_list >= x)
        kosuu = a_next_i
        b_next_i += 1
    else:
        #kosuu = np.sum(A_list >= x) * np.sum(B_list >= x) - (N * M - x)
        kosuu = a_next_i * b_next_i - (N * M - x)
    out *= kosuu
    out = out % 1000000007
   
print(out)

#print(A_list)
#print(B_list)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, M = list(map(int, input().split(" ")))
A_list = np.sort(np.asarray(list(map(int, input().split(" ")))))[::-1]
B_list = np.sort(np.asarray(list(map(int, input().split(" ")))))[::-1]

out = 1
a_next_i = 0
b_next_i = 0
for x in range(N*M, 1, -1):
    cond1 = a_next_i < N and x == A_list[a_next_i]
    cond2 = b_next_i < M and x == B_list[b_next_i]
    if cond1 and cond2:
        kosuu = 1
        a_next_i += 1
        b_next_i += 1
    elif cond1:
        kosuu = b_next_i
        a_next_i += 1
    elif cond2:
        kosuu = a_next_i
        b_next_i += 1
    else:
        kosuu = a_next_i * b_next_i - (N * M - x)
    out *= kosuu
    out = out % 1000000007
   
print(out)
Problem p03155 (python)

Fixed submission:
N, H, W = [int(input()) for i in range(3)]

print((N - H + 1) * (N - W + 1))

Buggy submission (verdict: Runtime Error):
N, Q = list(map(int, input().split(" ")))
A_list = list(map(int, input().split(" ")))

def game(A_list, X, N):
    aoki_A_list = sorted(A_list, key=lambda val: abs(val-X))

    count = 0
    aoki_last_plus = None 
    aoki_minus_plus = None
    aoki_last_minus = None
    while True:
        taka_val = A_list[-count-1]
        aoki_val = aoki_A_list[count]
        aoki_view_val = aoki_val - X

        if aoki_view_val >= 0:
            aoki_last_plus = aoki_val
            now_plus = True
        else:
            now_plus = False

        #print(taka_val, aoki_val, aoki_last_plus, aoki_view_val)

        if aoki_last_plus is not None and aoki_last_plus >= taka_val:
            if not now_plus:
                aoki_fail = False
            if now_plus:
                if aoki_last_plus == taka_val:
                    aoki_fail = True
                else:
                    aoki_fail = False

            break

        if aoki_view_val < 0:
            aoki_last_minus = aoki_val
        
        count += 1

    conflict_count = count

    first_sum = sum(aoki_A_list[:conflict_count])
    if aoki_last_minus is not None:
        aoki_minus_last_i = A_list.index(aoki_last_minus)
    else:
        if conflict_count >= 1:
            aoki_minus_last_i = A_list.index(aoki_A_list[0])
        else:
            aoki_minus_last_i = None

    last_i = aoki_minus_last_i
    if last_i is not None:
        if aoki_fail:
            if last_i >= 1:
                if last_i % 2 == 1:
                    nokori_sum = sum(A_list[0:last_i:2])
                else:
                    nokori_sum = sum(A_list[1:last_i:2])
                
            else:
                nokori_sum = 0
        else:
            if last_i >= 2:
                nokori_sum = sum(A_list[(last_i%2):last_i-1:2])
            else:
                nokori_sum = 0

        out = sum(A_list) - (first_sum + nokori_sum)
    else:
        if N % 2 == 1:
            out = sum(A_list[0::2])
        else:
            out = sum(A_list[1::2])

    return out
        
for i in range(Q):
    X = int(input())
    out = game(A_list, X, N)
    print(out)
Problem p03227 (python)

Fixed submission:
str1 = raw_input().replace("\n", "")

if len(str1) == 2:
    print str1
else:
    print str1[::-1]

Buggy submission (verdict: Runtime Error):
import numpy as np
import copy

N = int(raw_input().replace("\n", ""))

a_list = []

for i in xrange(N):
    a = int(raw_input().replace("\n", ""))
    a_list.append(a)

input_list = a_list

a_array = np.asarray(a_list)
sum_diffs = []
for start_elm in input_list:
    a_list = copy.deepcopy(input_list)
    target_elm = start_elm
    
    sum_diff = 0
    while len(a_list) >= 1:
        a_list.remove(target_elm)
        if len(a_list) >= 1:
            a_array = np.abs(np.asarray(a_list) - target_elm)
            target_elm_index = np.argmax(a_array)
            target_elm = a_list[target_elm_index]
            sum_diff += a_array[target_elm_index]
        else:
            #sum_diff += np.abs(a_list[0] - target_elm)
            break
    
    sum_diffs.append(sum_diff)

print max(sum_diffs)
Problem p03273 (python)

Fixed submission:
import numpy as np

inputs = raw_input().replace("\n", "")
H, W = map(int, inputs.split(" "))

lines = np.asarray([list(raw_input().replace("\n", "")) for h in xrange(H)])

h_indexs, w_indexs = map(set, np.where(lines == "#"))

outlines = lines[list(h_indexs), :][:, list(w_indexs)]
for outline in outlines:
    print "".join(outline)

Buggy submission (verdict: Runtime Error):
import numpy as np

H, W = map(int, input().split(" "))

lines = np.asarray([list(input().replace("\n", "")) for h in range(H)])

h_indexs, w_indexs = map(set, np.where(lines == "#"))

outlines = lines[list(h_indexs), :][:, list(w_indexs)]
for outline in outlines:
    print("".join(outline))
Problem p02588 (python)

Fixed submission:
N = int(input())
A = []
for i in range(N):
    a = input()
    b = a.split(".")
    if len(b)==1:
        A.append(int(a)*(10**9))
    else:
        A.append(int(b[0] + b[1] + (9-len(b[1]))*"0"))

B = [[0]*50 for i in range(50)]
ans1 = 0
for i in range(N):
    a = A[i]
    count1 = 0
    while a%2==0:
        a//=2
        count1+=1
    count2 = 0
    while a%5==0:
        a//=5
        count2+=1
    #print(count1,count2,A[i])
    B[count1][count2] += 1
    if count1>=9 and count2>=9:
        ans1+=1

C = [[0]*51 for i in range(51)]

for i in range(50):
    for j in range(50):
        C[i+1][j+1] = B[i][j] + C[i+1][j] + C[i][j+1] - C[i][j]

#print(*C,sep="\n")
ans = 0
for i in range(50):
    for j in range(50):
        k,l = min(18,i),min(18,j)
        #if B[i][j]>0:
        #    print(B[i][j],C[21][21] + C[18-k][18-l] - C[21][18-l] - C[18-k][21],i,j)
        ans += B[i][j] * (C[50][50] + C[18-k][18-l] - C[50][18-l] - C[18-k][50])

print((ans-ans1)//2)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = []
for i in range(N):
    a = input()
    b = a.split(".")
    if len(b)==1:
        A.append(int(a)*(10**9))
    else:
        A.append(int(b[0] + b[1] + (9-len(b[1]))*"0"))

B = [[0]*30 for i in range(30)]
ans1 = 0
for i in range(N):
    a = A[i]
    count1 = 0
    while a%2==0:
        a//=2
        count1+=1
    count2 = 0
    while a%5==0:
        a//=5
        count2+=1
    #print(count1,count2,A[i])
    B[count1][count2] += 1
    if count1>=9 and count2>=9:
        ans1+=1

C = [[0]*31 for i in range(31)]

for i in range(30):
    for j in range(30):
        C[i+1][j+1] = B[i][j] + C[i+1][j] + C[i][j+1] - C[i][j]

#print(*C,sep="\n")
ans = 0
for i in range(30):
    for j in range(30):
        k,l = min(18,i),min(18,j)
        #if B[i][j]>0:
        #    print(B[i][j],C[21][21] + C[18-k][18-l] - C[21][18-l] - C[18-k][21],i,j)
        ans += B[i][j] * (C[21][21] + C[18-k][18-l] - C[21][18-l] - C[18-k][21])

print((ans-ans1)//2)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = []
for i in range(N):
    a = input()
    b = a.split(".")
    if len(b)==1:
        A.append(int(a)*(10**9))
    else:
        A.append(int(b[0] + b[1] + (9-len(b[1]))*"0"))

B = [[0]*21 for i in range(21)]
ans1 = 0
for i in range(N):
    a = A[i]
    count1 = 0
    while a%2==0:
        a//=2
        count1+=1
    count2 = 0
    while a%5==0:
        a//=5
        count2+=1
    #print(count1,count2,A[i])
    B[count1][count2] += 1
    if count1>=9 and count2>=9:
        ans1+=1

C = [[0]*22 for i in range(22)]

for i in range(21):
    for j in range(21):
        C[i+1][j+1] = B[i][j] + C[i+1][j] + C[i][j+1] - C[i][j]

#print(*C,sep="\n")
ans = 0
for i in range(21):
    for j in range(21):
        k,l = min(18,i),min(18,j)
        #if B[i][j]>0:
        #    print(B[i][j],C[21][21] + C[18-k][18-l] - C[21][18-l] - C[18-k][21],i,j)
        ans += B[i][j] * (C[21][21] + C[18-k][18-l] - C[21][18-l] - C[18-k][21])

print((ans-ans1)//2)
Problem p02603 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))

ud = [0]

if A[1] > A[0]:
    trend = 1
elif A[1] == A[0]:
    trend = 0
else:
    trend = -1

if trend != 0:
    first_trend = trend
else:
    first_trend = 0
for i in range(1,N):
    if A[i] > A[i-1]:
        if first_trend==0:
            first_trend = 1
        if trend==-1:
            ud.append(i-1)
        trend = 1
    elif A[i] < A[i-1]:
        if first_trend==0:
            first_trend = -1
        if trend==1:
            ud.append(i-1)
        trend = -1

ud.append(N-1)

M = 1000

for i in range(len(ud)):
    if first_trend == 1:
        if i%2==0 and i!=len(ud)-1:
            stock = M // A[ud[i]]
            M = stock*A[ud[i+1]] + M % A[ud[i]]
    else:
        if i%2==1 and i!=len(ud)-1:
            stock = M // A[ud[i]]
            M = stock*A[ud[i+1]] + M % A[ud[i]]


print(M)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

ud = [0]

if A[1] > A[0]:
    trend = 1
elif A[1] == A[0]:
    trend = 0
else:
    trend = -1

if trend != 0:
    first_trend = trend

for i in range(1,N):
    if A[i] > A[i-1]:
        if first_trend==0:
            first_trend = 1
        if trend==-1:
            ud.append(i-1)
        trend = 1
    elif A[i] < A[i-1]:
        if first_trend==0:
            first_trend = -1
        if trend==1:
            ud.append(i-1)
        trend = -1

ud.append(N-1)

M = 1000

for i in range(len(ud)):
    if first_trend == 1:
        if i%2==0 and i!=len(ud)-1:
            stock = M // A[ud[i]]
            M = stock*A[ud[i+1]] + M % A[ud[i]]
    else:
        if i%2==1 and i!=len(ud)-1:
            stock = M // A[ud[i]]
            M = stock*A[ud[i+1]] + M % A[ud[i]]


print(M)
Problem p02937 (python)

Fixed submission:
from bisect import bisect_right

s = input()
t = input()

char_list = [[] for i in range(26)]

for i in range(2*len(s)):
        if i<len(s):
                char_list[ord(s[i])-97].append(i)
        else:
                char_list[ord(s[i-len(s)])-97].append(i)

INF = 10**27

for i in range(26):
        char_list[i].append(INF)

next_list = [[char_list[j][bisect_right(char_list[j],i)] for j in range(26)] for i in range(len(s))]

flag = False
for i in range(len(s)):
        if t[0]==s[i]:
                flag=True
                x = i
                y = i
                break
if flag:
        flag2 = True
        for i in range(1,len(t)):
                n = next_list[x][ord(t[i])-97]
                y += n - x
                x = n%(len(s))
                if y >= INF:
                        flag2=False
                        break
        if flag2:
                print(y+1)
        else:
                print(-1)
else:
        print(-1)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_right

s = input()
t = input()

char_list = [[] for i in range(26)]

for i in range(2*len(s)):
        if i<len(s):
                char_list[ord(s[i])-97].append(i)
        else:
                char_list[ord(s[i-len(s)])-97].append(i)

INF = 10**27

for i in range(26):
        char_list[i].append(INF)

next_list = [[char_list[j][bisect_right(char_list[j],i)] for j in range(26)] for i in range(len(s))]

flag = False
for i in range(len(s)):
        if t[0]==s[i]:
                flag=True
                x = i
                y = i
                break
if flag:
        flag2 = True
        for i ina range(1,len(t)):
                n = next_list[x][ord(t[i])-97]
                y += n - x
                x = n%(len(s))
                if y >= INF:
                        flag2=False
                        break
        if flag2:
                print(y+1)
        else:
                print(-1)
else:
        print(-1)
Problem p02985 (python)

Fixed submission:
N,K = list(map(int,input().split()))

e_list = [[] for i in range(N)]

for i in range(N-1):
    a,b = list(map(int,input().split()))
    a,b = a-1,b-1
    e_list[a].append(b)
    e_list[b].append(a)

if K==1:
    if N==1:
        print(1)
    else:
        print(0)
else:
    mod=10**9+7
    combA = [1]
    ca = 1
    for i in range(K-1):
        ca = (ca*(K-1-i))%mod
        combA.append(ca)
    combB = [1]
    cb = 1
    for i in range(K-2):
        cb = (cb*(K-2-i))%mod
        combB.append(cb)
    flag=True
    #print(combA)
    #print(combB)
    ans = K
    mod=10**9+7
    vi = 0 #時と場合によってここを変える
    from collections import deque
    Q = deque([vi])
    checked_list = [False for i in range(N)]
    checked_list[vi]=True
    while len(Q)>0:
        v = Q.pop()
        count=0
        for v1 in e_list[v]:
            if not checked_list[v1]:
                checked_list[v1]=True
                Q.appendleft(v1)
                count+=1
        
        if v==0:
            if count<=K-1:
                ans= (ans*combA[count])%mod
            else:
                flag=False
                break
        else:
            if count<=K-2:
                ans= (ans*combB[count])%mod
                #print(count)
            else:
                flag=False
                break
    if flag:
        print(ans)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
N,K = list(map(int,input().split()))

e_list = [[] for i in range(N)]

for i in range(N-1):
    a,b = list(map(int,input().split()))
    a,b = a-1,b-1
    e_list[a].append(b)
    e_list[b].append(a)

if K==1:
    print(1)
else:
    mod=10**9+7
    combA = [1]
    ca = 1
    for i in range(K-1):
        ca = (ca*(K-1-i))%mod
        combA.append(ca)
    combB = [1]
    cb = 1
    for i in range(K-2):
        cb = (cb*(K-2-i))%mod
        combB.append(cb)

    #print(combA)
    #print(combB)
    ans = K
    mod=10**9+7
    vi = 0 #時と場合によってここを変える
    from collections import deque
    Q = deque([vi])
    checked_list = [False for i in range(N)]
    checked_list[vi]=True
    while len(Q)>0:
        v = Q.pop()
        count=0
        for v1 in e_list[v]:
            if not checked_list[v1]:
                checked_list[v1]=True
                Q.appendleft(v1)
                count+=1
        
        if v==0:
            ans= (ans*combA[count])%mod
        else:
            ans= (ans*combB[count])%mod
            #print(count)

    print(ans)
Problem p02999 (python)

Fixed submission:
X,A = list(map(int,input().split()))

if X<A:
    print(0)
else:
    print(10)

Buggy submission (verdict: Runtime Error):
parseInt(x) = parse(Int,x)

parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    X, A = readline() |> split |> parseMap
    if X<A
        println(0)
    else
        println(10)
    end
end

main()
Problem p03026 (python)

Fixed submission:

N=int(input())
road_list = [[] for i in range(N)]

for i in range(N-1):
    a,b=list(map(int,input().split()))
    a=a-1
    b=b-1
    road_list[a].append(b)
    road_list[b].append(a)
c = list(map(int,input().split()))
from collections import deque
Q = deque([[0,0]])
ans = []
checked_list = [False for i in range(N)]
checked_list[0]=True
count_list = [10**9 for i in range(N)]
count_list[0] = 0

while len(Q)>0:
    v,count = Q.pop()
    count+=1
    for v1 in road_list[v]:        
        if not checked_list[v1]:
            checked_list[v1]=True
            Q.append([v1,count])
            count_list[v1]=count

c.sort()

count_list = [[i,count_list[i]] for i in range(N)]
count_list = sorted(count_list, key=lambda x:x[1],reverse=True)
d = [[count_list[i][0],c[i]] for i in range(N)]
d = sorted(d, key=lambda x:x[0])
d = [d[i][1] for i in range(N)]
print(sum(c[:-1]))
print(*d)

Buggy submission (verdict: Runtime Error):



N=int(input())
road_list = [[] for i in range(N)]

for i in range(N-1):
    a,b=list(map(int,input().split()))
    a=a-1
    b=b-1
    road_list[a].append(b)
    road_list[b].append(a)
c = list(map(int,input().split()))
from collections import deque
Q = deque([[0,0]])
ans = []
checked_list = [False for i in range(N)]
checked_list[0]=True
count_list = [10**9 for i in range(N)]
count_list[0] = 0

while len(Q)>0:
    v,count = Q.pop()
    count+=1
    for v1 in road_list[v]:        
        if not checked_list[v1]:
            checked_list[v1]=True
            Q.append([v1,count])
            count_list[v1]=count

c.sort()

count_list = [[i,count_list[i]] for i in range(N)]
count_list = sorted(count_list, key=lambda x:x[1],reverse=True)
d = [[count_list[i][0],c[i]] for i in range(N)]
d = sorted(d, key=lambda x:x[0])
d = [d[i][1] for i in range(N)]
print(sum(c[:-1]))
print(*d)


N,A,B,C = list(map(int,input().split()))
Problem p03029 (python)

Fixed submission:

A,P=list(map(int,input().split()))

P+=A*3

print(P//2)

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]

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

    road = []
    x_list = []

    for i in range(N):
        s,t,x = list(map(int,input().split()))
        road.append([0,s-x,x])
        road.append([1,t-x,x])

    for i in range(Q):
        road.append([2,int(input()),i])

    from collections import defaultdict

    counter = defaultdict(int)
    counter[10**27] = 1
    ans = [0]*Q

    road.sort(key=lambda x:x[0])
    road.sort(key=lambda x:x[1])

    q = [10**27]

    from heapq import heappop,heappush

    for id,_,x in road:
        if id==0:
            heappush(q,x)
            counter[x]+=1
        elif id==1:
            counter[x]-=1
        else:
            while counter[q[0]]==0:
                heappop(q)
            #print(q)
            if q[0]<10**27:
                ans[x] = q[0]
            else:
                ans[x] = -1
    print("\n".join(map(str,ans)))

if __name__ == '__main__':
    main()