Harryxun/stf_run huggingface dataset:
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b//gcd(a,b)
n,m=map(int,input().split())
s=input()
t=input()
n,m=max(n,m),min(n,m)
l=lcm(n,m)
d=[set() for i in range(l)]
f=l
for i in range(n):
    d[i*(l//n)].add(s[i])
for i in range(m):
    d[i*(l//m)].add(t[i])
for i in range(l):
    if len(d[i])==2: f=-1
print(f)

### FIXED CODE ###

def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b//gcd(a,b)
n,m=map(int,input().split())
s=input()
t=input()
l=lcm(n,m)
d={}
f=l
for i in range(max(n,m)):
    o=i*(l//n)
    p=i*(l//m)
    if i<n and o not in d:
        d[o]=s[i]
    elif i<n and o in d and d[o]!=s[i]:
        f=-1
    if i<m and p not in d:
        d[p]=t[i]
    elif i<m and p in d and d[p]!=t[i]:
        f=-1
print(f)
x=r()
print(360/x)

### FIXED CODE ###

import math

x=int(input())
print(360//math.gcd(x,360))
from bisect import bisect_left
INFTY = 10**5
P = [1 for _ in range(INFTY)]
P[0]=0
P[1]=0
for i in range(2,int(INFTY**0.5)+1):
    for j in range(i*i,INFTY,i):
        P[j] = 0
Q = []
for i in range(INFTY):
    if P[i]==1:
        Q.append(i)
X = int(input())
ind = bisect_left(Q,X)
print(Q[ind])

### FIXED CODE ###

from bisect import bisect_left
INFTY = 10**5+10
P = [1 for _ in range(INFTY)]
P[0]=0
P[1]=0
for i in range(2,int(INFTY**0.5)+1):
    for j in range(i*i,INFTY,i):
        P[j] = 0
Q = []
for i in range(INFTY):
    if P[i]==1:
        Q.append(i)
X = int(input())
ind = bisect_left(Q,X)
print(Q[ind])
K, S = map(int,input())
print(S//K)

### FIXED CODE ###

K, S = map(int,input().split())
ans = 0
for i in range(K+1):
    for j in range(K+1):
            if 0 <= S - i - j <= K:
                ans += 1
print(ans)
n, k = map(int, input().split())
pb = 0

for i in range(1, n):
  mul = 0
  
  while k > i * 2** mul:
    mul += 1
    
  pb += (0.5 ** mu) / n
print(pb)

### FIXED CODE ###

n, k = map(int, input().split())
pb = 0
 
for i in range(1, n+1):
  mul = 0
  
  while k > i * (2 ** mul):
    mul += 1
    
  pb += 1/(n*(2**mul))
print(pb)
A, B = map(int, input().split())
S = input()
C = "1234567890"
if S[A] == "-":
  for i in range(len(S)):
    if i != A-1:
      if A[i] in C:
        continue
      else:
        print("No")
        exit()
else:
  print("No")

### FIXED CODE ###

def resolve():
    A, B = map(int, input().split())
    S = input()
    C = "1234567890"
    for i in range(A):
        if S[i] in C:
            continue
        else:
            print("No")
            exit()
    if S[A] != "-":
        print("No")
        exit()
    for i in range(A+1, len(S)):
        if S[i] in C:
            continue
        else:
            print("No")
            exit()
    print("Yes")
resolve()
import sys
sys.setrecursionlimit(10**6)

N, K = map(int, input().split())
P = list(map(int,input().split()))
out_ = 0
p = P[0:K]
base = sum(p)
for i in range(N-K):
  out_ += P[i+K]-P[i]
  if i == 0:
    ans = out_
  else:
    if out_ > ans:
      ans = out_
    else:
      continue
answer = (base+ans+K)/2
print(answer)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

N, K = map(int, input().split())
P = list(map(int,input().split()))
out_ = 0
p = P[0:K]
base = sum(p)
if N == K:
  answer = (sum(p)+K)/2
else:
  for i in range(N-K):
    out_ += P[i+K]-P[i]
    if i == 0:
      ans = out_
    else:
      if out_ > ans:
        ans = out_
      else:
        continue
  answer = (base+ans+K)/2
print(answer)
import collections
from collections import OrderedDict

#入力
N = int(input())
S = [input() for i in range(N)]

#出現回数のカウント
c = collections.Counter(S)
c_val = list(c.values())
c_key = list(c.keys())

"""
print(c)
print(c_val)
print(c_key)
"""

#多い順に並べ替えた辞書をつくる
c_sorted = OrderedDict(sorted(c.items(), key = lambda x : x[1], reverse=True))
c_sorted_val = list(c_sorted.values())
c_sorted_key = list(c_sorted.keys())

"""
print(c_sorted)
print(c_sorted_val)
print(c_sorted_key)
"""

#回数が多いものを抜き出したリストの制作
c_max = list(c_sorted_key[0])

i=1
if len(c_val)>1:
    while c_val[i-1]==c_val[i]:
        c_max.append(c_key[i])
        i+=1
        if i==len(c_max):
            break

"""
print(c_max)
"""

#keyを降順に並べ替え
c_max.sort()

"""
print(c_max)
print(c_max[0])
"""

#表示
i=0
while i!=len(c_max):
    print(c_max[i])
    i+=1

### FIXED CODE ###

import collections
from collections import OrderedDict

#入力
N = int(input())
S = [input() for i in range(N)]

#出現回数のカウント
c = OrderedDict(collections.Counter(S))
ln = len(c.values())

#多い順に並べ替えた辞書をつくる
d = OrderedDict(sorted(c.items(), key = lambda x : x[1], reverse=True))
dval = list(d.values())
dkey = list(d.keys())

#回数が多い単語を抜き出したリストの制作
word = list()
word.append(dkey[0])
i=1
if ln>1:
    while dval[i-1]==dval[i]:
        word.append(dkey[i])
        i+=1
        if i==ln:
            break

#辞書順に並べ替える
dic = sorted(word)

#表示
for i in range(len(dic)):
    print(dic[i])
from itertools import accumulate as ac
n=int(input())
a,b=[],[]
for i in range(n):
    x,s=map(int,input().split())
    a.append(x)
    b.append(s)
r=[0]+list(ac(b))
l=b[:]
for i in range(n):
    r[i]+=-a[i]
    l[i+1]+=-a[i]
q,d=0,0
for i in range(1,n+1):
    d=max(l[i]-q,d)
    q=min(q,r[i-1])
print(d)

### FIXED CODE ###

from itertools import accumulate as ac
n=int(input())
a,b=[],[]
for i in range(n):
    x,s=map(int,input().split())
    a.append(x)
    b.append(s)
r=[0]+list(ac(b))
l=r[:]
for i in range(n):
    r[i]+=-a[i]
    l[i+1]+=-a[i]
q,d=r[0],0
for i in range(1,n+1):
    d=max(l[i]-q,d)
    q=min(q,r[i])
print(d)
from sys import stdin
import math
a, b = map(int,stdin.readline().split())
gcd = math.gcd(a,b)
lcm = (a*b)/gcd
print(lcm)

### FIXED CODE ###

a, b = map(int,input().split())
for i in range(1,b+1):
  if (a*i) % b == 0:
    print(a*i)
    break
n = int(input())
a = list(map(int,input().split()))
b = [a.count(i+1) for i in range(n)]
d = []
for j in b:
    if j >= 2:
        d.append(factorial(j)//factorial(2)//factorial(j-2))
    else:
        d.append(0)

for k in a:
    if b[k-1] >= 3:
        u = b[k-1] 
        p = factorial(u-1)//factorial(2)//factorial(u-3)
        print(sum(d)-d[k-1]+p)
    else:
        print(sum(d)-d[k-1])

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
num = [0]*(n+1)
s = 0
for i in a:
    num[i] += 1
for i in num:
    s += i*(i-1)//2
for i in range(n):
    print(s-num[a[i]]+1)
N=int(input())
def sq(n):
    c=0
    A=[0 for j in range(n**2)]
    for i in range(n//2):
        for j in range(i**2,(i+1)**2):
            A[j]=i
    return A
A=sq(N)[0:N+1]
print(A)
for n in range(1,N+1):
    c=0
    for x in range(1,A[n]):
        for y in range(1,A[n-x**2]):
            for z in range(1,A[n-x**2-y**2]):
                if n==x**2+y**2+z**2+x*y+y*z+z*x:
                    c=c+1
    print(c)


### FIXED CODE ###

N=int(input())
def sq(n):
    c=0
    A=[0 for j in range(n+1)]
    for i in range(n//2):
        p=(i+1)**2
        if p>n:
            for j in range(i**2,n+1):
                A[j]=i
            break
        else:
            for j in range(i**2,p):
                A[j]=i
    return A
A=sq(N)
a=A[N]
L=[0 for j in range(N+1)]
for x in range(1,a+1):
    for y in range(1,a+1):
        for z in range(1,a+1):
            p=x**2+y**2+z**2+x*y+y*z+z*x
            if p<=N:
                L[p]=L[p]+1
            else:
                break
for i in range(1,N+1):
    print(L[i])
from itertools import accumulate
import numpy as np
N=int(input())
L=[26**(i+1) for i in range(10)]
sL=list(accumulate(L))
result=[]
for i in range(10):
    if N<=sL[i]:
        N-=sL[i-1]
        k=i
        break
for m in range(k):
    time=0
    while N>=L[k-m-1]:
        N-=L[k-m-1]
        time+=1
    result.append(chr(time+97))
result.append(chr(N+96))
print(''.join(result))

### FIXED CODE ###

from itertools import accumulate
import numpy as np
N=int(input())
N-=1
L=[26**(i+1) for i in range(15)]
sL=list(accumulate(L))
result=[]
k=0
for i in range(15):
    if N+1<=sL[i] and N>=25:
        N-=sL[i-1]
        k=i
        break
for m in range(k):
    time=0
    while N>=L[k-m-1]:
        N-=L[k-m-1]
        time+=1
    result.append(chr(time+97))
result.append(chr(N+97))
print(''.join(result))
class unionFind:
    def __init__(self, n):
        self.data = [-1] * (n+10)

    def find(self, x):
        if self.data[x]>=0: return self.find(self.data[x])
        else: return x

    def unite(self, x, y):
        a, b = self.find(x), self.find(y)
        if a!=b:
            self.data[b] += self.data[a]
            self.data[a] = b


n, m = map(int, input().split())
p = list(map(int, input().split()))

tree = unionFind(n)
for i in range(m):
    x, y = map(int, input().split())
    tree.unite(p[x-1], p[y-1])

ans = 0
for i in range(n):
    if tree.find(i+1)==tree.find(p[i]): ans += 1
print(ans)

### FIXED CODE ###

class unionFind:
    def __init__(self, n):
        self.data = [-1] * (n+10)

    def find(self, x):
        if self.data[x]>=0:
            self.data[x] = self.find(self.data[x])
            return self.data[x]
        else: return x

    def unite(self, x, y):
        a, b = self.find(x), self.find(y)
        if a!=b:
            self.data[b] += self.data[a]
            self.data[a] = b


n, m = map(int, input().split())
p = list(map(int, input().split()))

tree = unionFind(n)
for i in range(m):
    x, y = map(int, input().split())
    tree.unite(p[x-1], p[y-1])

ans = 0
for i in range(n):
    if tree.find(i+1)==tree.find(p[i]): ans += 1
print(ans)
s = int(input())
t = int(input())
count = 0
for i in range(len(s)):
    if s[i] == t[i]:
        count += 1
        
print(count)

### FIXED CODE ###

s = list(input())
t = list(input())
count = 0
for i in range(len(s)):
    if s[i] == t[i]:
        count += 1

print(count)
n = int(input())
s = input()

count = 0

for i in range(n):
    if s[i] == "A":
        if s[i+1] == "B":
            if s[i+2] == "C":
                count += 1
            else:
                continue
        else:
            continue
    else:
        continue

print(count)

### FIXED CODE ###

n = int(input())
s = input()

count = 0

for i in range(n-2):
    if s[i] == "A":
        if s[i+1] == "B":
            if s[i+2] == "C":
                count += 1

print(count)
n = int(input())
s = input()
k = int(input())
s_list = list(s) 
for i in range(0 , n) :
    if s_list[i] == s_list[k] :
        s_list[i] = "*"
print(s_list)


### FIXED CODE ###

a ,b ,c = map(int,input().split())
if a > c> b or b > c > a :
    print("Yes")
else :
    print("No")
import sys
sys.setrecursionlimit(10000000)


def gcd(aa, b):
    if b == 0:
        return aa
    return gcd(b, aa % b)


mod = 1e9 + 7
n = int(input())
a = [int(i) for i in input().split()]
kek = 1
for i in range(n):
    kek = (kek * a[i]) // gcd(kek, a[i])
s = 0
for i in range(n):
    s += kek / a[i]
print(int(s % mod))




### FIXED CODE ###

import sys
sys.setrecursionlimit(10000000)


def gcd(aa, b):
    if b == 0:
        return aa
    return gcd(b, aa % b)


mod = int(1e9 + 7)
n = int(input())
a = [int(i) for i in input().split()]
kek = 1
for i in range(n):
    kek = (kek * a[i]) // gcd(kek, a[i])
s = 0
for i in range(n):
    s += kek // a[i]
print(int(s % mod))
ln=10
bit=[0]*ln

def up(id):
    while id<ln:
        bit[id]+=1
        id+=id&(-id)
def qr(id):
    res=0
    while id:
        res+=bit[id]
        id-=id&(-id)
    return res

res=0

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

st=sorted(list(set(s)),reverse=True)
dc={}
id=1
for n in st:
    dc[n]=id
    id+=1


for n in range(x):
    up(dc[s[n]])
    p=qr(dc[s[n]])
    #print(p)
    res+=int(p!=0)
    

print(res)

### FIXED CODE ###

def readinput():
    n=int(input())
    p=list(map(int,input().split()))
    return n,p

def main(n,p):
    count=0
    pmin=p[0]
    for i in range(n):
        pmin=min(p[i],pmin)
        if pmin>=p[i]:
            count+=1
    return count

if __name__=='__main__':
    n,p=readinput()
    ans=main(n,p)
    print(ans)
import math
pi=math.pi()
r=int(input())
len=2*pi*r
return len

### FIXED CODE ###

import math
pi=math.pi
r=int(input())
len=2*pi*r
print(len)
W = input().rstrip()
text = ""
while True:
    line = input().rstrip()
    text += line if line == "END_OF_TEXTS": break
print(text.count(W))


### FIXED CODE ###

W = input().rstrip()
lst = []
while True:
    line = input().rstrip()
    if line == "END_OF_TEXT":
        break
    lst += line.lower().split()
print(lst.count(W))
X=map(int,input().split())
print(max(X)-min(X))

### FIXED CODE ###

X=list(map(int,input().split()))
print(max(X)-min(X))
import numpy as np
a,b = input().split()
np.trunc((a+b)/2)

### FIXED CODE ###

import numpy as np
a,b = input().split()
print(int(np.ceil((int(a)+int(b))/2)))
s=input()
if s[0]==s[1] or s[1]==s[2] or s[2]==s[3] or s[3]==s[4]:
    print("bad")
else:
    print("good")

### FIXED CODE ###

s=input()
if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
    print("Bad")
else:
    print("Good")
A,B,C,X,Y=map(int,input().split())

P=X*A+B*Y
if X>Y:
    Q=C*2*Y+(X-Y)*A
    L=X*2*C
elif Y<X:
    Q=C*2*Y+(Y-X)*B
    L=Y*2*C
elif X==Y:
    Q=min(C*2*Y, C*2*X)
    L=min(X*2*C, Y*2*C)



print(min(P,Q,L))

### FIXED CODE ###

A,B,C,X,Y=map(int,input().split())

K=10**9
for i in range(10**5+1):
    S=i*2*C+max(0,X-i)*A+max(0,Y-i)*B
    K=min(K,S)
print(K)
from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
#from functools import lru_cache   #use @lru_cache(None)
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')
#
def input(): return sys.stdin.readline()
def mapi(arg=0): return map(int if arg==0 else str,input().split())
#------------------------------------------------------------------


n,k = mapi()
a = [0]+list(mapi())
gr = defaultdict(int)
for i in range(1,n+1):
    gr[i]=a[i]

vis ={}
path = []
p = 1
def dfs(s):
    global p
    if s in vis:
        p = s
        return
    path.append(s)
    vis[s] = 1
    dfs(gr[s])
dfs(1)
i = 0
ln = 0
path2 = path[:]
while i<len(path):
    if p==path[i]:
        path2 = path2[i:]
        break
    i+=1
#print(path)
if k<len(path)-len(path2):
    print(path[k])
else:
    k -= len(path)-len(path2)
    print(path2[k%len(path2)])
#print(dfs(1,k))


### FIXED CODE ###

from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
#from functools import lru_cache   #use @lru_cache(None)
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')
#
def input(): return sys.stdin.readline()
def mapi(arg=0): return map(int if arg==0 else str,input().split())
#------------------------------------------------------------------
import sys
sys.setrecursionlimit(10**6)
from types import GeneratorType
#use:- put @bootstrap overrecursive function
def bootstrap(func, stack=[]):
    def wrapped_function(*args, **kwargs):
        if stack:
            return func(*args, **kwargs)
        else:
            call = func(*args, **kwargs)
            while True:
                if type(call) is GeneratorType:
                    stack.append(call)
                    call = next(call)
                else:
                    stack.pop()
                    if not stack:
                        break
                    call = stack[-1].send(call)
            return call
    return wrapped_function


n,k = mapi()
a = [0]+list(mapi())
gr = defaultdict(int)
for i in range(1,n+1):
    gr[i]=a[i]

vis ={}
path = []
p = 1

@bootstrap
def dfs(s):
    global p
    if s in vis:
        p = s
        yield 0
    path.append(s)
    vis[s] = 1
    res =0
    res+= yield dfs(gr[s])
    yield res
dfs(1)
i = 0
ln = 0
path2 = path[:]
while i<len(path):
    if p==path[i]:
        path2 = path2[i:]
        break
    i+=1
#print(path)
if k<len(path)-len(path2):
    print(path[k])
else:
    k -= len(path)-len(path2)
    print(path2[k%len(path2)])
#print(dfs(1,k))
def solve(n):
    for i in range(n+1):
        if (i+1)*i//2 > n:
            return i-1

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr



N = int(input())
li = factorization(N)
ans = 0
for [a,b] in li:
    ans += solve(b)
print(ans)

### FIXED CODE ###

def solve(n):
    for i in range(n+2):
        if (i+1)*i//2 > n:
            return i-1

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])


    return arr



N = int(input())
li = factorization(N)
ans = 0
for [a,b] in li:
    ans += solve(b)
    
if ans == 0:
    if N != 1:
        ans += 1
print(ans)
a=int(input())
b=0;
if a==3:
  b=1
elif a==5:
  b=1:
elif a==7:
  b=1:
if b==1:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

print('YES' if int(input()) in [3,5,7] else 'NO')
n = int(input())
array = [int(input()) for i in range(n)]
def shift_only(array):
    tmp = []
    counter = 0
    while True:
        flag = True
        # 全て偶数かを確認
        for num in array:
            if num%2 != 0:
                flag = False
        if flag == False:
            break
        array = [i/2 for i in array]
        counter +=1
    print(counter)
shift_only(array)

### FIXED CODE ###

def shift_only(array):
    tmp = []
    counter = 0
    while True:
        flag = True
        # 全て偶数かを確認
        for num in array:
            if num%2 != 0:
                flag = False
        if flag == False:
            break
        array = [i/2 for i in array]
        counter +=1
    print(counter)
    
n = int(input())
a = list(map(int, input().split()))
shift_only(a)
def main():
    inputs = input()

    roop_num = len(inputs)
    if roop_num >= 1000000000
        cnt = 0

    else:
        cnt = 0
        flag = False
        for start in range(roop_num-3):
            roop_num_end = roop_num - start
            ans_list = []
            ans_list = [int(inputs[start:end+start+4]) for end in range(roop_num_end-3) if int(inputs[start:end+start+4]) % 2019 == 0]

            cnt += len(ans_list)

        print(cnt)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    inputs = input().split(' ')
    sheep = int(inputs[0])
    wolf = int(inputs[1])

    if sheep > wolf:
        print('safe')

    else:
        print('unsafe')

if __name__ == '__main__':
    main()
s = raw_input()
n = len(s)
a = 0
b = 0
for i in range(n):
	if ((i%2 == 0) and (s[i] == '0')):
		a += 1
	if ((i%2 == 1) and (s[i] == '1')):
		a += 1
	if ((i%2 == 0) and (s[i] == '1')):
		b += 1
	if ((i%2 == 1) and (s[i] == '0')):
		b += 1
print(min(a,b))


### FIXED CODE ###

s = input()
n = len(s)
a = 0
b = 0
for i in range(n):
	if ((i%2 == 0) and (s[i] == '0')):
		a += 1
	if ((i%2 == 1) and (s[i] == '1')):
		a += 1
	if ((i%2 == 0) and (s[i] == '1')):
		b += 1
	if ((i%2 == 1) and (s[i] == '0')):
		b += 1
print(min(a,b))
N=int(input())
for _ in[0]*N:
 r=[0]*N
 for i in input().split()[2:]:a[int(i)-1]=1
 print(*a)


### FIXED CODE ###

N=int(input())
for _ in[0]*N:
 r=[0]*N
 for i in input().split()[2:]:r[int(i)-1]=1
 print(*r)
K = int(input())

A = list(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)

Print(A[K-1])

### FIXED CODE ###

K = int(input())

A = [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]

print(A[K-1])
x = int(N**(0.5))
if(N%x == 0):
  print(N)
else:
  print((int(N**(0.5))-1)**2)

### FIXED CODE ###

N = int(input())

x = N**(0.5)
if(N%x == 0):
  print(N)
else:
  print(int(x)**2)
n,m=map(int,input().split())
x=sorted(list(map(int,input().split())))
if n<=m:
  print(0)
else:
  d=[]
  for j in range(n-1):
    d.append(x[i+1]-x[i])
  d=sorted(d)
  print(sum(d[:m]))

### FIXED CODE ###

n,m=map(int,input().split())
x=sorted(list(map(int,input().split())))
if m<=n:
  print(0)
else:
  d=[]
  for i in range(m-1):
    d.append(x[i+1]-x[i])
  d=sorted(d)
  print(sum(d[:m-n]))
N = int(input())
tree = [[] for _ in range(N)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    tree[a-1].append([b-1, c])
    tree[b-1].append([a-1, c])
Q, K = map(int, input().split())

dist = [-1] * N
def dfs(v, total_cost):
    # v：頂点, total_cost：今までかかったコストの合計
    dist[v] = total_cost
    for v_next, cost in tree[v]:
        if dist[v_next] >= 0:
            continue
            # v_nextが訪問済みならスキップ
        dfs(v_next, total_cost+cost)

dfs(K-1, 0)

for i in range(Q):
    x, y = map(int, input().split())
    print(dist[x-1] + dist[y-1])


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

N = int(input())
tree = [[] for _ in range(N)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    tree[a-1].append([b-1, c])
    tree[b-1].append([a-1, c])
Q, K = map(int, input().split())

dist = [-1] * N
def dfs(v, total_cost):
    # v：頂点, total_cost：今までかかったコストの合計
    dist[v] = total_cost
    for v_next, cost in tree[v]:
        if dist[v_next] >= 0:
            continue
            # v_nextが訪問済みならスキップ
        dfs(v_next, total_cost+cost)

dfs(K-1, 0)

for i in range(Q):
    x, y = map(int, input().split())
    print(dist[x-1] + dist[y-1])
from collections import Counter
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
n, p = map(int, input().split())
c = Counter(prime_factorize(p))
ans = 1
for i in c.most_common():
    ans *= i[0] ** (i[1] // n)
print(ans)

### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
a.sort()
ans = -2 * sum(a[:n // 2])
if n % 2 == 0:
    ans += 2 * sum(a[n // 2:]) + a[n // 2 - 1] - a[n // 2]
else:
    ans += 2 * sum(a[n // 2 + 1:]) + max(a[n // 2 - 1] - a[n // 2], a[n // 2] - a[n // 2 + 1])
print(ans)
n = int(input())
A, B = np.zeros(n), np.zeros(n)
for i in range(n):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

### FIXED CODE ###

n = int(input())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(n-1, -1, -1):
    if (A[i]+ans) % B[i] == 0:
        continue
    else:
        ans += B[i] - (A[i]+ans) % B[i]
print(ans)
# Hello World program in Python
import math
def lcm(a, b):
    return abs(a*b) // math.gcd(a, b)
N = int(raw_input())
A = map(int, raw_input().split())
l = 1
for x in A:
    l = lcm(l, x)
ans, mod = 0, 1000000007
for x in A:
    ans = (ans + l/x) % MOD
print(ans)


### FIXED CODE ###

def gcd(a,b):
    if not b: return a
    return gcd(b,a%b)

def lcm(a, b):
    return (a*b)//gcd(a, b)

N = int(input())
A = list(map(int,input().split()))
l = 1
ans, mod = 0, 1000000007

for x in A:
    l = lcm(l, x)

for x in A:
    ans = ans + l//x
print(ans % mod)