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

Fixed submission:
import sys
input = sys.stdin.readline
from itertools import accumulate

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = [0]+list(accumulate(A))
b = [0]+list(accumulate(B))
ans,j = 0,M
for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans,i+j)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from itertools import accumulate

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = [0]+list(accumulate(A))
b = [0]+list(accumulate(B))
ans,j = 0,M
for i in range(N+1):
    if i > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans,i+j)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from itertools import accumulate

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Acc = list(accumulate(A))
Bcc = list(accumulate(B))
a = N-1
b = M-1
ans = 0
for n,i in enumerate(Acc):
    if i > K:
        a = n-1
        break
for n,i in enumerate(Bcc):
    if i > K:
        b = n-1
        break
if a > b:
    K -= Acc[a]
    b = 0
    for i in B:
        if i <= K:
            K -= i
            b += 1
        elif i < A[a]:
            K += A[a]-i
            a -= 1
            b += 1
        else:
            break
else:
    K -= Bcc[b]
    a = 0
    for i in A:
        if i <= K:
            K -= i
            b += 1
        elif i < B[b]:
            K += B[b] - i
            b -= 1
            a += 1
        else:
            break
a = a+1 if a else a
b = b+1 if b else b
print(a+b)
Problem p02679 (python)

Fixed submission:
from math import gcd
from collections import defaultdict
N=int(input())
mod = 10**9+7
d_1 = defaultdict(int)
d_2 = defaultdict(int)
zeros = 0

def to_irreducible(a,b):
    GCD = gcd(a,b)
    return list(map(lambda x:x//GCD,[a,b]))
for i in range(N):
    a,b=map(int,input().split(' '))
    if a==b==0:
        zeros += 1
    elif a*b >= 0 and b!=0:
        a,b = to_irreducible(abs(a),abs(b))
        d_1[(a,b)] +=1
    else:
        a,b = to_irreducible(abs(b),abs(a))
        d_1[(a,b)] +=0
        d_2[(a,b)] +=1

ans =  1

for k,v_1 in d_1.items():
    v_2 = d_2[k]
    ans *= (pow(2,v_1,mod) + pow(2,v_2,mod) -1)
    ans %= mod

print((ans+zeros-1)%mod)

Buggy submission (verdict: Runtime Error):
from math import gcd
from fractions import Fraction
from numpy import sign
N=int(input())
d={}
mod = 10**9+7
d={}
zeros = 0
b_zero = 0
a_zero = 0
for i in range(N):
    a, b = map(int,input().split(' '))
    a, b = map(lambda x:x//gcd(a,b),[a,b])
    if a == b == 0:
        zeros += 1
    elif a == 0:
        a_zero += 1
    elif b == 0:
        b_zero += 1
    else:
        h,t=sorted([Fraction(a,b),Fraction(-b,a)])
        key = str(h)+'/'+str(t)
        d.setdefault(key,[0,0])
        if a*b > 0:
            d[key][0] += 1
        else:
            d[key][1] += 1
ans = 1
for  v in d.values():
    h,t=sorted(v)
    if h>0:
        ans *= pow(2,h,mod) + pow(2,t,mod) -1
    else:
        ans *= pow(2,t,mod)
    ans %=mod
ans += pow(2,a_zero,mod) + pow(2,b_zero,mod) + zeros -3
print(ans)
Problem p02685 (python)

Fixed submission:
N,M,K=map(int,input().split(' '))
mod = 998244353
ans =0
fac=[0]*(N+1)
inv=[0]*(N+1)
finv=[0]*(N+1)
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,N+1):
    fac[i] = fac[i-1]*i%mod
    inv[i] = mod-inv[mod%i]*(mod//i)%mod
    finv[i] = finv[i-1]*inv[i]%mod
def COM(n,k):
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod
for i in range(K+1):
    ans += M*pow(M-1,N-1-i,mod)*COM(N-1,i)
    ans %=mod
print(ans)

Buggy submission (verdict: Runtime Error):
N,M,K=map(int,input().split(' '))
mod = 998244353
ans =0
fac=[0]*N
inv=[0]*N
finv=[0]*N
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,N):
    fac[i] = fac[i-1]*i%mod
    inv[i] = mod-inv[mod%i]*(mod//i)%mod
    finv[i] = finv[i-1]*inv[i]%mod
def COM(n,k):
    if (n < k):
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod
for i in range(K+1):
    #print(M*pow(M-1,N-1-i,mod),COM(N-1,i))
    ans += M*pow(M-1,N-1-i,mod)*COM(N-1,i)
    ans %=mod
print(ans)
Problem p02762 (python)

Fixed submission:
class UnionFind:
    def __init__(self,N):
        self.par =[-1 for i in range(N)]
    def find(self,x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.par[x] > self.par[y]:
            x,y = y,x
        self.par[x] +=self.par[y]
        self.par[y] = x

    def size(self,x):
        return -self.par[self.find(x)]
    def same(self,x,y):
        return self.find(x)==self.find(y)

N,M,K=map(int,input().split(' '))
Friend = UnionFind(N)
pull = [-1] * N
for i in range(M):
    a,b = map(int,input().split(' '))
    Friend.unite(a-1,b-1)
    pull[a-1] -= 1
    pull[b-1] -= 1
for i in range(K):
    c,d=map(int,input().split(' '))
    if Friend.same(c-1,d-1):
        pull[c-1] -=1
        pull[d-1] -=1
print(' '.join([str(Friend.size(i)+pull[i]) for i in range(N)]))

Buggy submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self,N):
        self.par =[-1 for i in range(N)]
    def find(self,x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.par[x] > self.par[y]:
            x,y = y,x
        self.par[x] +=self.par[y]
        self.par[y] = x

    def size(self,x):
        if self.par[x] < 0:
            return -self.par[x]
        else:
            self.par[x] = self.size(self.par[x])
            return self.par[x]
    def same(self,x,y):
        return self.find(x)==self.find(y)

N,M,K=map(int,input().split(' '))
Friend = UnionFind(N)
pull = [-1] * N
for i in range(M):
    a,b = map(int,input().split(' '))
    Friend.unite(a-1,b-1)
    pull[a-1] -= 1
    pull[b-1] -= 1
for i in range(K):
    c,d=map(int,input().split(' '))
    if Friend.same(c-1,d-1):
        pull[c-1] -=1
        pull[d-1] -=1
print(' '.join([str(Friend.size(i)+pull[i]) for i in range(N)]))
Problem p02781 (python)

Fixed submission:
N=input()
K=int(input())
dp_0 = [[0]*(len(N)) for i in range(K+1)]
dp_1 = [[0]*(len(N)) for i in range(K+1)]
dp_0[0][0]=1
dp_0[1][0]=int(N[0])-1
dp_1[1][0]=1
for i in range(len(N)-1):
    for j in range(K+1):
        if j==K:
            dp_0[j][i+1] += dp_0[j][i]
        elif j==0:
            dp_0[j][i+1] =dp_0[j][i]
            dp_0[j+1][i+1] += dp_0[j][i]*9
        else:
            dp_0[j][i+1] += dp_0[j][i]
            dp_0[j+1][i+1] += dp_0[j][i]*9
        if j != K and N[i+1] != '0':
            dp_0[j+1][i+1] += (int(N[i+1])-1)*dp_1[j][i]
            dp_0[j][i+1] += dp_1[j][i]
            dp_1[j+1][i+1] = dp_1[j][i]
        elif N[i+1] =='0':
            dp_1[j][i+1] = dp_1[j][i]
        else:

            dp_0[j][i+1] += dp_1[j][i]

print(dp_0[K][len(N)-1]+dp_1[K][len(N)-1])

Buggy submission (verdict: Runtime Error):
from scipy.misc import comb
import math
N=input()
K=int(input())
if K !=1:
    ans = 0
elif len(N)<2:
    print(int(N))
    exit()
else:
    ans = 9
for i in range(2,len(N)):
    ans += 9*comb(i-1,K-1)*(9**(K-1))
ans += max(0,int(N[0])-1)*comb(len(N)-1,K-1)*9**(K-1)
if K==1:
    ans += 1
elif K==2:
    ans += 9*max(0,len(N)-2)+int(N[1])
else:
    ans += int(N[2])+max(0,len(N)-3)*9+max(0,int(N[1])-1)*max(0,len(N)-2)*9+comb(len(N)-2,2)*81
print(math.ceil(ans))

Buggy submission (verdict: Runtime Error):
from scipy.misc import comb
N=input()
K=int(input())
if len(N)<K:
    print(0)
    exit()
if K !=1:
    ans = 0
elif len(N)<2:
    print(int(N))
    exit()
else:
    ans = 9
for i in range(2,len(N)):
    ans += 9*comb(i-1,K-1)*(9**(K-1))
ans += (int(N[0])-1)*comb(len(N)-1,K-1)*9**(K-1)
if K==1:
    ans += 1
elif K==2:
    ans += 9*(len(N)-2)+int(N[1])
else:
    ans += int(N[2])+(len(N)-3)*9+(int(N[1])-1)*(len(N)-2)*9+comb(len(N)-2,2)*81
print(ans)
Problem p02835 (python)

Fixed submission:
a=list(map(int,input().split(' ')))
if sum(a) >=22:
    print('bust')
else:
    print('win')

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split(' '))
if sum(a.b.c) >=22:
    print('bust')
else:
    print('win')
Problem p02862 (python)

Fixed submission:
from numpy.linalg import solve
mod = 10**9+7
x,y=map(int,input().split(' '))
left = [[1,2],
        [2,1]]
right = [x,y]

A=solve(left,right)
ax,ay=float(A[0]),float(A[1])
if not 0.5 <= y/x <= 2:
    print(0)
    exit()
if not float.is_integer(ax) or not float.is_integer(ay):
    print(0)
    exit()
ax,ay=int(ax),int(ay)
fac=[0 for i in range(ax+ay+1)]
inv=[0 for i in range(ax+ay+1)]
finv=[0 for i in range(ax+ay+1)]
fac[0] = 1
fac[1] = 1
finv[0]=1
finv[1]=1
inv[1] = 1
for i in range(2,ax+ay+1):
    fac[i] = fac[i-1]*i%mod
    inv[i] = mod-inv[mod%i]*(mod//i)%mod
    finv[i]= finv[i-1] * inv[i]%mod
ans = fac[ax+ay]*(finv[ax]*finv[ay])
ans %= mod
print(int(ans))

Buggy submission (verdict: Runtime Error):
from numpy.linalg import solve
mod = 10**9+7
x,y=map(int,input().split(' '))
left = [[1,2],
        [2,1]]
right = [x,y]

A=solve(left,right)
ax,ay=float(A[0]),float(A[1])
if (not float.is_integer(ax) or not float.is_integer(ay)):
    print(0)
    exit()
ax,ay=int(ax),int(ay)
fac=[0 for i in range(ax+ay+1)]
inv=[0 for i in range(ax+ay+1)]
finv=[0 for i in range(ax+ay+1)]
fac[0] = 1
fac[1] = 1
finv[0]=1
finv[1]=1
inv[1] = 1
for i in range(2,ax+ay+1):
    fac[i] = fac[i-1]*i%mod
    inv[i] = mod-inv[mod%i]*(mod//i)%mod
    finv[i]= finv[i-1] * inv[i]%mod
ans = fac[ax+ay]*(finv[ax]*finv[ay])
ans %= mod
print(int(ans))
Problem p02933 (python)

Fixed submission:
def main():
    a=int(input())
    s=input()
    if a >= 3200:
        print(s)
    else:
        print('red')

if __name__ == '__main__':
    main()

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

N, Q = map(int, input().split(' '))
tree = [[] for i in range(N + 1)]
for i in range(N - 1):
    a, b = map(int, input().split(' '))
    tree[a].append([a, b])
    tree[b].append([b, a])
val = [0] * (N + 1)
for i in range(Q):
    p, x = map(int, input().split(' '))
    val[p] += x
ans = [-1] * (N + 1)
ans[1] = val[1]
bfs = deque(tree[1])
while bfs:
    p, n = bfs.popleft()
    if ans[n] == -1:
        ans[n] = val[n] + ans[p]
        for i in tree[n]:
            bfs.append(i)
for i in ans[1:-1]:
    print(i,'',end="")
print(ans[-1])
Problem p03011 (python)

Fixed submission:
def main():
    n=list(map(int,input().split(' ')))
    n_sorted = sorted(n)
    print(n_sorted[0]+n_sorted[1])

if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
mod = 10**9+7

def fac(n):
    fac = [1]*(n+1)
    fac[0] = 1
    fac[1] = 1
    for i in range(1,n+1):
        fac[i] = fac[i-1]*i%mod
    return fac

def main():
    n,m=map(int,input().split(' '))
    fact = fac(n)
    check = 0
    pattern = 1
    a = [0]
    a_list = []
    tmp = -1
    for i in range(m):
        an = int(input())
        a.append(an)
    for i in range(m):
        a_list.append(a[i+1]-a[i]-1)
    a_list.append(n-a[-1]-1)
    if a_list[0] ==0:
        a_list.pop(0)
    for i in a_list:
        tmp = 0
        for j in range(i):
            if i - 2*j >=0:
                tmp +=(fact[(i-j)]/fact[j]/fact[i-2*j])%mod
        pattern *= tmp
        pattern %= mod

    print(int(pattern))

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

Fixed submission:
import heapq as hq

def get_num():
    return list(map(int,input().split(' ')))

def main():
    n,m = get_num()
    card = get_num()
    card_sum=sum(card)
    hq.heapify(card)
    d_set=[]
    d=[]
    for i in range(m):
        b,c=get_num()
        hq.heappush(d_set,(-c,b))
    for i in range(m):
        if len(d) ==n:
            break
        cnt = hq.heappop(d_set)
        for i in range(cnt[1]):
            d.append(-cnt[0])
            if len(d)==n:
                break
    for i in range(len(d)):
        c_min=hq.heappop(card)
        d_max=d[i]
        if c_min>=d_max:
            break
        else:
            card_sum += (d_max-c_min)
    print(card_sum)
main()

Buggy submission (verdict: Runtime Error):
import heapq as hq

def get_num():
    return list(map(int,input().split(' ')))

def main():
    n,m = get_num()
    card = get_num()
    card_sum=sum(card)
    hq.heapify(card)
    d_set=[]
    d=[]
    for i in range(m):
        b,c=get_num()
        hq.heappush(d_set,(-c,b))
    for i in range(m):
        if len(d) ==n:
            break
        cnt = hq.heappop(d_set)
        for i in range(cnt[1]):
            d.append(-cnt[0])
            if len(d)==n:
                break
    for i in range(n):
        c_min=hq.heappop(card)
        d_max=d[i]
        if c_min>=d_max:
            break
        else:
            card_sum += (d_max-c_min)
    print(card_sum)
main()

Buggy submission (verdict: Runtime Error):
import heapq as hq

def get_num():
    return list(map(int,input().split(' ')))

def main():
    n,m = get_num()
    card = get_num()
    card_sum=sum(card)
    hq.heapify(card)
    d_set=[]
    d=[]
    for i in range(m):
        b,c=get_num()
        hq.heappush(d_set,(-c,b))
    while len(d)<n:
        cnt = hq.heappop(d_set)
        for i in range(cnt[1]):
            d.append(-cnt[0])
            if len(d)==n:
                break
    for i in range(n):
        c_min=hq.heappop(card)
        d_max=d[i]
        if c_min>=d_max:
            break
        else:
            card_sum += (d_max-c_min)
    print(card_sum)
main()
Problem p03041 (python)

Fixed submission:
n,k=list(map(int,input().split(" ")))
s=list(input())
s_str = ""
if s[k-1]=="A":
    s[k-1]="a"
elif s[k-1]=="B":
    s[k-1]="b"
else:
    s[k-1]="c"
for i in s:
    s_str += i
print(s_str)

Buggy submission (verdict: Runtime Error):
n,k=list(map(int,input().split(" ")))
s=list(input())
s_str=""
s[k-1]=s[k-1].lower()
for i in s:
    s_str +=s[i]
print(s_str)

Buggy submission (verdict: Runtime Error):
n,k=list(map(int,input().split(" ")))
s=list(input())
s_str=""
s[k-1]=s[k-1].lower()
for i in s:
  s_str +=s[i]
print(s_str)

Buggy submission (verdict: Runtime Error):
n,k=list(map(int,input().split(" ")))
s=list(input())
s_str=""
s[k-1]=s[k-2].lower()
for i in s:
    s_str +=s[i]
print(s_str)

Buggy submission (verdict: Runtime Error):
n,k=list(map(int,input().split(" ")))
s=list(input())
s_str=""
s[k-1]=s[k-2].lower()
for i in s:
  s_str +=s[i]
print(s_str)

Buggy submission (verdict: Runtime Error):
n,k=list(map(int,input().split(" ")))
s=list(input())
s_str=""
s[k-1]=s[k-2].lower()
for i in s:
  s_str +=s[i]
print(s_str)
Problem p03053 (python)

Fixed submission:
import numpy as np

def solve():
    H,W=map(int,input().split(' '))
    max_value = H+W
    values =[]
    for i in range(H):
      values.append([0 if i == '#' else max_value for i in list(input())])
    values = np.array(values)

    for x in range(W-1):
        values[:,x+1] = np.minimum(values[:,x]+1,values[:,x+1])
    for x in range(W-1,0,-1):
        values[:,x-1] = np.minimum(values[:,x-1],values[:,x]+1)
    for x in range(H-1):
        values[x+1,:] = np.minimum(values[x,:]+1,values[x+1,:])
    print('')
    for x in range(H-1,0,-1):
        values[x-1,:] = np.minimum(values[x,:]+1,values[x-1,:])
    print(np.max(values))
solve()

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

def solve():
    H,W=map(int,input().split(' '))
    max_value = H+W
    values =[]
    for i in range(H):
      values.append([0 if i == '#' else max_value for i in list(input())])
    values = np.array(values)

    for x in range(W-1):
        values[:,x+1] = np.minimum(values[:,x]+1,values[:,x+1])
    for x in range(W-1,0,-1):
        values[:,x] = np.minimum(values[:,x+1]+1,values[:,x])
    for x in range(H-1):
        values[x+1,:] = np.minimum(values[x,:]+1,values[x+1,:])
    for x in range(H-1,0,-1):
        values[x,:] = np.minimum(values[x+1,:]+1,values[x,:])

    print(np.max(values),)
solve()
Problem p03135 (python)

Fixed submission:
t,x=map(int,input().split(' '))
print(t/x)

Buggy submission (verdict: Runtime Error):
t,x=map(int,input().split(' ')
print(t/x)

Buggy submission (verdict: Runtime Error):
t,x=map(int,input().split(''))
print(t/x)
Problem p03208 (python)

Fixed submission:
N,K=map(int,input().split(' '))
h=sorted([int(input()) for i in range(N)])
ans = 10**9
for i in range(N-K+1):
    ans = min(ans,h[i+K-1]-h[i])
print(ans)

Buggy submission (verdict: Runtime Error):
5 3
5
7
5
7
7
Problem p03327 (python)

Fixed submission:
N=int(input())
if N < 1000:
    print('ABC')
else:
    print('ABD')

Buggy submission (verdict: Runtime Error):
N=int(input())
if N < 1000:
    print('ABC'+N)
else:
    print('ABD'+format(N-999,'03d'))
Problem p03631 (python)

Fixed submission:
def main():
    n=input()
    for i,j in zip(n,reversed(n)):
        if i!=j:
            print('No')
            exit()
    print('Yes')

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
N=int(input())
tree=np.array([[0]*N for i in range(N)])
for i in range(N-1):
    a,b,c=map(int,input().split(' '))
    tree[a-1][b-1] = c
    tree[b-1][a-1] = c
Q,K=map(int,input().split(' '))
ans = dijkstra(tree,indices=K-1)
for i in range(Q):
    s,e=map(int,input().split(' '))
    print(int(ans[s-1]+ans[e-1]))
Problem p03634 (python)

Fixed submission:
from collections import deque

N = int(input())
ABC=[map(int,input().split(' ')) for i in range(N-1)]
Q,K =  map(int,input().split(' '))
query = [map(int,input().split(' ')) for i in range(Q)]
tree = [[] for i in range(N+1)]
for a,b,c in ABC:
    tree[b].append((a,c))
    tree[a].append((b,c))
k_shortest = [0]*(N+1)
stack=deque([K])
while stack:
    k = stack.popleft()
    for v,d in tree[k]:
        if k_shortest[v] == 0:
            k_shortest[v] = k_shortest[k]+d
            stack.append(v)
for i,j in query:
    print(k_shortest[i]+k_shortest[j])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)

def dfs(v,d):
    k_shortest[v] = d
    visit[v] = 1
    for i,j in tree[v]:
        if not visit[i]:
            dfs(i,d+j)

N=int(input())
tree=[[] for i in range(N+1)]
visit = [0]*(N+1)
k_shortest = [0]*(N+1)
for i in range(N-1):
    a,b,c=map(int,input().split(' '))
    tree[a].append((b,c))
    tree[b].append((a,c))
Q,K=map(int,input().split(' '))
dfs(K,0)
query = [list(map(int,input().split(' '))) for i in range(Q)]
for i,j in query:
    print(k_shortest[i]+k_shortest[j])

Buggy submission (verdict: Runtime Error):
def dfs(v,d):
    k_shortest[v] = d
    visit[v] = 1
    for i,j in tree[v]:
        if not visit[i]:
            dfs(i,d+j)

N=int(input())
tree=[[] for i in range(N+1)]
visit = [0]*(N+1)
k_shortest = [0]*(N+1)
for i in range(N-1):
    a,b,c=map(int,input().split(' '))
    tree[a].append((b,c))
    tree[b].append((a,c))
Q,K=map(int,input().split(' '))
dfs(K,0)
query = [list(map(int,input().split(' '))) for i in range(Q)]
for i,j in query:
    print(k_shortest[i]+k_shortest[j])

Buggy submission (verdict: Runtime Error):
import math

def dfs(v,d):
    k_shortest[v] = d
    visit[v] = 1
    for i,j in tree[v]:
        if not visit[i]:
            dfs(i,d+j)

N=int(input())
tree=[[] for i in range(N+1)]
visit = [0]*(N+1)
k_shortest = [math.inf]*(N+1)
for i in range(N-1):
    a,b,c=map(int,input().split(' '))
    tree[a].append((b,c))
    tree[b].append((a,c))
Q,K=map(int,input().split(' '))
dfs(K,0)
query = [list(map(int,input().split(' '))) for i in range(Q)]
for i,j in query:
    print(k_shortest[i]+k_shortest[j])

Buggy submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix
import math
N=int(input())
tree=[[math.inf]*N for i in range(N)]
for i in range(N-1):
    a,b,c=map(int,input().split(' '))
    tree[a-1][b-1] = c
    tree[b-1][a-1] = c
tree = np.array(tree)
Q,K=map(int,input().split(' '))
csr = csr_matrix(tree)
ans = shortest_path(csr,indices=K-1)
for i in range(Q):
    s,e=map(int,input().split(' '))
    print(int(ans[s-1]+ans[e-1]))
Problem p02623 (python)

Fixed submission:
from sys import stdin
import sys
import math
import random
from decimal import Decimal


N, M, K = [int(x) for x in stdin.readline().rstrip().split()]
A = list(map(int, input().split()))
A1 = [0]
for i, v in enumerate(A):
    x = A1[i]+v
    A1.append(x)
B = list(map(int, input().split()))
B1 = [0]
for i, v in enumerate(B):
    x = B1[i]+v
    B1.append(x)
c1 = 0
c2 = 0
ans = 0
temp = M

for i in range(N+1):
    if A1[i] > K:
        break
    while B1[temp] > K-A1[i]:
        temp -= 1
    ans = max(ans, i+temp)
    # for k in range(temp, 0, -1):
    #     if A1[i]+B1[k] <= K:
    #         ans = max(ans, i+k)
    #         temp = k
    #         break
# print(c1, c2)

print(ans)

Buggy submission (verdict: Runtime Error):
from sys import stdin
import sys
import math
import random
from decimal import Decimal


N, M, K = [int(x) for x in stdin.readline().rstrip().split()]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(10**10)
B.append(10**10)
c1 = 0
c2 = 0
flag = 0
while True:
    if K < A[c1] and K < B[c2]:
        break
    if A[c1] < B[c2]:
        K = K-A[c1]
        c1 += 1
    elif A[c1] > B[c2]:
        K = K-B[c2]
        c2 += 1
    else:
        t1 = c1+1
        t2 = c2+1
        while True:
            if A[t1] < B[t2]:
                K = K-A[c1]
                c1 += 1
                break
            elif A[t1] > B[t2]:
                K = K-B[c2]
                c2 += 1
                break
            else:
                t1 = t1+1
                t2 = t2+1
print(c1+c2)
Problem p02820 (python)

Fixed submission:
from sys import stdin
# import math
N, K = [int(x) for x in stdin.readline().rstrip().split()]
R, S, P = [int(x) for x in stdin.readline().rstrip().split()]
s = input()
ans = 0
d = {'r': P, 's': R, 'p': S}
# print(d)
temp = [0 for i in range(len(s))]
for i, v in enumerate(s):
    # print(i, v, temp)
    if i < len(s)-K and temp[i] != 1:
        if s[i+K] == s[i]:
            ans += d[s[i]]
            temp[i+K] = 1
        else:
            ans += d[s[i]]
    else:
        if temp[i] != 1:
            ans += d[s[i]]
print(ans)

Buggy submission (verdict: Runtime Error):
from sys import stdin
# import math
N, K = [int(x) for x in stdin.readline().rstrip().split()]
R, S, P = [int(x) for x in stdin.readline().rstrip().split()]
s = input()
ans = 0
d = {'r': P, 's': R, 'p': S}
# print(d)
temp = [0 for i in range(len(s))]
for i, v in enumerate(s):
    # print(i, v, temp)
    if i <= len(s)-K and temp[i] != 1:
        if d[s[i+K]] == d[s[i]]:
            ans += d[s[i]]
            temp[i+K] = 1
        else:
            ans += d[s[i]]
    else:
        if temp[i] != 1:
            ans += d[s[i]]
print(ans)
Problem p03072 (python)

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

_count=1
max_height=H[0]

for i in range(1,N):
    if max_height <= H[i]:
        _count +=1
        max_height = H[i]
print(_count)

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

_count=1
max_height=H[0]

for i in range(1,N):
    if max_height <= H[i]:
        count +=1
        max_height = H[i]
print(_count)