Harryxun/stf_run huggingface dataset:
n = int(input())
a = list(map(int,input().split()))
cnt = 0
while a != []:
    id = 1
    if a[0] == a[1]:
        while a[id-1] == a[id]:
            id += 1
        del(a[:id-1])
        id = 1

    if a[0] > a[1]:
        while a[id-1] >= a[id] and id < len(a)-1:
            id += 1
    elif a[0] < a[1]:
        while a[id-1] <= a[id] and id < len(a)-1:
            id += 1
    cnt += 1
    if id ==len(a)-1:break 
    del(a[:id])

    if len(a)==1:
        cnt += 1
        break
print(cnt)


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
cnt = 0
id = 1
while a != []:
    if len(a)==1:
        cnt += 1
        break
    if a[0] == a[1]:
        while a[id-1] == a[id] and id <= len(a)-1:
            id += 1
            if id == len(a):break
        if id == n:
            cnt = 1
            break
        del(a[:id-1])
        id = 1
    if a[0] > a[1]:
        while  a[id-1] >= a[id] and id <= len(a)-1:
            id += 1
            if id == len(a):break
    elif a[0] < a[1]:
        while a[id-1] <= a[id] and id <= len(a)-1:
            id += 1
            if id == len(a):break
    cnt += 1
    del(a[:id])
    id = 1


print(cnt)
import numpy as np
while True:
    try:
        a,b,c,d,e,f = (int(i) for i in input().split())
        x,y = [np.dot(np.linalg.inv(np.array([[a,b],[d,e]])),np.array([c,f]))[0],np.dot(np.linalg.inv(np.array([[a,b],[d,e]])),np.array([c,f]))[1]]
        print(x,y)
    except EOFError:
        break

### FIXED CODE ###

while True:
    try:
        a,b,c,d,e,f = (int(i) for i in input().split())
        det=a*e-b*d
        x = (c*e-b*f)/det
        y = (a*f-c*d)/det
        if x==0:x=0
        if y==0:y=0
        print("{0:.3f} {1:.3f}".format(x,y))
    except EOFError:
        break
in = input()

print('%s %s %s' % (in[2],in[0],in[1]))

### FIXED CODE ###

x = input().split()

print('%s %s %s' % (x[2],x[0],x[1]))
#ABC076A

r=int(raw_input())
d=int(raw_input())
print g*2-r


### FIXED CODE ###

#ABC076A

r=int(raw_input())
g=int(raw_input())
print g*2-r
A = input()
B = input()

if A == 1 and B == 2:
    print(3)
elif A == 2 and B == 1:
    print(3):
elif A == 1 and B == 3:
    print(2)
elif A == 3 and B == 1:
    print(2)
else:
    print(1)

### FIXED CODE ###

A = int(input())
B = int(input())

if A == 1 and B == 2:
    print(3)
elif A == 2 and B == 1:
    print(3)
elif A == 1 and B == 3:
    print(2)
elif A == 3 and B == 1:
    print(2)
else:
    print(1)
INF = float('inf')
from collections import defaultdict
from heapq import heappop, heappush

class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, From, To, cost=1):
        self.graph[From].append((To,cost))

    def get_nodes(self):
        return self.graph.keys()

class Dijkstra(object):

    def __init__(self, graph, start):
        self.g = graph.graph
        self.dist = defaultdict(lambda:INF)
        self.dist[start] = 0
        self.prev = defaultdict(lambda: None)
        self.Q = []
        heappush(self.Q,(self.dist[start], start))

        while  self.Q:
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, cost in self.g[u]:
                alt = dist_u + cost
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q,(alt, v))

    def shortest_distance(self, goal):
        return self.dist[goal]

    def shortest_path(self, goal):
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]

        return path[::-1]




N, M = map(int,input().split())
g = Graph()

for i in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    g.add_edge(a,b)
    g.add_edge(a,b+N)
    g.add_edge(a+N,b)

ans = -1
for i in range(N):
    d = Dijkstra(g,i)
    if d.dist[i+N] != INF:
        path = d.shortest_path(i+N)
        path = path[:-1]
        path = [node%N for node in path]
        if len(path) == len(set(path)):
            ans = path
            break

if ans != -1:
    print(len(ans))
    for i in range(len(ans)):
        print(ans[i]+1)
else:
    print(ans)

d[i].shortest_path(i+N)



### FIXED CODE ###

import numpy as np
from scipy.sparse.csgraph import dijkstra

def get_path(start, goal, pred):
    return get_path_row(start, goal, pred[start])

def get_path_row(start, goal, pred_row):
    path = []
    i = goal
    while i != start and i >= 0:
        path.append(i)
        i = pred_row[i]
    if i < 0:
        return []
    path.append(i)
    return path[::-1]
N, M = map(int,input().split())
g = [[np.inf]*(2*N) for _ in range(2*N)]
for i in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    g[a][b] = 1
    g[a][b+N] = 1
    g[a+N][b] = 1

ans = np.inf
j = -1
d = dijkstra(g,return_predecessors=True)

for i in range(N):
    if d[0][i][i+N] < ans:
        ans = int(d[0][i][i+N])
        j = i

if ans != np.inf:
    path = get_path(j,j+N,d[1])[::-1][:-1]
    path = [node%N for node in path]
    print(ans)
    for node in path:
        print(node+1)
else:
    print(-1)
n1 = int(input())
n2 = int(input())

s = n1 * n2

if s % 2 == 0:
    print("Even")
else:
    print("Odd")


### FIXED CODE ###

a, b = map(int, input().split())
if (a*b)%2 ==0:
    print('Even')
else:
    print('Odd')
n, k = map(int, input().split())
h =  list(map(int, input().split()))

def solve():
    if n <= k:
        return 0
    s = sum(h)
    h = sorted(h, reverse=True)
    for i in range(k):
        print(h[i])
        s -= h[i]
    return s

print(solve())

### FIXED CODE ###

n, k = map(int, input().split())
h =  list(map(int, input().split()))

def solve():
    global n, k, h
    if n <= k:
        return 0
    s = sum(h)
    h = sorted(h, reverse=True)
    for i in range(k):
        s -= h[i]
    return s

print(solve())
n,ki=map(int,input().split())
v=list(map(int,input().split()))

m=min(n,ki)
ans=0

for i in range(m+1):
    for j in range(i+1):
        q=[]
        tmp=0
        for k in range(j):
            if len(v)>0:
                q.append(v[k])
        for kz in range(i-j):
            if len(v)>0:
                q.append(v[n-1-kz])
        tmp=sum(q)
        q.sort()
        for l in range(ki-i):
            if l<len(q) and q[l]<0:
                tmp-=q[l]
        ans=max(ans,tmp)
        
print(ans)

### FIXED CODE ###

a,b=map(int,input().split())
print((a*3+b)//2)
import sys
import numpy as np
from numba as njit


@njit
def solve(A):
  count = np.zeros(10**6+10, np.int32)
  for x in A:
    if count[x] > 1:
      continue
    else:
      count[::x] += 1
  ret = 0
  for x in A:
    if count[x] == 1:
      rep += 1
  return ret


A = np.array(read().split(),np.int32)
print(solve(A))

### FIXED CODE ###

import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

#@njit
def slove(A):
  count = np.zeros(10**6 + 10, np.int32)
  for x in A:
    if count[x] > 1:
      continue
    count[::x] += 1
  ret = 0
  for x in A:
    ret += count[x] == 1
  return ret

A = np.array(read().split(), np.int32)[1:]

print(slove(A))
A, B, C, X, Y = map(int, input().split())
ans = 0

if A + B <= C:
    ans = A*X + B*Y
else:
    ans += 2*C*min(X, Y)

    if X >= Y:
        ans + = A*(X-Y)
    else:
        ans + = B*(X-Y)

print (ans)


### FIXED CODE ###

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

if A + B <= 2*C:
    ans = A*X + B*Y
else:
    ans += 2*C*min(X, Y)

    if X >= Y:
        ans += min(A, 2*C) * (X-Y)
    else:
        ans += min(B, 2*C) * (Y-X)

print (ans)
import pandas as pd

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

data = pd.Series(S)

print(data.nunique())


### FIXED CODE ###

import numpy as np

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

print(len(np.unique(S)))
inf = 10 ** 9
memo = {}


def cost(n):
    if n == 1:
        return 0
    if n < 1:
        return inf
    if n in memo:
        return memo[n]
    re = min(cost(n - 2) + abs(h[n] - h[n - 2]), cost(n - 1) + abs(h[n] - h[n - 1]))
    memo[n] = re
    return re


n = int(input())
h = [0] + list(map(int, input().split()))
print(cost(n))


### FIXED CODE ###

n = int(input())
h = [0] + list(map(int, input().split()))
cost = {1:0,2: abs(h[2] - h[1])}
for i in range(1, n):
    cost[i + 1] = min(cost[i + 1], cost[i] + abs(h[i + 1] - h[i]))
    if i==n-1:break
    cost[i + 2] = cost[i] + abs(h[i + 2] - h[i])

print(cost[n])
n = int(input())
num_list = [ int(v) for v in range(n)]
s = 0
for i in range(n):
	if max(num_list[:i+1]) <= i:
		s += 1
print(ans)

### FIXED CODE ###

n = int(input())
num_list = [ int(v) for v in input().split() ]
s = 0
for i in range(n):
  if max(num_list[:i+1]) <= num_list[i]:
    s += 1
print(s)
from math import ceil,sqrt,log,gcd



def main():
    
    # a=list(map(int,input().split()))
    # s=input()
    
    a,b,c=map(int,input().split())
    a,b=b,a
    a,c=c,a
    print(a,b,c)
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
      
if __name__ =="__main__":
    main()

### FIXED CODE ###


    
a,b,c=map(int,input().split())
a,b=b,a
a,c=c,a
print(a,b,c)
import fractions

N = int(input())
A = list(map(int, input().split()))

a = A[0]
for i in range(1, N):
    g = a * A[i] // fractions.gcd(a, A[i])
    a = g
    
b = 0
for i in range(N):
    b = b + gcc // A[i]

c = b % (1000000007)
print(c)

### FIXED CODE ###

N, M = map(int, input().split())

if M >= N:
    print('Yes')
else:
    print('No')
import math

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

cities = [a, b, c, d, e]
min_val = 10
for i, x in enumerate(cities):
    if x < min_val:
        min_val = x
        idx = i

ans = 0 if idx == 0 else idx

ans += math.ceil(n / min_val)
ans = ans + 4 - idx
print(ans)


### FIXED CODE ###

import math

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

cities = [a, b, c, d, e]
min_val = 1e18
idx = 0
for i, x in enumerate(cities):
    if x < min_val:
        min_val = x
        idx = i

ans = 0 if idx == 0 else idx

ans += math.ceil(n / min_val)
ans = ans + 4 - idx
print(ans)
n = int(input())
if n % 2 == 0:
  print n
else:
  print n * 2

### FIXED CODE ###

n = int(input())
if n % 2 == 0:
  print(n)
else:
  print(n * 2)
from collections import deque

def bfs(que,d): #幅優先探索
  "
  #いつもはここで定義
  #入力のグラフを初期化
  #d = [[float("inf")] * w for i in range(h)] 
  #que = deque([])
  #que.append((sx,sy))
  #d[sx][sy] = 0
  "
  lead = 0
  dx = [-1,0,0,1]
  dy = [0,-1,1,0]
  
  while que:
    lead_h,lead_w = que.popleft()
    lead = d[lead_h][lead_w]
    #lead == queの先頭にある要素を取り出す
    for i in range(4):
      nx = lead_w + dx[i]
      ny = lead_h + dy[i]
      if ny<0 or h<=ny or nx<0 or w<=nx:
        #範囲外の場合
        continue
      if d[ny][nx]==float("inf"):
        d[ny][nx] = lead + 1
        que.append((ny,nx))
  return lead

h, w = map(int, input().split())
maze = [list(input()) for i in range(h)]

#多点スタートなのでbfs()内で定義して初期化しない
d = [[float("inf")] * w for i in range(h)] 

#キューも同様
que = deque([])
for i in range(h):
  for j in range(w):
    if maze[i][j] == "#":
      que.append((i,j))
      #各"#"を入れる
      d[i][j] = 0

#print(bfs())
lead = bfs(que,d)
print(lead)

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
grid = [input() for i in range(H)]

# 初期の黒('#')の位置からの距離
dist = [[-1]*W for _ in range(H)]

# '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append((h, w))
            dist[h][w] = 0

def bfs(black_cells, dist):
    d = 0
    while black_cells:
        # キューとして使うのでpop()ではなくpopleft()
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:  # セルが白('.')であるのと同義
                dist[new_h][new_w] = d+1
                black_cells.append((new_h, new_w))
    return d

d = bfs(black_cells, dist)
print(d)
n = int(input())
a = list(map(int, input().split()))
odd = a[::2]
even = a[1::2]
even.reverse()
ans = even + odd
print(" ".join(ans))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
odd = a[::2]
even = a[1::2]
even.reverse()
ans = even + odd
if n % 2:
  ans.reverse()
  
print(" ".join(list(map(str, ans))))
n=int(input())
x=map(int,input().split())
y = sorted(x)
x1, x2 = y[n//2-1], y[n//2]
for i in range(n):
    if x[i]<=x1:
        print(x2)
    else:
        print(x1)


### FIXED CODE ###

a, b, x = map(int, input().split())
if a + b >= x and a <= x:
    print('YES')
else:
    print('NO')
A, B = map(int, input().split())
D = []
E = []
total = A
for i in range(B):
    C = int(input())
    D = map(int, input().split())
    E.append(list(D))
 
for i in range(A):
  if str(i+1) in str(E):
    total = total - 1
 
print(total)

### FIXED CODE ###

I = input()
print("ABC" if I == "ARC" else "ARC")
n = int(input())
x = list(map(int, input().split()))

n, k, s = map(int, input().split())

a = []
if k == 0:
    for _ in range(n):
        a.append(str(s + 1000))
else:
    if n == k:
        for _ in range(n):
            a.append(str(s))
    else:
        if s != 1:
            for i in range(k + 1):
                if i % 2 == 0:
                    a.append(str(s - 1))
                else:
                    a.append(str(1))
            for _ in range(n - k - 1):
                a.append(str(s + 1))
        else:
            for _ in range(k):
                a.append(str(1))
            for _ in range(n - k):
                a.append(str(2))


ans = ' '.join(a)
print(ans)

### FIXED CODE ###

n, k, s = map(int, input().split())
a = []
for _ in range(k):
        a.append(str(s))
for _ in range(n-k):
  if s != 1000000000:
  	a.append(str(s+1))
  else:
    a.append(str(s-1))
ans = ' '.join(a)
print(ans)
sp = []
for i in range(n):
    s, p = input().split()
    sp.append((s, int(p), i+1))

sp_sort = sorted(sp, key=lambda x: (x[0], -1 * x[1]))

for i in range(n):
    print(sp_sort[i][2])


### FIXED CODE ###

n = int(input())

sp = []
for i in range(n):
    s, p = input().split()
    sp.append((s, int(p), i+1))

sp_sort = sorted(sp, key=lambda x: (x[0], -1 * x[1]))

for i in range(n):
    print(sp_sort[i][2])
n,d=map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
a=0
for i in range(len(x)):
    for j in range(i+1, len(x)):
        if float.is_integer(((x[i][0]-x[j][0])**2+(x[i][1]-x[j][1])**2)**0.5):
            a += 1
print(a)

### FIXED CODE ###

n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
a = 0
for i in range(len(x)):
    for j in range(i+1, len(x)):
        t = 0
        for k in range(d):
            t += (x[i][k]-x[j][k])**2
        if float.is_integer(t**0.5):
            a += 1
print(a)
mod = 10**9+7
N = int(input())
Ca = [int(input())-1 for i in range(N)]
C = []
p = -1
for c in Ca:
    if p != c:
        C.append(c)
    p = c
#print(C)
N = len(C)
L = [-1]*N
dp = [0]*N
dp[0] = 1
L[C[0]] = 0

if N<=2:
    print(1)
    exit()
for i, c in enumerate(C[1:], 1):
    if L[c] == -1:
        L[c] = i
        dp[i] = dp[i-1]
        continue
    else:
        dp[i] = (dp[i-1] + dp[L[c]]) % mod
        L[c] = i
print(dp[-1])


### FIXED CODE ###

mod = 10**9+7
N = int(input())
Ca = [int(input())-1 for i in range(N)]
C = []
p = -1
for c in Ca:
    if p != c:
        C.append(c)
    p = c
#print(C)
N = len(C)
if N<=2:
    print(1)
    exit()
L = [-1]*(2*10**5)
dp = [0]*N
dp[0] = 1
L[C[0]] = 0


for i, c in enumerate(C[1:], 1):
    if L[c] == -1:
        L[c] = i
        dp[i] = dp[i-1]
        continue
    else:
        dp[i] = (dp[i-1] + dp[L[c]]) % mod
        L[c] = i
print(dp[-1])
n=int(input())
x=list(str,input().split() for _ in range(n))
ans=0
for i in range(n):
  if x[i][1]=="JPY":
    ans+=int(x[i][0])
  else:
    ans+=int(x[i][0])*380000
    
print(ans)    
  



### FIXED CODE ###

n=int(input())
x=list(input().split() for _ in range(n))
ans=0
for i in range(n):
  if str(x[i][1])=="JPY":
    ans+=float(x[i][0])
  else:
    ans+=float(x[i][0])*380000
    
print(ans)
n=int(input())
r=list(map(int,input().split()))
m=int(input())
d=list(map(int,input().split()))
e=set(d)

from collections import Counter
n=counter(n)
d=counter(d)

for item in e:
  if r[item]<d[item]:
    print("NO")
    exit()
print("YES")


### FIXED CODE ###

import collections

a=int(input())
b=collections.Counter(list(map(int,input().split())))
c=int(input())
d=collections.Counter(list(map(int,input().split())))
e=set(d)

for item in e:
  if d[item]>b[item]:
    print("NO")
    exit()
    
print("YES")
n,q = map(int, raw_input().split())
que = [map(str, raw_input().split()) for i in range(n)]
for i in range(n):que[i][1] = int(que[i][1])
mxt = sum([y for x,y in que])
t = 0
i = 0
while t < mxt:
    if i = n: i = 0
    if que[i][1] <= q:
        t += que[i][1]
        print que[i][0],t
        que.pop(i)
        n -= 1
    else:
        t += q
        que[i][1] -= q
        i += 1

### FIXED CODE ###

n,q = map(int, raw_input().split())
que = [map(str, raw_input().split()) for i in range(n)]
for i in range(n):que[i][1] = int(que[i][1])
mxt = sum([y for x,y in que])
t = 0
i = 0
while t < mxt:
    if i >= n: i %= n
    if que[i][1] <= q:
        t += que[i][1]
        print que[i][0],t
        que.pop(i)
        n -= 1
    else:
        t += q
        que[i][1] -= q
        i += 1
int X=input()
if(X==30):
  print("Yes")
else:
  print("No")


### FIXED CODE ###

X=int(input())
if(X<=40 and X>=-40):
    if(X>=30):
        print("Yes")
    else:
        print("No")
import sys
input=sys.stdin.readline
a,b=int(input())
if a+b%2==0:
  print((a+b)/2)
else:
  print('impossible')

### FIXED CODE ###

a,b=map(int, input().split())
print (int((a+b)/2) if (a+b)%2 == 0 else "IMPOSSIBLE")
import sys
sys.setrecursionlimit(10**8)

n = int(input())
xs = list(input())[::-1]

x = 0
for i in range(n):
    if xs[i] == '1':
        x+=2**i

def popcount(x):
    '''xの立っているビット数をカウントする関数
    (xは64bit整数)'''

    # 2bitごとの組に分け、立っているビット数を2bitで表現する
    x = x - ((x >> 1) & 0x5555555555555555)

    # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
    x = x + (x >> 8) # 16bitごと
    x = x + (x >> 16) # 32bitごと
    x = x + (x >> 32) # 64bitごと = 全部の合計
    return x & 0x0000007f

memo = {}
memo[0] = 0
def dfs(n, depth=0):
    if n in memo:
        return depth + memo[n]
    else:
        ret = dfs(n%popcount(n), depth+1)
        return ret

ans = []
for i in range(n):
    ans.append(dfs(x^(1<<i)))
for a in ans[::-1]:
    print(a)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)

n = int(input())
x = list(input())
bit_cnt = x.count('1')

# bitを一つ増やす場合
pos = [0] * n
pos_total = 0

# bitを一つ減らす場合
neg = [0] * n
neg_total = 0

base = 1
for i in range(n):
    pos[-i-1] = base%(bit_cnt+1)
    if x[-i-1] == '1':
        # 同時にmod(bit_cnt+1)の法でトータルを作成
        pos_total = (pos_total + base) % (bit_cnt+1)
    base = (base*2) % (bit_cnt+1)

base = 1
if bit_cnt == 1:
    # mod取れない
    pass
else:
    for i in range(n):
        neg[-i-1] = base%(bit_cnt-1)
        if x[-i-1] == '1':
            # 同時にmod(bit_cnt-1)の法でトータルを作成
            neg_total = (neg_total + base) % (bit_cnt-1)
        base = (base*2) % (bit_cnt-1)

def popcount(n):
    s = list(bin(n)[2:])
    return s.count('1')

memo = {}
memo[0] = 0
def dfs(n, depth=0):
    if n in memo:
        return depth + memo[n]
    else:
        ret = dfs(n%popcount(n), depth+1)
        # memo[n] = ret
        return ret

ans = []
for i in range(n):
    if x[i] == '0':
        st = (pos_total + pos[i]) % (bit_cnt+1)
        print(dfs(st, depth=1))
    elif bit_cnt == 1:
        # コーナーケース：すべてのbitが0となる
        print(0)
    else:
        st = (neg_total - neg[i]) % (bit_cnt-1)
        print(dfs(st, depth=1))
n=int(input())
graph=[[] for i in range(n+1)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    graph[a].append((b,c))
    graph[b].append((a,c))
    
q,k=map(int,input().split())

dis=[None]*(n+1)

def set_dis(x,d):
    dis[x]=d
    for yy,dd in graph[x] :
        if dis[yy] is not None:
            continue
        set_dis(yy,dd+d)
set_dis(k,0)

for i in range(q):
    x,y=map(int,input().split())
    print(dis[x]+dis[y])


### FIXED CODE ###

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


n=int(input())
graph=[[] for i in range(n+1)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    graph[a].append((b,c))
    graph[b].append((a,c))
    
q,k=map(int,input().split())

dis=[None]*(n+1)

def set_dis(x,d):
    dis[x]=d
    for yy,dd in graph[x] :
        if dis[yy] is not None:
            continue
        set_dis(yy,dd+d)
set_dis(k,0)

for i in range(q):
    x,y=map(int,input().split())
    print(dis[x]+dis[y])
H1 = int(raw_input())
M1 = int(raw_input())
H2 = int(raw_input())
M2 = int(raw_input())
K = int(raw_input())

### FIXED CODE ###

import sys
readline = sys.stdin.buffer.readline

h1, m1, h2, m2, k = map(int, readline().split())
print(60 * (h2 - h1) + m2 - m1 - k)
n = int(input())
a = list(map(int, input().split()))

if max(a) == 0 :
    bl = [0]
else :
    bl = [0 for _ in range(floor(log2(max(a)))+1)]
for ai in a :
    aj = ai
    if ai == 0 :
        pass
    else :
        for i in range(floor(log2(ai))+1) :
            if aj & 1 == 1 :
                bl[i] += 1
            aj >>= 1

ans = reduce(or_, map(lambda x : x&1, bl))
if ans :
    print("No")
else :
    print("Yes")

### FIXED CODE ###

from math import log2, floor
from operator import or_
from functools import reduce

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

if max(a) == 0 :
    bl = [0]
else :
    bl = [0 for _ in range(floor(log2(max(a)))+1)]
for ai in a :
    aj = ai
    if ai == 0 :
        pass
    else :
        for i in range(floor(log2(ai))+1) :
            if aj & 1 == 1 :
                bl[i] += 1
            aj >>= 1

ans = reduce(or_, map(lambda x : x&1, bl))
if ans :
    print("No")
else :
    print("Yes")
n=int(input())
s=[input() for in range(n)]
for v in ['AC', 'WA', 'TLE', 'RE']:
    print('{0} x {1}'.format(v, s.count(v)))

### FIXED CODE ###

n=int(input())
ac=0
wa=0
tle=0
re=0
for i in range(n):
    m=input()
    if m=='AC': ac+=1
    elif m=='WA': wa+=1
    elif m=='TLE': tle+=1
    elif m=='RE': re+=1
print('AC x '+str(ac))
print('WA x '+str(wa))
print('TLE x '+str(tle))
print('RE x '+str(re))
from fractions import gcd
n=int(input())
ans=int(input())
for i in range(1,n):
  t=int(input())
  ans=int(ans*t/gcd(ans,t))
print(ans)

### FIXED CODE ###

from fractions import gcd
n=int(input())
ans=int(input())
for i in range(1,n):
  t=int(input())
  ans=ans*t//gcd(ans,t)
print(int(ans))
import math
from functools import reduce
K = int(input())
ans = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      ans += gcd(a,b,c)
print(ans)

### FIXED CODE ###

import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
K = int(input())
ans = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    for c in range(1, K+1):
      ans += gcd(a,b,c)
print(ans)