Harryxun/stf_run huggingface dataset:
import numpy as np
import heapq
initial = 10 ** 15

def di(link_costs, s):
    costs = np.full(n, initial)
    costs[s] = 0
    node_list = []
    serched_node = set()
    heapq.heappush(node_list, (0, s))
    
    while(len(node_list) != 0 and len(serched_node) != n):
        index = heapq.heappop(node_list)[1]
        if index in serched_node:
            continue
        serched_node.add(index)
        link = links[index]
        for j in link:
            if j in serched_node:
                continue
        
            cost = link_costs[index][j]
            newcost =  costs[index] + cost
            if newcost < costs[j]:
                costs[j] = newcost
                heapq.heappush(node_list, (newcost, j))
    return costs
    
n, m, s, t  = list(map(int, input().split()))
s -= 1
t -= 1
links = [set() for _ in range(n)]
links_cost_en = np.full((n, n), initial)
links_cost_sn = np.full((n, n), initial)

for _ in range(m):
    u, v, a, b  = list(map(int, input().split()))
    links[u-1].add(v-1)
    links[v-1].add(u-1)
    links_cost_en[u - 1][v - 1] = a
    links_cost_en[v - 1][u - 1] = a
    links_cost_sn[u - 1][v - 1] = b
    links_cost_sn[v - 1][u - 1] = b

cost_en_from_s = di(links_cost_en, s)
cost_sn_to_t = di(links_cost_sn, t)

trans = n - 1
costs = np.full(n, initial)
for i in range(n - 1, -1, -1):
    newcost = cost_en_from_s[i] + cost_sn_to_t[i]
    if newcost < costs[trans]:
        trans = i
        costs[i] = newcost
        continue
    
    costs[i] = costs[trans]
    
for cost in costs:
    print(int(initial - cost))


### FIXED CODE ###

import heapq
initial_cost = 10 ** 9
initial = 10 ** 15

def di(link_costs, s):
    costs = [initial] * n
    costs[s] = 0
    q = []
    heapq.heappush(q, (0, s))
    
    while(len(q) != 0):
        index_cost, index = heapq.heappop(q)
        if costs[index] < index_cost:
            continue

        for j in link_costs[index]:
            newcost = costs[index] + link_costs[index][j]
            if newcost < costs[j]:
                costs[j] = newcost
                heapq.heappush(q, (newcost, j))
    return costs
    
n, m, s, t  = list(map(int, input().split()))
s -= 1
t -= 1
links_cost_en = [{} for _ in range(n)]
links_cost_sn = [{} for _ in range(n)]

for _ in range(m):
    u, v, a, b  = list(map(int, input().split()))
    u -= 1
    v -= 1
    links_cost_en[u][v] = a
    links_cost_en[v][u] = a
    links_cost_sn[u][v] = b
    links_cost_sn[v][u] = b

cost_en_from_s = di(links_cost_en, s)
cost_sn_to_t = di(links_cost_sn, t)
cost_list = [cost_en_from_s[i] + cost_sn_to_t[i] for i in range(n)]

ans = [initial] * n
ans[-1] = cost_list[-1]
for i in list(range(n - 1))[::-1]:
    ans[i] = min(ans[i + 1], cost_list[i])
for i in range(n):
    print(initial - ans[i])
n=int(ibput())
 
r=0
 
for i in range(1,n+1):
	if len(str(i))%2==1:
    	r+=1
print(r)

### FIXED CODE ###

n=int(input())
 
r=0
 
for i in range(1,n+1):
	if len(str(i))%2==1:
		r+=1
print(r)
x,y,z=int(input())
v=0

v=x
x=y
y=v

v=x
x=z
z=v
print(x,y,z)

### FIXED CODE ###

x,y,z=map(int,input().split())
v=0

v=x
x=y
y=v

v=x
x=z
z=v
print(x,y,z)
def divisors(n):
    res = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            res.append(i)
            if i != n // i:
                res.append(n // i)
    return res

n, m = map(int, input().split())
ans = 0
nums = divisors(m)
nums.sort()
num = nums.pop(0)
while num * n <= m:
    if (m - num * n) % num == 0:
        ans = num
    num = nums.pop(0)
print(ans)

### FIXED CODE ###

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

n, m = map(int, input().split())
ans = 0
nums = divisors(m)
nums.sort()
num = nums.pop(0)
while num * n <= m:
    if (m - num * n) % num == 0:
        ans = num
    if nums == []:
        break
    num = nums.pop(0)
print(ans)
N = int(input())
g = [[] for _ in range(N)]
ans = [[] for _ in range(N-1)]

def dfs(v, c=-1, p=-1):
    k = 1
    for i in range(len(g[v])):
        u = g[v][i][0]
        ei = g[v][i][1]
        if u == p:
            continue
        if k == c:
            k += 1
        ans[ei] = k
        k += 1
        dfs(u, ans[ei], v)


for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append((b, i))
    g[b].append((a, i))
dfs(0)
mx = 0
for i in range(N):
    mx = max(mx, len(g[i]))
print(mx)
for i in range(N-1):
    print(ans[i])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
N = int(input())
g = [[] for _ in range(N)]
ans = [0 for _ in range(N-1)]

def dfs(v, c=-1, p=-1):
    k = 1
    for i in range(len(g[v])):
        u = g[v][i][0]
        ei = g[v][i][1]
        if u == p:
            continue
        if k == c:
            k += 1
        ans[ei] = k
        k += 1
        dfs(u, ans[ei], v)


for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append([b, i])
    g[b].append([a, i])
dfs(0)
mx = 0
for i in range(N):
    mx = max(mx, len(g[i]))
print(mx)
for i in range(N-1):
    print(ans[i])
N=int(input())
E=[[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  E[a-1].append((b-1,i))
  E[b-1].append((a-1,i))
ans=[[] for _ in range(N-1)]
visitted=[False for _ in range(N)]
def sub(p, n):
  m=1
  visitted[p]=True
  for a,b in E[p]:
    if not visitted[a]:
      if m == n: m+=1
      ans[b]=m
      sub(a,m)
      m+=1
sub(0,0)
print(max(ans))
for a in ans:
  print(a)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

N=int(input())
E=[[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  E[a-1].append((b-1,i))
ans=[[] for _ in range(N-1)]
def sub(p, n):
  m=1
  for b,i in E[p]:
    if m == n: m+=1
    ans[i]=m
    sub(b,m)
    m+=1
sub(0,0)
print(max(ans))
for a in ans:
  print(a)
N, M = map(int, input().split())
H = list(map(int, input().split()))
ma = [0]*(N+1)
cnt = 0
for _ in range(M):
    a, b = map(int, input().split())
    ma[a] = max(ma[a], H[b-1])
    ma[b] = max(H[a-1], ma[b])
for i in range(1, N+1):
    if H[i] > ma[i]:
        cnt += 1
print(cnt)

### FIXED CODE ###

N, M = map(int, input().split())
H = list(map(int, input().split()))
ma = [0]*(N+1)
cnt = 0
for _ in range(M):
    a, b = map(int, input().split())
    ma[a] = max(ma[a], H[b-1])
    ma[b] = max(H[a-1], ma[b])
for i in range(1, N+1):
    if H[i-1] > ma[i]:
        cnt += 1
print(cnt)
import re
S=input()
if S[0]=="A" and S[2:-1].count("C")==1 and len(re.findall("[A-Z]")):
  print("AC")
else:
  print("WA")


### FIXED CODE ###

import re
S=input()
if S[0]=="A" and S[2:-1].count("C")==1 and len(re.findall("[A-Z]",S))==2:
  print("AC")
else:
  print("WA")
n = int(input())
action = []
for i in range(n):
    action.append(list(map(int,input().split())))

memo = []
for i in range(n):
    memo.append([-1]*3)

def dp(i, a):
    if i == 0:
        return action[0][a]
    else:
        memo[i][a] = max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]
        return memo[i][a]

print(max([dp(n-1,a) for a in range(3)]))

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

n = int(input())
action = []
for i in range(n):
    action.append(list(map(int,input().split())))

memo = []
for i in range(n):
    memo.append([-1]*3)

def dp(i, a):
    if i == 0:
        return action[0][a]
    elif memo[i][a] != -1:
        return memo[i][a]
    else:
        memo[i][a] = max(dp(i-1, (a+1)%3), dp(i-1, (a+2)%3)) + action[i][a]
        return memo[i][a]

print(max([dp(n-1,a) for a in range(3)]))
N=int(input())
A=list(map(int,input().split()))

from functools import lru_cache
@lru_cache(None)

def gcd(x,y):
    if y>x:
        x,y=y,x
    if y==0:
        return x
    else:
        return gcd(y,x-y)

pairwise=True
setwise=True
gcds=[]
for i in range(N):
    for j in range(i+1,N):
        g=gcd(A[i],A[j])
        print(i,j)
        print("gcd:",g)
        if g in gcds:
            setwise=False
        else:
            gcds.append(g)
        print(gcds)
        if g > 1:
            pairwise=False
        if pairwise==False and setwise==False:
            break
    if pairwise==False and setwise==False:
        break
        

if pairwise==True:
    print("pairwise coprime")
elif setwise==True:
    print("setwise coprime")
else:
    print("not coprime")

### FIXED CODE ###

import sys

N=int(input())
A = list(map(int,input().split()))
 
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

if gcd_list(A) > 1:
    print("not coprime")
    sys.exit()

D = [i for i in range(max(A)+1)] #iを割り切る最小の素数を格納
p = 2
 
while(p*p<=max(A)):
    if D[p]==p:
        for i in range(p*p,max(A)+1,p):
            if D[i]==i:
                D[i]=p
 
    p+=1
    
prime = set()
for a in A:
    tmp=D[a]
    L=set()
    while(a>1):
        a=a//tmp
        L.add(tmp)
        tmp=D[a]

    for l in L:
        if l in prime:
            print("setwise coprime")
            sys.exit()
        else:
            prime.add(l)

print("pairwise coprime")
A, B, C, K = map(float, input().split())

if A>K:
    print(K)
elif (A+B)>=K:
    print(A)
else:
    print(A-(K-A-B))


### FIXED CODE ###

S = input()
T = input()

if S == T[:len(T)-1]:
    print("Yes")
else:
    print("No")
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def comb(a,b):
        return f[a]*inv[b]*inv[a-b]%mod
    r1,c1,r2,c2 = LI()
    N = 2*10**6
    f = [1]
    for i in range(N):
        f.append(f[-1]*(i+1)%mod)
    inv = [None]*(N+1)
    inv[-1] = pow(f[-1],mod-2,mod)
    for i in range(N)[::-1]:
        inv[i] = inv[i+1]*(i+1)%mod
    ans = 0
    for i in range(r1,r2+1):
        s = 0
        ans += comb(i+1+c2,i+1)-comb(i+c1,i+1)
        ans %= mod
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


### FIXED CODE ###

#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def comb(a,b):
        return f[a]*inv[b]*inv[a-b]%mod
    r1,c1,r2,c2 = LI()
    N = 3*10**6
    f = [1]
    for i in range(N):
        f.append(f[-1]*(i+1)%mod)
    inv = [None]*(N+1)
    inv[-1] = pow(f[-1],mod-2,mod)
    for i in range(N)[::-1]:
        inv[i] = inv[i+1]*(i+1)%mod
    ans = 0
    for i in range(r1,r2+1):
        s = 0
        ans += comb(i+1+c2,i+1)-comb(i+c1,i+1)
        ans %= mod
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()
import sys
X, Y = map(int, input().split())

for x in range(0, X+1):
    if 2 * x + 4 * (X-x) == Y:
        print('Yes')
        sys.exit()
print('No'

### FIXED CODE ###

import sys
X, Y = map(int, input().split())

for x in range(0, X+1):
    if 2 * x + 4 * (X-x) == Y:
        print('Yes')
        sys.exit()
print('No')
from fractions import gcd
n, m = map(int, input().split())
a = list(map(int, input().split()))

def lcm(a, b):
    return a*b // gcd(a, b)
"""
akが偶数だから、bk=2akとして、
bk × (2p + 1)を満たすpが存在すれば良い
2p+1は奇数のため、Xとbkの2の素因数は一致しなければならない
akに含まれる最大の2^kを探す。
"""
lcm_all = lcm(a[0]//2, a[1]//2)
amax = 0
for i in range(1, n):
    lcm_all = lcm(lcm_all, a[i]//2)
    amax = max(amax, a[i]//2)

f = True
if lcm_all > m:
    f = False
for i in range(n):
    if (lcm_all//(a[i]//2))%2 == 0:
        # akの2の約数の数がそろわないので、どんな奇数を掛けても共通のXを作れない
        f = False
if f:
    # amaxの奇数倍でmを超えないもの
    ans = (m // lcm_all + 1)//2
    print(ans)
else:
    print(0)

### FIXED CODE ###

from fractions import gcd
n, m = map(int, input().split())
a = list(map(int, input().split()))

def lcm(a, b):
    return a*b // gcd(a, b)
"""
akが偶数だから、bk=2akとして、
bk × (2p + 1)を満たすpが存在すれば良い
2p+1は奇数のため、Xとbkの2の素因数は一致しなければならない
akに含まれる最大の2^kを探す。
"""
if len(a) == 1: lcm_all = a[0]//2
else: lcm_all = lcm(a[0]//2, a[1]//2)
amax = 0
for i in range(1, n):
    lcm_all = lcm(lcm_all, a[i]//2)
    amax = max(amax, a[i]//2)

f = True
if lcm_all > m:
    f = False
for i in range(n):
    if n == 1: break
    if (lcm_all//(a[i]//2))%2 == 0:
        # akの2の約数の数がそろわないので、どんな奇数を掛けても共通のXを作れない
        f = False
if f:
    # amaxの奇数倍でmを超えないもの
    ans = (m // lcm_all + 1)//2
    print(ans)
else:
    print(0)
N,a,b = map(int,input().split())

if (b-a)%2 ==0:
  ams = (b-a)//2
else:
  ans = min(a-1,N-b)+1 + (b-a-1)//2
print(ans)

### FIXED CODE ###

N,a,b = map(int,input().split())

if (b-a)%2 ==0:
  ans = (b-a)//2
else:
  ans = min(a-1,N-b)+1 + (b-a-1)//2
print(ans)
N,K = map(int,input().split())
X = list(map(int,input().split()))
res = 10**10
for i in range(N-K+1):
    if X[i]*X[i+K-1] >= 0:
        res = min(res,max(abs(X[i+K-1],X[i])))
    else:
        res = min(res,abs(X[i])*2+X[i+K-1],X[i+K-1]*2+abs(X[i]))
print(res)

### FIXED CODE ###

n,k = map(int,input().split())
X = list(map(int,input().split()))
S = []
for i in range(n-k+1):
	if X[i]*X[i+k-1] < 0:
		S.append(X[i+k-1]-X[i]+min(abs(X[i+k-1]),abs(X[i])))
	else:
		S.append(max(abs(X[i+k-1]),abs(X[i])))
print(min(S))
N = int(input())
a = [int(input()) for i in range(N)]
A = max(a)
for i in range(len(a)):
    if i == a.index(A):
        print(sorted(set(a))[-2])
    else:
        print(A)

### FIXED CODE ###

N = int(input())
a = [int(input()) for i in range(N)]
A = max(a)
b = sorted(a)[-2]
if a.count(A) > 1:
    for i in range(len(a)):
        print(A)
else:
    for i in range(len(a)):
        if a[i] == A:
            print(b)
        else:
            print(A)
S = input()
T = input()

count = 0
for i in range(len(S)):
	if S[i] != T[i]:
		count = count + 1

print(count)

### FIXED CODE ###

a = int(input())

print(a + a * a  + a * a * a)
#デフォルト
import itertools
from collections import defaultdict
import collections
import math
import sys
sys.setrecursionlimit(200000)
mod = 1000000007

n = int(input())
a = list(map(int, input().split()))

a.sort(reverse=True)
ans = 0

for i in range(n):
    for j in range(n):
        if a[i] % a[n - j - 1] == 0 and i != n - j - 1:
            break
        if j == n - 1:
            ans += 1

print(ans)

### FIXED CODE ###

#デフォルト
import itertools
from collections import defaultdict
import collections
import math
import sys
sys.setrecursionlimit(200000)
mod = 1000000007

x = list(map(int,input().split()))

for i in range(5):
    if x[i] != i + 1:
        print(i+1)
        break
import math

N = int(input())
ans = 0
sqi = math.sqrt(N)
for i in range(1, int(sqi)+1):
    if (N-i)%i == 0:
        m = (N-1)//i
        if N//m == N%m:
        	ans += (N-i)//i
print(ans)

### FIXED CODE ###

import math

N = int(input())
ans = 0
ms = set()
sqi = math.sqrt(N)
for i in range(1, int(sqi)+1):
    if N % i == 0:
        ms.add(i-1)
        ms.add(N//i-1)
for m in ms:
    if m <= 0:
        continue
    if N//m == N%m:
        ans += m
print(ans)
li = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = input()
print(li[k-1])

### FIXED CODE ###

li = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(li[k-1])
import sys
sys.setrecursionlimit(10**9)

def main():
    A,B,N = map(int,input().split())

    def f(x):
        return math.floor((A*x)/B) - A * math.floor(x/B)

    def bin(a):
        left = 0
        right = A+1

        while right-left > 1:
            x = (right+left) // 2
            # print(left,right)
            if f(x) < a:
                left = x
            else:
                right = x

        # print("____")
        # print(right)
        return right


    for _a in range(A+1):
        a = A - _a
        x = bin(a)
        # print(x,a)
        if 0<=x<=N and f(x) == a:
            print(a)
            exit()


if __name__ == "__main__":
  main()


### FIXED CODE ###

import sys
import math
sys.setrecursionlimit(10**9)

def main():
    A,B,N = map(int,input().split())

    def f(x):
        return math.floor((A*x)/B) - A * math.floor(x/B)
	
    print(f(min(B-1,N)))


if __name__ == "__main__":
  main()
X = int(input())
K = int(input())
D = int(input())
loc = 0
lis = []

def calucu_min(X,K,D):
    for num in range(K) :
        lis.append( abs(abs(2 *D *num -K *D) - abs(X)))
        lis_unique = set(lis)
        print (max(lis_unique))

calucu_min(X,K,D)

### FIXED CODE ###

S = input()
li = list(S)
count = 0
re_num = 0
for num in range(3):
    if li[num] == "R" :
        count = count + 1

if count == 0 :
    re_num = 0
elif count == 1 :
    re_num = 1
elif count == 2 and li[1] == "S" :
    re_num = 1
elif count == 2 and li[1] == "R" :
    re_num = 2
else :
    re_num = 3

print(re_num)
N = int(input())
A = list(map(int, input().split()))
sum=0
for i in range(N-1):
  if A[i] < A[i+1]:
    continue
  else:
    sa = A[i]-A[i+1]+1
    A[i+1]=A[i]+1
    sum += sa
print(sa)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
sum=0
sa=0
for i in range(N-1):
  if A[i] <= A[i+1]:
    continue
  else:
    sa = A[i]-A[i+1]
    A[i+1]=A[i]
    sum += sa
print(sum)
input = open('file.txt').readline

    
n = int( input() )
arr = list( map( int , input().strip().split(" ") ) )

dp = [ 0 for i in range(n) ]

for i in range(1,n):

    #one jump
    cost1 = abs(arr[i] - arr[i-1]) + dp[i-1] 
    cost2 = cost1 + 2
    # two jump
    if i != 1:
        cost2 = abs(arr[i] - arr[i-2]) + dp[i-2]

    dp[i] = min( cost1  ,cost2 )

print(dp[n-1])

### FIXED CODE ###

    
n = int( input() )
arr = list( map( int , input().strip().split(" ") ) )

dp = [ 0 for i in range(n) ]

for i in range(1,n):

    #one jump
    cost1 = abs(arr[i] - arr[i-1]) + dp[i-1] 
    cost2 = cost1 + 2
    # two jump
    if i != 1:
        cost2 = abs(arr[i] - arr[i-2]) + dp[i-2]

    dp[i] = min( cost1  ,cost2 )

print(dp[n-1])
# -*- coding: utf-8 -*-
import sys

args = sys.argv
num = args[1] * 100 + args[2] * 10 + args[3]
if num % 4 == 0:
    print('YES')
else:
    print('NO')


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys

x = input()
num = int(''.join(x.split()))
if num % 4 == 0:
    print('YES')
else:
    print('NO')
from collections import deque
import math
    
def dfs(edges, s):
    stack = deque([s])
    used  = {s}
    while stack:
        x = stack.pop()
        for y in edges[x]:
            if y not in used:
                used.add(y)
                stack.append(y)
    return used


def bfs(edges, s):
    queue = deque([s])
    used  = {s}
    while queue:
        x = queue.popleft()
        for y in edges[x]:
            if y in used:
                continue
            used.add(y)
            queue.append(y)
    return used
    

def bellman(dist):  #負辺があるケースでの、スタートからゴールへの最短路を求めるアルゴ。
    cost = [math.inf] * n
    cost[0] = 0
    for _ in range(n): #頂点の個数の分だけ回る
        updated = False
        for u,v,c in dist: #辺の個数の分だけ回る
            if cost[u] + c < cost[v]:
                cost[v] = cost[u] + c
                updated = True                
    #収束しない場合は負閉路があるため無限に小さくできる。
    if updated==True:
        return -1
    else:
        return max(0, cost[n-1]*-1)    
        

n,m,p = map(int, input().split())
dist  = []
edge1 = [[] for _ in range(n)]
edge2 = [[] for _ in range(n)]  # rev_edge
for _ in range(m):
    u,v,c = map(int, input().split())
    u -= 1
    v -= 1
    dist.append((u,v,(c-p)*-1))
    edge1[u].append(v)
    edge2[v].append(u)    
    
use = dfs(edge1, 0) & dfs(edge2, n-1)
dist2 = [(a,b,c) for a,b,c in dist if a in use and b in use]
print(bellman(dist2))

### FIXED CODE ###

from collections import deque
import math
    
def dfs(edges, s):
    stack = deque([s])
    used  = {s}
    while stack:
        x = stack.pop()
        for y in edges[x]:
            if y not in used:
                used.add(y)
                stack.append(y)
    return used


def bfs(edges, s):
    queue = deque([s])
    used  = {s}
    while queue:
        x = queue.popleft()
        for y in edges[x]:
            if y in used:
                continue
            used.add(y)
            queue.append(y)
    return used
    

def bellman(dist):  #負辺があるケースでの、スタートからゴールへの最短路を求めるアルゴ。
    cost = [float("inf")] * n
    cost[0] = 0
    for _ in range(n): #頂点の個数の分だけ回る
        updated = False
        for u,v,c in dist: #辺の個数の分だけ回る
            if cost[u] + c < cost[v]:
                cost[v] = cost[u] + c
                updated = True                
    #収束しない場合は負閉路があるため無限に小さくできる。
    if updated==True:
        return -1
    else:
        return max(0, cost[n-1]*-1)    
        

n,m,p = map(int, input().split())
dist  = []
edge1 = [[] for _ in range(n)]
edge2 = [[] for _ in range(n)]  # rev_edge
for _ in range(m):
    u,v,c = map(int, input().split())
    u -= 1
    v -= 1
    dist.append((u,v,(c-p)*-1))
    edge1[u].append(v)
    edge2[v].append(u)    
    
use = dfs(edge1, 0) & dfs(edge2, n-1)
dist2 = [(a,b,c) for a,b,c in dist if a in use and b in use]
print(bellman(dist2))
N = int(input())
A = list(map(int,input().split()))
import fractions
def lcm(a):
    x = a[0]
    for i in range(1,len(a)):
        x = (x*a[i])//fractions.gcd(x,a[i])
        return x
A_lcm = lcm(A)
ans = 0
for i in A:
    ans += (A_lcm//i)%mod
print(ans%mod)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
import fractions
mod = 10**9+7
lcm = A[0]
for i in range(1,N):
    lcm = lcm*A[i]//fractions.gcd(lcm,A[i])
ans = 0
for i in range(N):
    ans += lcm*pow(A[i],mod-2,mod)
print(ans%mod)
from collections import deque
n, m, r = map(int,input().split())
R = list(map(int, input().split()))
tree = [[] for _ in range(n+1)]
for i in range(m):
    a, b, c = map(int, input().split())
    tree[a].append([b, c])
    tree[b].append([a, c])

result = [10**9]
for i in R:
    visit = [-1 for _ in range(n+1)]
    visit[i] = 0
    q = deque([[i, visit.copy()]])
    while q:
        x, v = q.pop()
        for y, c in tree[x]:
            next_v = v.copy()
            if v[y]<0:
                next_v[y] = v[x]+c
                if all(next_v[j]>=0 for j in R):
                    result.append(next_v[y])
                else:
                    q.append([y, next_v.copy()])

print(min(result))

### FIXED CODE ###

import copy
from collections import deque
n, m, r = map(int,input().split())
R = list(map(int, input().split()))

f_inf = float('inf')
wf = [[f_inf for _ in range(n+1)] for __ in range(n+1)]

tree = [[] for _ in range(n+1)]
for i in range(m):
    a, b, c = map(int, input().split())
    wf[a][b] = c
    wf[b][a] = c
for i in range(1, n+1):
    wf[i][i] = 0
for k in range(1, n+1):
    for i in range(1, n+1):
        for j in range(1, n+1):
            wf[i][j] = min(wf[i][j], wf[i][k]+wf[k][j])

all_type = []
def get_all_type(r, info, lon):
    if lon == len(info):
        return [info]
    result = []
    for i in r:
        if i in info:
            continue
        else:
            next_info = copy.deepcopy(info)
            next_info.append(i)
            result.extend(get_all_type(r, next_info, lon))
    return result

Result = []
for i in get_all_type(R, [], r):
    j = deque(i)
    x = j.popleft()
    result = 0
    while j:
        y = j.popleft()
        result += wf[x][y]
        x = y
    Result.append(result)
print(min(Result))