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

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = sum(list(map(int, input().split())))
c = list(map(int, input().split()))
for i in range(n-1):
  if a[i+1]-a[i]==1:
    b+=c[a[i]-1]
print(b)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = sum(list(map(int, input().split())))
c = list(map(int, input().split()))
for i in range(n-1):
  if a[i+1]-a[i]==1:
    b+=c[a[i]-1]
print(total)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
total = sum(b)
for i in range(n):
  if a[i+1]-a[i]==1:
    total+=c[i]
print(total)
Problem p03127 (python)

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

#ユーグリッドの互除法で、a,bを与えて、aをbで割ってあまりを計算する
#あまりがないときは、最後に割った数を返す（最大公約数）
#あまりがあるときは、bにあまりを入れて、再び計算する
def gcd(a,b):
	if b == 0:
		return a
	return gcd(b,a%b)


x = A[0]
for i in A[1:]:
	x = gcd(x,i)
print(x)

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

#ユーグリッドの互除法で、a,bを与えて、aをbで割ってあまりを計算する
#あまりがないときは、最後に割った数を返す（最大公約数）
#あまりがあるときは、bにあまりを入れて、再び計算する
def gcd(a,b):
	if b == 0:
		return a
	return gcd(b,a%b)


x = A[0]
for i in a[1:]:
	x = gcd(x,i)
print(x)
Problem p03250 (python)

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

answer = A[0]*10 + A[1] + A[2] 

print(answer)

Buggy submission (verdict: Runtime Error):
S = str(input())
T = str(input())

from collections import defaultdict
s = defaultdict(int)
t = defaultdict(int)

for i in S:
	s[i] += 1

for j in T:
	t[j] += 1

ss = sorted(s.values())
tt = sorted(t.values())

if ss == tt:
	print('Yes')
else:
	print('No')

Buggy submission (verdict: Runtime Error):
S = str(input())
T = str(input())

#辞書型を使ってみる。defaultdictは便利らしい。どこがかはちょっとよく分からなかった。
from collections import defaultdict
s = defaultdict(int)
t = defaultdict(int)


for i in S:
	s[i] += 1

for j in T:
	t[j] += 1

#辞書型をソートできるsoted()を使う。
#values()で辞書型のkey valueのvalueだけを取り出している。

ss = sorted(s.values())
tt = sorted(t.values())

if ss == tt:
	print('Yes')
else:
	print('No')
Problem p03272 (python)

Fixed submission:
n,i = map(int,input().split())
print(n-(i-1))

Buggy submission (verdict: Runtime Error):
n,i = int(input())
print(n-(i-1))
Problem p03329 (python)

Fixed submission:

n = int(input())
pre_list = [1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
 
#nをn+1個並べたリストを作る
dp = [n]*(n+1)
#0を初期化する
dp[0] = 0
 
 
#dp[i]について一つずつ考える
for i in range(1,n+1):
#dp[i]のそれぞれの場合分けについて考える。場合はpre_listの中身の分だけ回せばいい
	for j in pre_list:
		if i - j >= 0:
			dp[i] = min(dp[i],dp[i-j]+1)
 
print(dp[n])

Buggy submission (verdict: Runtime Error):
dpの基本形
#漸化式を立てる
#nを与えられて求めるので、求める物をdp[n]とおいてみる
#dp[1]は１円払うのに必要な回数、dp[2]は...dp[n-1]まで知っている状態で、dp[n]はn円払うのに必要な回数を調べていくと考える


#場合１：dp[n]は、dp[n-1]にさらに1円を払う回数１回を足した回数である
#場合２：dp[n]は、dp[n-6]にさらに6円を払う回数１回を足した回数
#場合３：...

#これら全部の最小値を取れば良い！なるほど。
#でも参照できない物もあるから、参照できるやつだけ取り出すと良いだろう。



n = int(input())
pre_list = [1,6,9,36,81,216,729,1296,6561,7776,46656,59049]

#nをn+1個並べたリストを作る
dp = [n]*(n+1)
#0を初期化する
dp[0] = 0


#dp[i]について一つずつ考える
for i in range(1,n+1):
#dp[i]のそれぞれの場合分けについて考える。場合はpre_listの中身の分だけ回せばいい
	for j in pre_list:
		if i - j >= 0:
			dp[i] = min(dp[i],dp[i-j]+1)

print(dp[n])
Problem p02753 (python)

Fixed submission:
s = input()
if "A" in s and "B" in s:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n = 0

N, A, B = [int(i) for i in input().split()]

n += int(N/(A+B)) * A

amari = N % (A+B)
n += min(amari, A)

print(n)

Buggy submission (verdict: Runtime Error):
n = 0

N, A, B = [int(i) for i in input().split()]

n += int(N/(A+B)) * A

amari = N % (A+B)
n += min(amari, A)

print(n)

Buggy submission (verdict: Runtime Error):
A, B = [int(i) for i in input().split()]

if A<0 or B<0:
    print("-1")
    exit()

minA = int(A/0.08)
maxA = int((A+1)/0.08)
minB = int(B/0.1)
maxB = int((B+1)/0.1)

for i in range(minA, maxA):
    if i >= minB and i < maxB:
        print(i)
        exit()

print("-1")
Problem p02759 (python)

Fixed submission:

a = int(input()) + 1
print(int(a/2))

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

sys.setrecursionlimit(2000)
N, M, K = [int(i) for i in input().split(" ")]

class UnionNode():
    def __init__(self, number):
        self.number = number
        self.volume = 1
        self.master = None

    @property
    def rootnum(self):
        return self.root.number

    @property
    def root(self):
        if self.master:
            return self.master.root
        else:
            return self


    def same(self, target):
        if self.root == target.root:
            return True
        else:
            return False

    def unite(self, target):
        seroot = self.root
        taroot = target.root
        if seroot.number == taroot.number:
            pass
        else:
            #print(f"unite {target.rootnum}({target.root.volume}), {self.rootnum}({self.root.volume})")
            if seroot.number < taroot.number:
                seroot.volume += taroot.volume
                taroot.master = seroot
            else:
                taroot.volume += seroot.volume
                seroot.master = taroot

nodes = [UnionNode(i) for i in range(N)]

outlist = defaultdict(lambda :[])

for i in range(M):
    s = input()
    a, b = s.split(" ")
    a = int(a) - 1
    b = int(b) - 1
    nodes[a].unite(nodes[b])
    outlist[a].append(b)
    outlist[b].append(a)

for i in range(K):
    s = input()
    a, b = s.split(" ")
    a = int(a) - 1
    b = int(b) - 1
    outlist[a].append(b)
    outlist[b].append(a)

result = []
for i in range(N):
    node = nodes[i]
    ret = node.root.volume - 1
    for out in outlist[i]:
        if nodes[out].rootnum == node.rootnum:
            ret -=1
    result.append(ret)

#for i in range(100):
#    print(result[i])

print(" ".join([str(i) for i in result]))
Problem p02792 (python)

Fixed submission:
import math
import time


t = time.time()
def iip():
    ret = [int(i) for i in input().split()]
    if len(ret) == 1:
        return ret[0]
    return ret

def fkc(keta):
    return 10**keta

def pat_b(a, n):
    tail = a % 10

    if tail == 0:
        return 0

    head = int(str(a)[0])

    ret = 0
    if tail == head: #１桁解
        ret += 1

    if n >= tail*10+head: #２桁解は１通りあるかないか
        ret += 1

    for free_keta in range(1, 6): # 3桁以上解
        mincase = 10**(free_keta+1) * tail + head

        if n < mincase:
            break
        if n >= 10**(free_keta+1) + mincase + head - 10:
            ret += fkc(free_keta)
            continue
        else:
            ret += int(int(n-mincase)/10) + 1
    return ret

def main():
    n = iip()
    result = 0
    for i in range(n+1):
        result += pat_b(i, n)
    print(result)


main()

Buggy submission (verdict: Runtime Error):
mod = 10**9 + 7
def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret

n = iip()
A = iip()

def main():
    ss = []
    for a_i in A:
        for s in ss:
            if a_i % s == 0:
                a_i //= s

        ss.extend(soinsuu_bunkai(a_i))

    #print(ss)
    all = 1
    for s in ss:
        all *= s
        all %= mod

    ans = 0
    for a_i in A:
        ans += (all * inv(a_i, mod)) % mod
        ans %= mod
    print(ans)


main()
Problem p02793 (python)

Fixed submission:
mod = 10**9 + 7
def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret

n = iip()
A = iip(listed=True)

def main():
    ss = []
    for a_i in A:
        for s in ss:
            if a_i % s == 0:
                a_i //= s

        ss.extend(soinsuu_bunkai(a_i))

    #print(ss)
    all = 1
    for s in ss:
        all *= s
        all %= mod

    ans = 0
    for a_i in A:
        ans += (all * inv(a_i, mod)) % mod
        ans %= mod
    print(ans)


main()

Buggy submission (verdict: Runtime Error):
mod = 10**9 + 7
def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret

n = iip()
A = iip()

def main():
    ss = []
    for a_i in A:
        for s in ss:
            if a_i % s == 0:
                a_i //= s

        ss.extend(soinsuu_bunkai(a_i))

    #print(ss)
    all = 1
    for s in ss:
        all *= s
        all %= mod

    ans = 0
    for a_i in A:
        ans += (all * inv(a_i, mod)) % mod
        ans %= mod
    print(ans)


main()

Buggy submission (verdict: Runtime Error):
mod = 10**9 + 7
def iip():
    ret = [int(i) for i in input().split()]
    if len(ret) == 1:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret

n = iip()
A = iip()

def main():
    ss = []
    for a_i in A:
        for s in ss:
            if a_i % s == 0:
                a_i //= s

        ss.extend(soinsuu_bunkai(a_i))

    #print(ss)
    all = 1
    for s in ss:
        all *= s
        all %= mod

    ans = 0
    for a_i in A:
        ans += (all * inv(a_i, mod)) % mod
        ans %= mod
    print(ans)


main()
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/K)
Problem p03137 (python)

Fixed submission:
N,M=map(int,input().split())
poti=list(input().split())
poti= [ int(s) for s in poti ]
poti=sorted(poti)
sa=[]
if N>=M:
    print(0)
else:
    for i in range(0,M-1):
        a=poti[i+1]-poti[i]
        sa.append(a)


    if len(sa)!=0:  
        sa=sorted(sa)
        sa=sa[0:(M-1)-(N-1)]
        print(sum(sa))
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
poti=list(input().split())
poti= [ int(s) for s in poti ]
poti=sorted(poti)
sa=[]
for i in range(0,M-1):
    a=poti[i+1]-poti[i]
    sa.append(a)
#print(sa)
if len(sa)!=0:
    while len(sa)!=M-N:
        maxi=max(sa)
        sa.remove(maxi)

    print(sum(sa))

else:
    print(0)
#print(poti)
Problem p03242 (python)

Fixed submission:
a=int(input())
b=1110-a
print(b)

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if a*10+b>b*10+c:
  print(a*10+b+c)
else:
  print(b*10+c+a)

Buggy submission (verdict: Runtime Error):
a=input()
b=1110-a
print(b)

Buggy submission (verdict: Runtime Error):
a=input()
b=a.translate("1":"9","9":"1")
print(b)

Buggy submission (verdict: Runtime Error):
a=str(input())
b=a.replace(1,9)
c=b.replace(9,1)
print(b)

Buggy submission (verdict: Runtime Error):
a=input()
b=a.replace(1,9)
c=b.replace(9,1)
print(b)

Buggy submission (verdict: Runtime Error):
a=input()
b=a.replace((1,9)and(9,1))
print(b)
Problem p02954 (python)

Fixed submission:
S = input()
N = len(S)
ans = [0]*N
r_switch = []
l_switch = []
cur = S[0]
for i, si in enumerate(S):
    if si != cur:
        if cur == "R":
            r_switch.append(i-1)
        else:
            l_switch.append(i-1)
        cur = si

idx = 0
for i, si in enumerate(S):
    if si == "L":
        continue
    swi = r_switch[idx]
    if i >= swi:
        idx += 1
        if idx > len(r_switch):
            break
    if (swi - i) % 2 == 0:
        ans[swi] += 1
    else:
        ans[swi + 1] += 1


idx = -1
for i, si in enumerate(reversed(S)):
    i = N-i-1
    if si == "R":
        continue

    if i <= swi:
        idx -= 1
        if idx < -N:
            break
    swi = r_switch[idx]
    if (i - swi) % 2 == 0:
        ans[swi] += 1
    else:
        ans[swi+1] += 1
print(*ans, sep=" ")

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


def warshall_floyd(matrix):
    """ ワーシャルフロイド
    :param matrix:  隣接行列(到達不能はfloat("inf"))
    :return matrix
    """
    # 到達不能をfloat("inf")にしておけば余計なチェックを入れなくても
    # inf > inf+(-1) のような到達不能＋負辺が繋がってしまうことはない
    V = len(matrix)  # 頂点数
    for i in range(V):
        for j, c2 in enumerate(row[i] for row in matrix):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3  # min(c1, c2+c3)
    return matrix


def init_matrix(V: int):
    """:param V: 頂点数
    """
    return [[float('inf')]*V for _ in range(V)]


H, W = map(int, input().split())
V = 10
matrix = init_matrix(V)
for i in range(10):
    c = map(int, input().split())
    for j, cj in enumerate(c):
        matrix[i][j] = cj

warshall_floyd(matrix)
costs = [matrix[i][1] for i in range(10)]

l = []
for _ in range(H):
    l.extend(list(map(int, input().split())))
c = Counter(l)
ans = 0


for k, v in c.items():
    if k == -1:
        continue
    ans += costs[k]*v
print(ans)
Problem p03054 (python)

Fixed submission:
H,W,N = map(int, input().split())
r,c = map(int, input().split())
S = input()
T = input()

y,x = r,c
# Taka: R, Aoki: L
for si,ti in zip(S,T):
    if si == "R":
        x += 1
    if x > W:
        print("NO")
        exit()
    if ti == "L" and x > 1:
        x -= 1

y,x = r,c
# Taka: L, Aoki: R
for si,ti in zip(S,T):
    if si == "L":
        x -= 1
    if x < 1:
        print("NO")
        exit()
    if ti == "R" and x < W:
        x += 1

y,x = r,c
# Taka: U, Aoki: D
for si,ti in zip(S,T):
    if si == "U":
        y -= 1
    if y < 1:
        print("NO")
        exit()
    if ti == "D" and y < H:
        y += 1

y,x = r,c
# Taka: U, Aoki: D
for si,ti in zip(S,T):
    if si == "D":
        y += 1
    if y > H:
        print("NO")
        exit()
    if ti == "U" and y > 1:
        y -= 1

print("YES")

Buggy submission (verdict: Runtime Error):
H,W,N = map(int, input().split())
sr,sc = map(int, input().split())
S = input()
T = input()

left, right = 0, W+1
if S[-1] == "R":
    right -= 1
elif S[-1] == "L":
    left += 1
for i in reversed(range(N-1)):
    si, ti = S[i], T[i]
    if ti == "R":
        left -= 1
    elif ti == "L":
        right += 1
    left = max(0, left)
    right = min(W+1, right)

    if si == "R":
        right -= 1
    elif si == "L":
        left += 1

    if right - left == 1:
        print("NO")
        exit()

if sc <= left or right <= sc:
    print("NO")
    exit()


left, right = 0, H+1
if S[-1] == "U":
    left += 1
elif S[-1] == "D":
    right -= 1

for i in reversed(range(N-1)):
    si, ti = S[i], T[i]
    if ti == "D":
        left -= 1
    elif ti == "U":
        right += 1
    down = max(0, down)
    up = min(H+1, up)

    if si == "D":
        right -= 1
    elif si == "":
        left += 1

    if right - left == 1:
        print("NO")
        exit()

if sr <= left or right <= sr:
    print("NO")
    exit()

print("YES")
Problem p03209 (python)

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

a,p = [1],[1]
for i in range(N):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

def f(n,x):
    if n==0:
        return 1 if x>=1 else 0
    if x==1:
        return 0
    elif x<=1+a[n-1]:
        return f(n-1, x-1)
    else:
        return p[n-1]+1+f(n-1, x-2-a[n-1])
    
print(f(N,X))

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

a = [1]  # 厚さ
p = [1]  # パティの数
for i in range(N):
    a.append(2*a[-1] + 3)
    p.append(2*p[-1] + 1)


def f(n: int, x: int) -> int:
    """レベルnバーガーの下からx枚のパティの数
    """
    if x == 1:
        return 0 if n > 0 else 1
    elif x <= 1+a[n-1]:
        return f(n-1, x-1)
    elif x == 2 + a[n-1]:
        return p[n-1] + 1
    elif x <= 2*a[n-1] + 2:
        return p[n-1] + 1 + f(n-1, x - (2+a[n-1]))
    elif x == 2*a[n-1] + 3:
        return p[n]
    else:
        raise ValueError(f"xがレベルnバーガーの厚さより大きい, x={x}, n={n}")


if __name__ == "__main__":
    ans = f(N, X)
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
N, X = map(int, input().split())
sys.setrecursionlimit(1_000_000_000)


def dfs(level, idx, cnt_p):
    if X == idx+1:
        return 0
    elif X < 2**(level+1)-3+2:
        return cnt_p + dfs(level-1, idx+1, cnt_p)
    elif X == 2**(level+1)-3+2:
        return 2**(level)-1 + 1
    else:
        return cnt_p + 2**(level)-1 + 1 + dfs(level-1, idx+2**(level+1)-2, cnt_p)


ans = dfs(N, 0, 0)
print(ans)

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
import sys
N, X = map(int, input().split())
sys.setrecursionlimit(1_000_000_000)


@lru_cache(maxsize=1000)
def dfs(level, idx, cnt_p):
    if X == idx+1:
        return 0
    elif X < 2**(level+1)-3+2:
        return cnt_p + dfs(level-1, idx+1, cnt_p)
    elif X == 2**(level+1)-3+2:
        return 2**(level)-1 + 1
    else:
        return cnt_p + 2**(level)-1 + 1 + dfs(level-1, idx+2**(level+1)-2, cnt_p)


ans = dfs(N, 0, 0)
print(ans)
Problem p03326 (python)

Fixed submission:
N,M = map(int, input().split())
xyz = [tuple(map(int, input().split())) for _ in range(N)]

constraint = []
for x,y,z in xyz:
    ci = []
    for b in range(8):
        v = 0
        if (b>>0)&1==1: v += x 
        else: v -= x
        if (b>>1)&1==1: v += y
        else: v -= y
        if (b>>2)&1==1: v += z 
        else: v -= z
        ci.append(v)
    #print(ci)
    constraint.append(ci)

ans = 0
for c in zip(*constraint):
    cond = sorted(c, reverse=True)[:M]
    ans = max(ans, sum(cond))
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
xyz = [tuple(map(int, input().split())) for _ in range(N)]
xs,ys,zs= zip(*xyz)

def calc(t):
    x,y,z = zip(*t)
    return abs(sum(x)) + abs(sum(y)) + abs(sum(z))

cond = []
sx = sorted(xyz, key=lambda x:x[0])
cond.append(calc(sx[:M]))
cond.append(calc(sx[-M:]))
sy = sorted(xyz, key=lambda x:x[1])
cond.append(calc(sy[:M]))
cond.append(calc(sy[-M:]))
sz = sorted(xyz, key=lambda x:x[2])
cond.append(calc(sz[:M]))
cond.append(calc(sz[-M:]))

print(max(cond))
Problem p03634 (python)

Fixed submission:
# D
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N-1):
    ai,bi,ci = map(int, input().split())
    edge[ai-1].append((bi-1, ci))
    edge[bi-1].append((ai-1, ci))
Q,K = map(int, input().split())
K = K-1
x,y = [],[]
for _ in range(Q):
    xi,yi = map(int, input().split())
    x.append(xi-1)
    y.append(yi-1)


dist = [float('inf')]*N # from K
visited = [False]*N
q = [K]
dist[K] = 0
visited[K] = True
while q:
    cur = q.pop()
    visited[cur] = True
    for nex,cost in edge[cur]:
        if not visited[nex]:
            q.append(nex)
            dist[nex] = dist[cur]+cost
#print(dist)
for xi,yi in zip(x,y):
    print(dist[xi] + dist[yi])

Buggy submission (verdict: Runtime Error):
# D
N = int(input())
edge = [[] for _ in range(N)]
for _ in range(N):
    ai,bi,ci = map(int, input().split())
    edge[ai-1].append((bi-1, ci))
    edge[bi-1].append((ai-1, ci))
Q,K = map(int, input().split())
K = K-1
x,y = [],[]
for _ in range(Q):
    xi,yi = map(int, input().split())
    x.append(xi-1)
    y.append(yi-1)


dist = [float('inf')]*N # from K
visited = [False]*N
q = [K]
dist[K] = 0
visited[K] = True
while q:
    cur = q.pop()
    visited[cur] = True
    for nex,cost in edge[cur]:
        if not visited[nex]:
            q.append(nex)
            dist[nex] = dist[cur]+cost
#print(dist)
for xi,yi in zip(x,y):
    print(dist[xi] + dist[yi])
Problem p03776 (python)

Fixed submission:
# D
N,A,B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)

max_mean = sum(v[:A])/A
print(max_mean)

from collections import Counter
from math import factorial

def comb(n,r):
    return factorial(n)//(factorial(r)*factorial(n-r))

v_count = Counter(v)
ans = 0
if v[0]==v[A-1]:
    n = v_count[v[A-1]]
    for r in range(A, B+1):
        if r>n: break
        ans += comb(n, r)
else:
    #print(n, r)
    n = v_count[v[A-1]]
    select_count = Counter(v[:A])
    r = select_count[v[A-1]]
    ans = comb(n,r)
print(ans)

Buggy submission (verdict: Runtime Error):
# D
N,A,B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)

max_mean = sum(v[:A])/A
print(max_mean)

from collections import Counter
from math import factorial

def comb(n,r):
    return factorial(n)//(factorial(r)*factorial(n-r))

v_count = Counter(v)
ans = 0
if v[0]==v[A-1]:
    n = v_count[v[A-1]]
    for r in range(A, B+1):
        if r>n: break
        ans += comb(n, r)
else:
    print(n, r)
    n = v_count[v[A-1]]
    select_count = Counter(v[:A])
    r = select_count[v[A-1]]
    ans = comb(n,r)
print(ans)

Buggy submission (verdict: Runtime Error):
# D
N,A,B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)

max_mean = sum(v[:A])/A
print(max_mean)

from collections import Counter
from math import factorial

def comb(n,r):
    return factorial(n)//(factorial(r)*factorial(n-r))

v_count = Counter(v)
ans = 0
if v[0]==v[A-1]:
    n = v_count[v[A-1]]
    for r in range(A, B+1):
        ans += comb(n, r)
else:
    n = v_count[v[A-1]]
    select_count = Counter(v[:A])
    r = select_count[v[A-1]]
    ans = comb(n,r)
print(ans)