Harryxun/stf_run huggingface dataset:
a,b,c,d = map(int, iput().split())

if a+b+c+d == 7:
  print('{}+{}+{}+{}=7'.format(a,b,c,d))
elif a+b+c-d == 7:
  print('{}+{}+{}-{}=7'.format(a,b,c,d))
elif a+b-c+d == 7:
  print('{}+{}-{}+{}=7'.format(a,b,c,d))
elif a-b-c-d == 7:
  print('{}-{}-{}-{}=7'.format(a,b,c,d))
  
elif a-b+c+d == 7:
  print('{}-{}+{}+{}=7'.format(a,b,c,d))
elif a-b+c-d == 7:
  print('{}-{}+{}-{}=7'.format(a,b,c,d))
elif a-b-c+d == 7:
  print('{}-{}-{}+{}=7'.format(a,b,c,d))
elif a-b-c-d == 7:
  print('{}-{}-{}-{}=7'.format(a,b,c,d))

### FIXED CODE ###

a,b,c,d = (int(i) for i in input())
 
if a+b+c+d == 7:
  print('{}+{}+{}+{}=7'.format(a,b,c,d))
elif a+b+c-d == 7:
  print('{}+{}+{}-{}=7'.format(a,b,c,d))
elif a+b-c+d == 7:
  print('{}+{}-{}+{}=7'.format(a,b,c,d))
elif a+b-c-d == 7:
  print('{}+{}-{}-{}=7'.format(a,b,c,d))
  
elif a-b+c+d == 7:
  print('{}-{}+{}+{}=7'.format(a,b,c,d))
elif a-b+c-d == 7:
  print('{}-{}+{}-{}=7'.format(a,b,c,d))
elif a-b-c+d == 7:
  print('{}-{}-{}+{}=7'.format(a,b,c,d))
elif a-b-c-d == 7:
  print('{}-{}-{}-{}=7'.format(a,b,c,d))
d = int(input("Digite um numero sendo ele 0, 1 ou 2"))
n = int(input("Digite um numero de 0 a 100"))

if (d == 0):
    x = 1
    y = 0
    n0 = []
    while ( x <= n ):
        n0.append(y)
        x = x + 1
        y = y + 1
    print(n0[-1])
elif (d == 1):
    x = 1
    y = 100
    n1 = []
    while (x <= n ):
        n1.append(y)
        x = x + 1
        y = y + 100
    print(n1[-1])
elif (d == 2):
    x = 1
    y = 1000
    n2 = []
    while (x <= n):
        n2.append(y)
        x = x + 1
        y = y + 1000
    print(n2[-1])

### FIXED CODE ###

d,n = map(int,input().split())
for i in range (n):
    ans=100 ** d * (i+1)
if n==100:
    ans+=100 ** d
print(ans)
n=int(input())
a=list(map(int,input().split()))

ans=1

if 0 in a:
    print(0)
    exit()

for i in a:
   ans*=i
   if ans>10**18:
    print(-1)
    exit()


print(ans)

### FIXED CODE ###

a, b = map(int, input().split())
print(a*b);
def resolve():
    def main():
        N, M = map(int, input().split())
        S, C = [0] * M, [0] * M

        if N == 1 and M == 1:
            return 0
        elif N == 2 and M == 0:
            return 10
        elif N == 3 and M == 0:
            return 100

        for i in range(M):
            S[i], C[i] = map(int, input().split())
            if i == 0:
                dic = {S[i]: C[i]}
            else:
                if S[i] not in dic.keys():
                    dic[S[i]] = C[i]
                elif dic[S[i]] != C[i]:
                    return -1

        ans = [0] * N
        for i, j in dic.items():
            ans[i - 1] = j

        if len(ans) != 1 and ans[0] == 0:
            return -1
        else:
            return ans

    val = main()
    try:
        int(val)
        print(val)
    except:
        for i in val:
            print(i, end='')
        print()


resolve()

### FIXED CODE ###

N,M=map(int,input().split())
s=[list(map(int,input().split())) for i in range(M)]

#print(A)
def main():
    if N==1 and M==0:
        return 0
    if N==2 and M==0:
        return 10
    if N==3 and M==0:
        return 100

        
    if N==1:
        for i in range(0,10**N):
            for j in range(M):
                if str(i)[s[j][0]-1]!=str(s[j][1]):
                    break
                if j==M-1:
                    return i
            if i==10**N-1:
                return -1
    else:
        for i in range(10**(N-1),10**N):
            for j in range(M):
                if str(i)[s[j][0]-1]!=str(s[j][1]):
                    break
                if j==M-1:
                    return i
            if i==10**N-1:
                return -1
                    

print(main())
import sys
import numpy as numpy
input = sys.stdin.readline

N,M = map(int,input().split())
XY = [[] for i in range(N)]

path = [-1] * N

for i in range(N):
  x,y = map(int,input().split())
  XY[x - 1].append(y - 1)

  
def recur(n):
  if path[n] != -1:
    return path[n]
  else:
    ret = 0
    for chi in XY[n]:
      ret = max(ret,recur(chi) + 1)
    
    path[n] = ret
    return path[n]
    
recur(0)

print(max(path))

### FIXED CODE ###

import sys
import numpy as numpy
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 5)

N,M = map(int,input().split())
XY = [[] for i in range(N + 1)]

path = [-1] * (N + 1)

for i in range(M):
  x,y = map(int,input().split())
  XY[x - 1].append(y - 1)

  
def recur(n):
  if path[n] != -1:
    return path[n]
  
  elif XY[n] == []:
    path[n] = 0
    return path[n]
        
  else:
    ret = 0
    for chi in XY[n]:
      ret = max(ret,recur(chi) + 1)
    
    path[n] = ret
    return path[n]
    
for i in range(N):
  recur(i)

print(max(path))
n = int(input())
b = list(map(int, input().split()))

a = []

a.append(b[0])

for i in range(1, n-1):
  if b[i-1] <= b[i]:
    a.append(b[i-1])
  elif b[i] <= b[i+1]:
    a.append(b[i+1])
a.append(b[-1])
print(sum(a))

### FIXED CODE ###

n = int(input())

print(n**3)
from collections import Counter
n, *A = map(int, open(0).read().split())

a0 = Counter(A[::2]).most_common(2)
a1 = Counter(A[1::2]).most_common(2)

count = n
if a0[0][0] == a1[0][0]:
    count -= max(a0[1][1] + a1[0][1], a0[0][1] + a1[1][1])
else:
    count -= a0[0][1] + a1[0][1]
print(count)

### FIXED CODE ###

from collections import Counter
n, *A = map(int, open(0).read().split())

a0 = Counter(A[::2]).most_common(2)
a1 = Counter(A[1::2]).most_common(2)

count = n
if a0[0][0] == a1[0][0]:
    if len(a0) == len(a1) == 1:
        count -= n//2
    elif len(a0) < len(a1):
        count -= n//2 - a1[1][1]
    elif len(a0) > len(a1):
        count -= n//2 - a0[1][1]
    else:
        count -= max(a0[1][1] + a1[0][1], a0[0][1] + a1[1][1])
else:
    count -= a0[0][1] + a1[0][1]
print(count)
A, B = int(input())
count = 0
for i in range(A, B+1):
    if i == i[::-1]:
        count += 1
print(count)

### FIXED CODE ###

A, B = map(int, input().split())
a = 0
for i in range(A, B+1):
    i = str(i)
    if i == i[::-1]:
        a += 1
print(a)
s = input()
k = int(input())
s_list = []
for i in range(len(s)):
  s_list.append(s[i:i+k])
s_list = sorted(list(set(s_list)))
if len(s_list[0]) == k:
  print(s_list[0])
else:
  n = len(s_list[0]) + len(s_list[1])
  if n == k:
    print(s_list[2][0])
  elif n < k:
    print(s_list[2][0:k-n+1])
  else:
    print(s_list[1][0:n-k+1])

### FIXED CODE ###

s = input()
k = int(input())
s_list = []
for i in range(len(s)):
  for j in range(k):
    s_list.append(s[i:i+j+1])
s_list = sorted(list(set(s_list)))
print(s_list[k-1])
import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

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

def resolve():
    readline=sys.stdin.readline

    
    a,b=map(int, readline().rstrip().split())
    memo = [0] * (10**6 + 1)
    af = factorization(a)
    bf = factorization(b)
    for x in af:
        memo[x[0]]+=1
    for x in bf:
        memo[x[0]]+=1
    print(memo.count(2)+1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### FIXED CODE ###

### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
import collections

def yn(b):
    print("Yes" if b==1 else "No")
    return

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

def resolve():
    readline=sys.stdin.readline
    a,b=map(int, readline().rstrip().split())

    af = factorization(a)
    bf = factorization(b)

    c = collections.Counter()
    c[1]=2
    for x in af:
        c[x[0]]+=1
    for x in bf:
        c[x[0]]+=1
    ans=0
    for k in c.keys():
        if c[k]>=2:
            ans+=1
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------
import sys
input = sys.stdin.readline
import math

def Main(N, K, h):
    dp = [math.inf]*N
    dp[0] = 0
    for i in range(N):
        for j in range(1, min(N-i,K+1)):
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]))
    return dp[N-1]

def main():
    N, K = map(int, input().split())
    h = list(map(int, input().split()))
    print(Main(N, K, h))

if __name__ == '__main__':
    main()

### FIXED CODE ###

N, K = map(int, input().split())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	for j in range(1, min(K + 1, N - i)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])
A, B, C = map(int, raw_input())

if B + C <= 100:
    print('YES')
else:
    print('NO')


### FIXED CODE ###

import sys

A, B, C = map(int, raw_input().split())

for i in range(1, 101):
    if C == 0 and (B * i % A) == 0 or \
            (C % A) == 0 and (B * i % A) == 0 or \
            (B * i % A) != 0 and (C % A) % (B * i % A) == 0:
        print('YES')
        sys.exit()

print('NO')
line = input().rstrip().split(' ')

fst_point = int(line[0]) * 10 + int(line[1])
sec_point = int(line[1]) * 10 + int(line[2])

if fst_point >= sec_point:
    return print(fst_point + int(line[2]))
else:
    return print(sec_point + int(line[0]))
  

### FIXED CODE ###

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

max_lines = [[x * 10 + y, z],
                 [x * 10 + z, y],
                 [y * 10 + x, z],
                 [y * 10 + z, x],
                 [z * 10 + x, y],
                 [z * 10 + y, x]]

max_point = 0
one_point = 0
for max_line in max_lines:
    if max_line[0] >= max_point:
        max_point = max_line[0]
        one_point = max_line[1]

print(max_point + one_point)
N = int(input())

ans = {}
for i in range(N):
    ans.add(input())

print(len(ans))

### FIXED CODE ###

N = int(input())

ans = set()
for i in range(N):
    ans.add(input())

print(len(ans))
i=input().split()
print(i[0]/i[1])

### FIXED CODE ###

a,b=map(int,input().split())
print(a/b)
import collections
n=int(input())
A=list(map(int,input().split()))
x=0
lst=[]
for i in range(n):
    x+=A[i]
    lst.append(x)
c=collections.Counter(lst)

 
def conv(n,m):
    if n==m or m==0:
        return 1
    else:
        return conv(n-1,m-1)+conv(n-1,m)
ans=0
for k in c.keys():
    if c[k]==0:
        continue
    if c[k]==1:
        if k==0:
            ans+=1
        else:
            continue
    elif k==0:
        ans+=c[k]+conv(c[k],2)
    else:
        ans+=conv(c[k],2)
print(ans)

### FIXED CODE ###

import collections
n=int(input())
A=list(map(int,input().split()))
x=0
lst=[]
for i in range(n):
    x+=A[i]
    lst.append(x)
c=collections.Counter(lst)

 
def conv(n,m):
    if n==m or m==0:
        return 1
    else:
        return conv(n-1,m-1)+conv(n-1,m)
ans=0
for k in c.keys():
    if c[k]==1:
        if k==0:
            ans+=1
        else:
            continue
    elif k==0:
        ans+=c[k]+int(c[k]*(c[k]-1)/2)
    else:
        ans+=int(c[k]*(c[k]-1)/2)
print(ans)
n = map(int, input())
print(n // 3)

### FIXED CODE ###

n = int(input())
print(n // 3)
N = int(input())
H = list(map(int,input().split()))
cnt = 0
for i in range(N-2):
    if H[i+1]-H[i]<0 and H[i+2]-H[i+1]<0:
        cnt = 1
        break
    elif H[i+1]-H[i]<-1:
        cnt = 1
        break
for j in range(N-3):
    if H[i+1]-H[i]<0 and H[i+2]-H[i+1] == 0 and H[i+3]-H[i+2]<0:
        cnt = 1
        break
if cnt >0:
  print('No')
else:
  print('Yes')
N = int(input())
H = list(map(int,input().split()))
cnt = 0
for i in range(N-2):
    if H[i+1]-H[i]<=0 and H[i+2]-H[i+1]<0:
        cnt = 1
        break
    elif H[i+1]-H[i]<-1:
        cnt = 1
        break
if cnt >0:
  print('No')
else:
  print('Yes')


### FIXED CODE ###

N = int(input())
H = list(map(int,input().split()))
H.reverse()
cnt = 0
for i in range(N-1):
  if H[i+1]-H[i]==1:
    H[i+1] = H[i+1]-1
  elif H[i+1]-H[i]>1:
    cnt = 1
    break
if cnt == 0:
  print('Yes')
else:
  print('No')
option = int(input())
ref_t, tmp_id = int(input().split())
height = list((int(n) for n in input().split()))

ave_t = []
for i in range(option):
  ave_t.append(abs(tmp_id - (ref_t - height[i] * 0.06)))

print(ave_t.index(min(ave_t)) + 1)

### FIXED CODE ###

option = int(input())
ref_t, tmp_id = (int(n) for n in input().split())
height = list((int(n) for n in input().split()))

ave_t = []
for i in range(option):
  ave_t.append(abs(tmp_id - (ref_t - height[i] * 0.006)))

print(ave_t.index(min(ave_t)) + 1)
a=input()
if a<1000:
	print('ABC')
else:
	print('ABD')

### FIXED CODE ###

a=int(input())
if a<1000:
	print('ABC')
else:
	print('ABD')
n = input()
total = 0
for i in range(len(n)):
  total += int(n[i])
if total % 9 == 0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

n, x, t = map(int, input().split())
if n % x == 0:
  print(int(n/x*t))
else:
  print(int((n//x+1)*t))
n = input()
N = input()
if n in N: 
  print("Yes")
else: 
  print("No"

### FIXED CODE ###

S = input()
T = input()
if T[:-1] == S:
    print("Yes")
else:
    print("No")
import math 

x = int(input())
a = []
for i in range(1,x):
  for j in range(2,32):
    if math.log(i,j).is_integer() == True:
      a.append(i)
print(max(a))

### FIXED CODE ###

x = int(input())
a = []
for i in range(1,32):
  for j in range(2,9):
    if i ** j <= x:
      a.append(i**j)
print(max(a))
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

s = ins()
t = ins()
oa = ord('a')
ls = len(s)
nxt = [[-1]*26 for i in range(ls)]
nx = [-1]*26
for i in range(2*ls-1,-1,-1):
    c = ord(s[i%ls])-oa
    for j in range(26):
        if i<ls and nx[j]>=0:
            nxt[i][j] = nx[j]-i
    nx[c] = i
if DBG:
    for i in range(ls):
        printn(f"{i} ")
        print(nxt[i])
cur = 0
for i in range(len(t)):
    c = ord(t[i])-oa
    nx = nxt[cur%ls][c]
    if nx<0:
        print(-1)
        exit()
    cur += nx
print(cur+1)


### FIXED CODE ###

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

s = ins()
t = ins()
oa = ord('a')
ls = len(s)
nxt = [[-1]*26 for i in range(ls)]
nx = [-1]*26
for i in range(2*ls-1,-1,-1):
    c = ord(s[i%ls])-oa
    for j in range(26):
        if i<ls and nx[j]>=0:
            nxt[i][j] = nx[j]-i
    nx[c] = i
if DBG:
    for i in range(ls):
        #printn(f"{i} ")
        print(nxt[i])

prevpos = nxt[ls-1][ord(t[0])-oa]-1
if prevpos<0:
    print(-1)
    exit()
for i in range(1,len(t)):
    c = ord(t[i])-oa
    nx = nxt[prevpos%ls][c]
    if nx<0:
        print(-1)
        exit()
    prevpos += nx
    #ddprint(f"i {i} pp {prevpos} c {c} ti {t[i]}")
print(prevpos+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,K=map(int,input().split())
L=factorization(N)
ans=1
for i in L:
  ans*=L[0]**(L[1]//N)
print(ans)

### FIXED CODE ###

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,K=map(int,input().split())
L=factorization(K)
ans=1
for i in L:
  ans*=i[0]**(i[1]//N)
print(ans)
import heapq
N, M = [int(_) for _ in input().split()]
H = [-int(_) for _ in input().split()]
heapq.heapify(H)
ans = 0
for _ in range(M):
    a = heapq.heappop(H)
    heapq.heappush(H, a / 2)
print(-sum(int(a) for a in H))


### FIXED CODE ###

weather = ['Sunny','Cloudy','Rainy']
N = input()
if N == weather[0]:
  print(weather[1])
elif N == weather[1]:
  print(weather[2])
else:
  print(weather[0])
import statistics
import math


def main():
    n = int(input())
    x = list(map(int, input().split()))

    c = 0
    t = 0
    for i in range(n-1):
        c += 1/(i+1)
        t += c * (x[i+1]-x[i])
        t %= 10**9+7

    print(int(t * math.factorial(n-1) % (10**9+7)))


main()


### FIXED CODE ###

import statistics
import math

MOD = 10**9+7


def main():
    n = int(input())
    x = list(map(int, input().split()))

    c = 0
    t = 0
    for i in range(n-1):
        c += pow(i+1, MOD-2, MOD)
        t += c * (x[i+1]-x[i])
        t %= MOD

    fact = math.factorial(n-1) % MOD
    print(t * fact % MOD)


main()
# -*- coding: utf-8 -*-

import numpy as np

s = input()

x = np.base_repr(int(s), 26)

strings = {
"1": "a",
"2": "b",
"3": "c",
"4": "d",
"5": "e",
"6": "f",
"7": "g",
"8": "h",
"9": "i",
"A": "j",
"B": "k",
"C": "l",
"D": "m",
"E": "n",
"F": "o",
"G": "p",
"H": "q",
"I": "r",
"J": "s",
"K": "t",
"L": "u",
"M": "v",
"N": "w",
"O": "x",
"P": "y",
"Q": "z"
}

r = ''
for i in list(x):
    r += strings[i]

print(x, r)


### FIXED CODE ###

# -*- coding: utf-8 -*-

n = int(input())

r = ''

def to_moji(x: int):
    if x == 0:
        x = 26
    return chr(96 + x)

def devide(x, moji):
    a = x // 26
    b = x % 26

    if b == 0:
        a -= 1

    if a < 1:
        moji = to_moji(b) + moji
        return moji
    elif 1 <= a and a <= 26:
        moji = to_moji(b) + moji
        moji = to_moji(a) + moji
        return moji
    else:
        moji = to_moji(b) + moji
        return devide(a, moji)

print(devide(n, r))
s = input()
t = input()

s1 = s.sort()
t1 = t.sort(reserve = True)

if s1 < t1:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

s = sorted((input()))
t = sorted((input()), reverse=True)

if s<t:
    print('Yes')
else:
    print('No')
h, k = map(int, input().split())
lis = list(map(int, input().split()))
for i in range(k):
    lis.remove(max(lis))
    
print(sum(lis))

### FIXED CODE ###

h, k = map(int, input().split())
lis = list(map(int, input().split()))
if h >= k:
    lis.sort(reverse=True)
    lis = lis[k:]
else:
    lis = []
    
print(sum(lis))
n, a, b = map(int, input().split())
x = 0

for i in range(1:n+1):
  q = i
  w = i / 10
  e = i / 100
  r = i / 1000
  sum = q + w + e + r
  if sum >= a and sum <= b:
    x += 1
    
print(x)

### FIXED CODE ###

n, a, b = map(int, input().split())
x = 0

for i in range(1, n+1):
  q = i // 10000
  qi = i % 10000
  w = qi // 1000
  wi = qi % 1000
  e = wi // 100
  ei = wi % 100
  r = ei // 10
  ri = ei % 10
  t = ri
  sum = q + w + e + r + t
  if sum >= a and sum <= b:
    x += i
    
print(x)
from itertools import permutations

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

allp = p.copy()
allp.sort()
allperms = list(map(list, permutations(allp)))
print(abs(allperms.index(p) - allperms.index(q))) 

### FIXED CODE ###

from itertools import permutations

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

allp = p.copy()
allp.sort()
allperms = list(map(list, permutations(allp)))
print(abs(allperms.index(p) - allperms.index(q)))
from collections import deque

N=int(input())
a=[0]*(N-1)
b=[0]*(N-1)
c=[0]*(N-1)
L=[ [] for _ in range(N)]
for i in range(N-1):
  a[i],b[i],c[i]= map(int,input().split())
  L[a[i]-1].append((b[i]-1,c[i]))
  L[b[i]-1].append((a[i]-1,c[i]))
Q,K= map(int,input().split())
         
#Lの中のitemの0は接続先、1は距離

d=[ -1 for i in range(N)]

def BFS(x):
  v=deque([x])
  d[x]=0
  
  while len(v)>0:
    s=v.popleft() #sはint
    for item in L[s]:
      if d[item[0]]==-1:
        d[item[0]]=d[s]+item[1]
        v.append(item[0])
BFS(K-1)

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

### FIXED CODE ###

from collections import deque

N=int(input())
a=[0]*(N-1)
b=[0]*(N-1)
c=[0]*(N-1)
L=[ [] for _ in range(N)]
for i in range(N-1):
  a[i],b[i],c[i]= map(int,input().split())
  L[a[i]-1].append((b[i]-1,c[i]))
  L[b[i]-1].append((a[i]-1,c[i]))
Q,K= map(int,input().split())
         
#Lの中のitemの0は接続先、1は距離

d=[ -1 for i in range(N)]

def BFS(x):
  v=deque([x])
  d[x]=0
  
  while len(v)>0:
    s=v.popleft() #sはint
    for item in L[s]:
      if d[item[0]]==-1:
        d[item[0]]=d[s]+item[1]
        v.append(item[0])
BFS(K-1)

x=[0]*Q
y=[0]*Q
for i in range(Q):
  x[i],y[i] = map(int,input().split())
  print(d[x[i]-1]+d[y[i]-1])
n = int(input())
A = input().split(' ')

for i in range(1, n-1):
    v = A[i]
    j = i - 1
    while j >= 0 && A[j] > v:
        A[j+1] = A[j]
        j--
        A[j+1] = v
    print(" ".join(A))

### FIXED CODE ###

n = int(input())
A = input().split(' ')

#for i in range(n):
#    A[i] = int(A[i])
print(" ".join(A))

for i in range(1, n):
    v = A[i]
    j = i - 1

    while j >= 0 and int(A[j]) > int(v):
        A[j+1] = A[j]
        A[j] = v
        j -= 1
    print(" ".join(A))
a = input()
A = int(a)
b = input()
B = int(b)
c = A * B
print(c)

### FIXED CODE ###

A, B = input().strip().split()
A, B = [int(A), int(B)]
print(A * B)
t = int(input())
a = list(map(int, input().split()))

if t == 1:
    print(0)
elif t == 2:
    print(abs(a[0] - a[1]))

else:

    dp[0] = 0
    dp[1] = abs(a[0] - a[1])
    for i in range(2, t):
        dp[i] = min(abs(a[i] - a[i - 1]) + dp[i - 1],
                    abs(a[i] - a[i - 2]) + dp[i - 2])

    print(dp[t - 1])


### FIXED CODE ###

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

dp = [0] * n
dp[1] = abs(arr[1] - arr[0])

for i in range(1, n - 1):
    dp[i + 1] = min(dp[i - 1] + abs(arr[i + 1] - arr[i - 1]), dp[i] + abs(arr[i + 1] - arr[i]))

print(dp[-1])
def solution(n, k, l_list):
    l_list.sort(reverse=True)
    result = sum(l_list[:k])
    return result


N, K = [int(value) for value in input().split(' ')]
l_list = [int(value) for value in input().split(' ')]
print(solution(N, K, l_list))

### FIXED CODE ###

def solution(a, b):
    total = a + b
    if total % 3 == 0:
        print('Possible')
    elif a % 3 == 0:
        print('Possible')
    elif b % 3 == 0:
        print('Possible')
    else:
        print('Impossible')

A, B = input().split(' ')
A, B = int(A), int(B)

solution(A, B)
import math
n = int(input())
print(int(2*n / math.gcd(2,n)))


### FIXED CODE ###

import fractions
n = int(input())
print(int(2*n / fractions.gcd(2,n)))