Harryxun/stf_run huggingface dataset:
import sys
def t(A,p,r):
 x=A[r][1];i=p-1
 for j in range(p,r):
  if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]
 A[i+1],A[r]=A[r],A[i+1]
 return i+1
def k(A,p,r):
 if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)
def s(A):
 for i in range(n-1):
  if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'
 return'S'
def m():
 n=int(input())
 A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]
 k(A,0,n-1)
 print(s(A)+'table')
 print('\n'.join(f'{a} {b}'for a,b,_ in A))
if'__main__'==__name__:m()


### FIXED CODE ###

import sys
def t(A,p,r):
 x=A[r][1];i=p-1
 for j in range(p,r):
  if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]
 A[i+1],A[r]=A[r],A[i+1]
 return i+1
def k(A,p,r):
 if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)
def s(A):
 for i in range(n-1):
  if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'
 return'S'
def m():
 A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]
 k(A,0,n-1)
 print(s(A)+'table')
 print('\n'.join(f'{a} {b}'for a,b,_ in A))
if'__main__'==__name__: n=int(input());m()
a,b,c=map(int,input().split())
def gojo(x,y):
    if x%y==0:
        return y
    else:
        return gojo(y,x-y)

if c==0:
    print("YES")
elif c%gojo(a,b)==0 and c!=0:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

a,b,c=map(int,input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
if c==0:
    print("YES")
elif c%gcd(a,b)==0 and c!=0:
    print("YES")
else:
    print("NO")
n, m = map(int, input().split())


a = [[],[],[]]
for i in range(m):
    s, c = map(int, input().split())
    if not c in a[s-1]:
        a[s-1].append(c)
    
ans = 0
if (len(a[0]) > 1) or (len(a[1]) > 1) or (len(a[2]) > 1):
    print(-1)
elif a[0][0] == 0:
    print(-1)
else:
    if len(a[0])==0 and a[1][0]==0:
        a[0].append(1)
    for i in range(n):
        if len(a[i]) == 1:
            ans += a[i][0] * (10**(n-1-i))
    print(ans)








### FIXED CODE ###

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


a = [[],[],[]]
for i in range(m):
    s, c = map(int, input().split())
    if not c in a[s-1]:
        a[s-1].append(c)
    
ans = 0
if m==0:
    if n==3:
        print(100)
    elif n==2:
        print(10)
    else :
        print(0)
elif (len(a[0]) > 1) or (len(a[1]) > 1) or (len(a[2]) > 1):
    print(-1)
else:
    if (n==3 or n==2) and len(a[0]) == 0:
        a[0].append(1)
    if (n==3 or n==2) and a[0][0] == 0:
        print(-1)
    else:
        for i in range(n):
            if len(a[i]) == 1:
                ans += a[i][0] * (10**(n-1-i))
        print(ans)
N,B,R = map(int,input().split())
k = N % (B + R)
k2 = int(N / (B + R))
s = ("b"*B + "r"*R)
s1 = s[:k]
if k <= B:
	print(k2*(B) + k)
else:
	print(k2*(B) + B)


### FIXED CODE ###

N,B,R = map(int,input().split())
k = N % (B + R)
k2 = int(N / (B + R))
#s = ("b"*B + "r"*R)

#s1 = s[:k]
if k <= B:
	print(k2*(B) + k)
else:
	print(k2*(B) + B)
def pyramid(N: int, info: list) -> tuple:
    """
    """
    _info = sorted(info, reverse=True)
    x, y, h = _info[0]
    candidtes = [
        (cx, cy, h + abs(cx - x) + abs(cy - y))
        for cx in range(100+1)
        for cy in range(100+1)]

    for x, y, h in _info[1:]:
        temp = []
        for cx, cy, H in candidtes:
            th = max(H - abs(cx - x)-abs(cy - y), 0)
            if th == h:
                temp.append((cx, cy, H))

        candidtes = temp

    return candidtes[0]

if __name__ == "__main__":
    N = int(input())
    info = [
        tuple(int(s) for s in input().split())
        for _ in range(N)]
    cx, cy, h = pyramid(N, info)
    print(cx, cy, h)


### FIXED CODE ###

def pyramid(N: int, info: list) -> tuple:
    """
    """
    _info = sorted(info, key=lambda x: x[2], reverse=True)
    x, y, h = _info[0]
    candidtes = [
        (cx, cy, h + abs(cx - x) + abs(cy - y))
        for cx in range(100+1)
        for cy in range(100+1)]

    for x, y, h in _info[1:]:
        temp = []
        for cx, cy, H in candidtes:
            th = max(H - abs(cx - x)-abs(cy - y), 0)
            if th == h:
                temp.append((cx, cy, H))

        candidtes = temp

    return candidtes[0]

if __name__ == "__main__":
    N = int(input())
    info = [
        tuple(int(s) for s in input().split())
        for _ in range(N)]
    cx, cy, h = pyramid(N, info)
    print(cx, cy, h)
while True:
    (m, f, r) = [int(i) for i in input().split()]
        if m==-1 and f==-1 and r==-1:
            break

    g = m + f
    if m == -1 or f == -1 or g < 30:
        print('F')
    elif g < 50 or r < 50:
        print('D')
    elif g < 65:
        print('C')
    elif g < 80:
        print('B')
    else:
        print('A')

### FIXED CODE ###

while True:
    (m, f, r) = [int(i) for i in input().split()]
    if m == f == r == -1:
        break
 
    total = m + f
    if m == -1 or f == -1 or total < 30:
        print('F')
    elif total < 50 and r < 50:
        print('D')
    elif total < 65:
        print('C')
    elif total < 80:
        print('B')
    else:
        print('A')
n, q = map(int, input().split())
node = [[] for _ in range(n)]
ans = [0] * n

def score(p, c):
    ans[p] += c
    for child in node[p]:
        score(child, ans[p])

for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    node[a].append(b)

for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

score(0, 0)
print(*ans)


### FIXED CODE ###

n, q = map(int, input().split())
node = [[] for _ in range(n)]
ans = [0] * n

for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    node[a].append(b)
    node[b].append(a)

for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

not_yet = [True] * n
not_yet[0] = False
stack = [0]
while stack:
    parent = stack.pop()
    for child in node[parent]:
        if not_yet[child]:
            ans[child] += ans[parent]
            not_yet[child] = False
            stack.append(child)

print(*ans)
a, b = input().split()
M = a * b
print(M)

### FIXED CODE ###

a, b = map(int,input().split())
M = a * b
S = 2 * (a + b)
print(M,S)
S=input()
T=input()
print(T+S)

### FIXED CODE ###

S, T=input().split()
print(T+S)
a=int(input())
b=int(input())

if a==b : 
  print(a*2)
else :
  print(max(a,b)*2-1)
    

### FIXED CODE ###

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

if a==b : 
  print(a*2)
else :
  print(max(a,b)*2-1)
N=int(input())

if N==2:
  A=int(input())
  B=int(input())
  
print('Hello World' if N==1 else a+b)

### FIXED CODE ###

N=int(input())

if N==2:
  A=int(input())
  B=int(input())
  
print('Hello World' if N==1 else A+B)
N,K=[int(s) for s in input().split(" ")]
ListH=[int(s) for s in input().split(" ")]

ListH=sorted(ListH,reverse=True)
sum=0

if N > K:
    for i in range(K):
        ListH.pop(i)

    for i in range(N-K):
        sum+=ListH[i]
else:
    sum=0
    
print(sum)

### FIXED CODE ###

N, K = map(int, input().split())
ListH = list(map(int, input().split()))


if N<=K:
    print(0)
else:
    ListH.sort()
    sum=0
    for i in range(N-K):
        sum+=ListH[i]

    print(sum)
def eratosthenes(n):
 is_p=[1]*n
 p_list=[]

 is_p[0]=0
 is_p[1]=0

 for i in range(2,n):
  if is_p[i]:
   p_list.append(i)
   for j in range(i*i,n,i):
    is_p[j] = 0

 return is_p, p_list

lim=10**5+1
is_p, p_list=eratosthenes(lim)

q=int(input())

'''
b=[0]
for i in range(1,lim+1):
 if is_p[i-1] and is_p[i//2]:
  b.append(b[i-1]+1)
 else:
  b.append(b[i-1])
'''
a = [0] * (10**4+2)
for i in range(3, 10**4+1, 2):
    if is_p[i] and is_p[(i+1)//2]:
        a[i] = 1
for i in range(1, 10**4+1):
    a[i+1] += a[i]

for i in range(q):
 l,r=map(int,input().split())
# print(b[r+1]-b[l])
 print(a[r]-a[l-1])

### FIXED CODE ###

def factorization(n):
 p=2
 fcr=[]
 while p*p<=n:
  while n%p==0:
   fcr.append(p)
   n//=p
  p+=1
 if n>1:
  fcr.append(n)
 return fcr

q=int(input())

cnt=1
p_list=[1]
q_list=[0]
for i in range(3,10**5+1,2):
 a=factorization(i)
 b=factorization((i+1)//2)

 if len(a)==len(b)==1:
  cnt+=1
  q_list.append(1)
 else:
  q_list.append(0)

 p_list.append(cnt)

for i in range(q):
 l,r=map(int,input().split())

 c=p_list[r//2]-p_list[l//2]
 if q_list[l//2]==1:
  print(c+1)
 else:
  print(c)
from collections import deque

class Dice:
    def __init__(self, top, down, right, left, up, bottom):
        self.top = top
        self.bottom = bottom
        self.up = up
        self.down = down
        self.left = left
        self.right = right

    def roll(self, command):
        for c in list(command):
            if c == 'N':
                self.up, self.top, self.down, self.bottom = self.top, self.down, self.bottom, self.up
            elif c == 'S':
                self.up, self.top, self.down, self.bottom = self.bottom, self.up, self.top, self.down
            elif c == 'E':
                self.left, self.top, self.right, self.bottom = self.bottom, self.left, self.top, self.right
            elif c == 'W':
                self.left, self,top, self.right, self.bottom = self.top, self.right, self.bottom, self.left

    def pip(self):
        return self.top

if __name__ == '__main__':
    seq = list(map(int, input().split()))
    dice = Dice(*seq)
    dice.roll(input())
    print(dice.pip())



### FIXED CODE ###

from collections import deque

class Dice:
    def __init__(self, top, down, right, left, up, bottom):
        self.top = top
        self.bottom = bottom
        self.up = up
        self.down = down
        self.left = left
        self.right = right

    def roll(self, command):
        for c in list(command):
            if c == 'N':
                self.up, self.top, self.down, self.bottom = self.top, self.down, self.bottom, self.up
            elif c == 'S':
                self.up, self.top, self.down, self.bottom = self.bottom, self.up, self.top, self.down
            elif c == 'E':
                self.left, self.top, self.right, self.bottom = self.bottom, self.left, self.top, self.right
            elif c == 'W':
                self.left, self.top, self.right, self.bottom = self.top, self.right, self.bottom, self.left

    def pip(self):
        return self.top

if __name__ == '__main__':
    seq = list(map(int, input().split()))
    dice = Dice(*seq)
    dice.roll(input())
    print(dice.pip())
N,A,B=map(int,input().split())

sum_k=0

for i in range(N+1):
    if i <10:
        k=i
    elif i<100:
        k=i//10+i%10
    elif i<1000:
        k=i//100+(i%100)//10+(i%100)%10
    else:
        k=1
    if A<=k and k<=B
        sum_k=sum_k+i
      
print(sum_k)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Wed Jun 20 16:39:29 2018

@author: Yuya
"""

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

sum_k=0

for i in range(N+1):
    if i <10:
        k=i
    elif i<100:
        k=i//10+i%10
    elif i<1000:
        k=i//100+(i%100)//10+(i%100)%10
    elif i<10000:
        k=i//1000+(i%1000)//100+((i%1000)%100)//10+((i%1000)%100)%10
    else:
        k=1
    if A<=k and k<=B:
        sum_k=sum_k+i
      
print(sum_k)
N,M = map(int,input().split())

if N == 1:
    c1 = 0
else:
    c1 = N! / (2! * (N - 2)!)

if M == 1:
    c2 = 0
else:
    c2 = M! / (2! * (M - 2)!)

print(c1 + c2)

### FIXED CODE ###

import itertools

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

if N == 1:
    c1 = 0
else:
    c1 = len(list(itertools.combinations(range(N), 2)))

if M == 1:
    c2 = 0
else:
    c2 = len(list(itertools.combinations(range(M), 2)))

c3 = c1 + c2
print(c3)
import numpy as np
a = input()
n, l = [int(i) for i in a.split(" ")]
apples = np.array([i for i in range(n)])
aji = apples + l
abss = [np.abs(aji[apples != i].sum() - aji.sum()) for i in range(n)]
i = abss.index(np.min(abss))
print([aji[apples != i].sum()][i])

### FIXED CODE ###

import numpy as np
a = input()
n, l = [int(i) for i in a.split(" ")]
apples = np.array([i for i in range(n)])
aji = apples + l
abss = [np.abs(aji[apples != i].sum() - aji.sum()) for i in range(n)]
i = abss.index(np.min(abss))
print(aji[apples != i].sum())
def main():
    N, M, K = map(int, input().split())
    A = deque([int(a) for a in input().split()])
    B = deque([int(b) for b in input().split()])
    Bsum = sum(B)
    ans = Asum = 0
    idx_b = len(B) - 1

    A.appendleft(0)

    for i in range(len(A)):
        Asum += A[i]

        for j in range(idx_b + 1):
            if Asum + Bsum > K:
                if idx_b >= 0:
                    Bsum -= B[idx_b]
                    idx_b -= 1
                else:
                    break
            else:
                break

        if Asum + Bsum <= K:
            ans = max(ans, i + (idx_b + 1))

    print(ans)
 
if __name__ == "__main__":
    main()

### FIXED CODE ###

def main3():
    N, M, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    Bsum = sum(B)
    ans = Asum = 0
    idx_b = len(B) - 1

    for i in range(N + 1):
        if i == 0:
            if Asum + Bsum <= K:
                ans = max(ans, i + idx_b + 1)

            else:
                while Asum + Bsum > K:
                    if idx_b >= 0:
                        Bsum -= B[idx_b]
                        idx_b -= 1
                    else:
                        break
                    
                if Asum + Bsum <= K:
                    ans = max(ans, i + idx_b + 1)

        else:
            Asum += A[i - 1]

            while Asum + Bsum > K:
                if idx_b >= 0:
                    Bsum -= B[idx_b]
                    idx_b -= 1
                else:
                    break
            if Asum + Bsum <= K:
                ans = max(ans, i + idx_b + 1)

    print(ans)

if __name__ == "__main__":
    main3()
a ,b= map(int,input().split())
aaa = [list(map(int,input().split())) for i in range(b*2)]
 
s = {i+1 for i in range(a)}

for i in range(1,a+1,2):
    for k in aaa[i]:
        for j in k:
            s.discard(j)
print(len(s))

### FIXED CODE ###

a,b = map(int,input().split())
aaa = [list(map(int,input().split())) for i in range(b*2)]

c = set()
e = set()
for i in range(1,len(aaa),2):
  for k in aaa[i]:
     c.add(k)
    
print(a - len(c))
#include <stdio.h>

int main(){
  int x;
  scanf("%d", &x);
  
  if (x >= 30){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  
  return 0;
}

### FIXED CODE ###

x = int(input())
if x >= 30:
  print("Yes")
else:
  print("No")
import queue
q = queue.Queue()

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

friend = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)

block = [[] for _ in range(n)]
for _ in range(k):
    c, d = map(int, input().split())
    block[c-1].append(d-1)
    block[d-1].append(c-1)
    
#print(friend)
#print(block)
c_list = []
for i in range(n):
    counter = 0
    seen = [i]
    for j in friend[i]:
        q.put(j)
        seen.append(j)
    while q.qsize() != 0:
        x = q.get()
        for k in friend[x]:
            if not k in seen and not k in block[i]:
                q.put(k)
                seen.append(k)
                counter += 1
    c_list.append(counter)
    
print(c_list)

### FIXED CODE ###

n = int(input())

if n%2 == 0:
  print(int(n/2))
else:
  print(int((n+1)/2))
#coding:utf-8
n, m = map(int, input().split())
A = list(map(int, input().split()))
ll = []
for i in range(m):
    b, c = map(int, input().split())
    ll.extend([c] * b)
A.sort(reverse=True)
ll.sort(reverse=True)
i, j = 0, 0
ans = 0
for _ in range(n):
    if A[i] > ll[j]:
        ans += A[i]
        i += 1
    else:
        ans += ll[j]
        j += 1
print(ans)
    

### FIXED CODE ###

# coding: utf-8
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)
minus = 0
l = []
for i in range(M):
    b, c = map(int, input().split())
    l.append([b, c])
l.sort(key=lambda x: x[1], reverse=True)
A.sort(reverse=False)
idx = 0
i = 0
ans = 0
while i < N and idx < M:
    if l[idx][0] == 0:
        idx += 1
    if idx >= M:
        ans += A[i]
        i += 1
        continue
    if A[i] < l[idx][1]:
        ans += l[idx][1]
        l[idx][0] -= 1
        i += 1
    else:
        ans += A[i]
        i += 1
    # print("ans =", ans)
for j in range(i, N):
    ans += A[j]
print(ans)
A, B = map(int, input().rstrip().sprit())
print(max(A+B, A-B, A*B))

### FIXED CODE ###

#98

A, B = map(int, input().rstrip().split())
print(max(A+B, A-B, A*B))
a, b, k = map(int, input().split())
num_list = list(range(a,b+1))

if (b-a+1) <= 2 *k :
    for i in range(b-a+1) :
        print(num_list[i])
else :
    smaller = num_list[:k]
    larger = num_list[-k:]
    ans = smaller + larger
    for i in range(k*2) :
        print(ans[i])


### FIXED CODE ###

a, b, k = map(int, input().split())
if (b-a+1) <= 2 * k :
    count = a
    while count <= b :
        print(count)
        count += 1
else :
    for i in range(k) :
        print(a+i)
    for i in range(k) :
        print(b-((k-1)-i))
import math

#n = int(input())
n, k = [int(i) for i in input().split()]
#table = [[i for i in input().split()] for n in range(h)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#s = input()
#list = list(s)

#s = [int(input()) for i in range(m)] #m行1列入力

if (k = 1) :
    kotae = 0
else :
    kotae = n - k

print(kotae)

### FIXED CODE ###

import math

#n = int(input())
n, k = [int(i) for i in input().split()]
#table = [[i for i in input().split()] for n in range(h)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#s = input()
#list = list(s)

#s = [int(input()) for i in range(m)] #m行1列入力

if (k == 1) :
    kotae = 0
else :
    kotae = n - k

print(kotae)
s=list(input())
t=list(input())
n=len(t)
m=len(s)
for i in range(n):
    l=n-i
    for j in range(i+1):
        print(t[j:j+l],i,s[j:j+m-i])
        if ''.join(t[j:j+l]) in ''.join(s[j:j+m-i]):
            print(i)
            exit()
print(n)

### FIXED CODE ###

s=list(input())
t=list(input())
n=len(t)
m=len(s)
mn=n
for i in range(m-n+1):
    err=0
    for j in range(n):
        if s[i+j]!=t[j]:
            err+=1
    mn=min(mn,err)
print(mn)
n=int(input())
sum=0
for i in range(1,n+1)
 if i%3!=0 and i%5!=0:
    sum+=i
print(sum)

### FIXED CODE ###

n=int(input())
sum=0
for i in range(1,n+1):
 if i%3!=0 and i%5!=0:
    sum+=i
print(sum)
import collections
import string
??
def solve(s):
????????s = s.lower()
????????counter = collections.Counter(s)
????????lows = string.ascii_lowercase
????????cnt = [counter[ch] for ch in lows]
????????for (ch, n) in zip(lows, cnt):
????????????????print('{0} : {1}'.format(ch, n))
??
if __name__ == '__main__':
????????s = ''
????????while True:
????????????????try:
????????????????????????s += input()
????????????????except:
????????????????????????break
????????solve(s)

### FIXED CODE ###

sentence = ''
while True:
    try:
        sentence += input().lower()
    except:
        break
 
for i in range(ord('a') , ord('z') + 1):
    print('{} : {}'.format(chr(i),sentence.count(chr(i))))
N, R = map(int, input())
if N >= 10:
  print(R)
else:
  print(R - 100 * (10 - N))N, R = map(int, input().split())
if N >= 10:
  print(R)
else:
  print(R + 100 * (10 - N))

### FIXED CODE ###

N, R = map(int, input().split())
if N >= 10:
  print(R)
else:
  print(R + 100 * (10 - N))
a,b,c=map(int,input().split())
if (a-b)>=c:
  print(0)
  else:
    print(c-a+b)

### FIXED CODE ###

a,b,c=map(int,input().split())
if (a-b)>=c:
  print(0)
else:
  print(c-a+b)
x, y = input()

print(">" if x > y else "<" if x < y else "=")

### FIXED CODE ###

x, y = input().split()

print(">" if x > y else "<" if x < y else "=")
Not found

### FIXED CODE ###

s = input()
for i in range(0,len(s),2):
    print(s[i],end="")
noWeight = [[0 for j in range(W+1)] for i in range(N)]
wv = [[] for i in range(N)]
for i in range(N) :
	wv = [int(i) for i in input().split()]
	for j in range(1,W+1) :
		if i != 0 :
			if j < wv[0]  :
				noWeight[i][j] = noWeight[i-1][j]
			else :
				noWeight[i][j] = max(noWeight[i-1][j - wv[0]] + wv[1], noWeight[i-1][j])
		else :
			if j >= wv[0] :
				noWeight[i][j] = wv[1]
			else :
				noWeight[i][j] = 0
	
print(noWeight[N-1][W])


### FIXED CODE ###

N, W = [int(i) for i in input().split()]
noWeight = [[0 for j in range(W+1)] for i in range(N)]
wv = [[] for i in range(N)]
for i in range(N) :
	wv = [int(i) for i in input().split()]
	for j in range(1,W+1) :
		if i != 0 :
			if j < wv[0]  :
				noWeight[i][j] = noWeight[i-1][j]
			else :
				noWeight[i][j] = max(noWeight[i-1][j - wv[0]] + wv[1], noWeight[i-1][j])
		else :
			if j >= wv[0] :
				noWeight[i][j] = wv[1]
			else :
				noWeight[i][j] = 0
	
print(noWeight[N-1][W])
while True:
    (H,W) = [int(i) for i in inpput().split()]
    if H == W == 0:
        break
    
    for hc in range(H):
        for wc in range(W):
            if (hc + wc) % 2  == 0:
                print('#', end = ' ')
            else:
                print('.'.end=' ')
            print() 
        print()

### FIXED CODE ###

while True:
    (H, W) = [int(i) for i in input().split()]
 
    if H == W == 0:
        break
 
    for i in range(H):
        for r in range(W):
            if (i + r) % 2 == 0:
                print('#', end='')
            else:
                print('.', end='')
            #print('#', end='') if (i + r) % 2 == 0 else print('.', end='')
        print()
    print()
def d(tree, array, v):
  next_v = tree.get(v)
  
  for nv, nd in next_v:
    if array[nv] == -1:
      array[nv] = array[v] + nd
      d(tree, array, nv)
  

n = int(input())
tree = {}

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

array = [-1] * n
array[k] = 0

d(tree, array, k)

ans = []
for i in range(q):
  x, y = map(int, input().split())
  x -= 1
  y -= 1
  
  ans.append(array[x] + array[y])
  
for i in range(len(ans)):
  print(ans[i])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)

def d(tree, array, v):
  next_v = tree.get(v)
  
  for nv, nd in next_v:
    if array[nv] == -1:
      array[nv] = array[v] + nd
      d(tree, array, nv)
  

n = int(input())
tree = {}

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

array = [-1] * n
array[k] = 0

d(tree, array, k)

ans = []
for i in range(q):
  x, y = map(int, input().split())
  x -= 1
  y -= 1
  
  ans.append(array[x] + array[y])
  
for i in range(len(ans)):
  print(ans[i])
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    mod = 10**9+7
    # a_sum = sum(A)
    a_cum = [0] * (n+1)
    for i in range(n):
        a_cum[i + 1] = a_cum[i] + A[i]
    ans = 0
    for i in range(len(A)-1):
        ans += A[i] * (a_cum[n] - a_cum[i+1]) % mod
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

n = int(input())
A = [int(x) for x in input().split()]
mod = 10**9+7
# a_sum = sum(A)
a_cum = [0] * (n+1)
for i in range(n):
    a_cum[i + 1] = a_cum[i] + A[i]
ans = 0
for i in range(len(A)-1):
    ans += A[i] * (a_cum[n] - a_cum[i+1])
ans %= mod
print(ans)

### FIXED CODE ###

def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    mod = 10**9+7
    a_sum = sum(A)
    a_cum = [0] * (n+1)
    for i in range(n):
        a_cum[i + 1] = a_cum[i] + A[i]
    ans = 0
    for i in range(len(A)-1):
        ans += A[i] * (a_sum - a_cum[i+1]) % mod
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()
n=int(input())
t,a=map(int,input().split())
h=list(map(lambda x: abs(a-(t-int(x)*0.006)) ,input().split())
print(h.index(min(h))+1)

### FIXED CODE ###

n=int(input())
t,a=map(int,input().split())
ans=0
min=1000000000
h=list(map(int, input().split()))
for i in range(n):
  b=t-h[i]*0.006
  if min>abs(a-b):
    ans=i+1
    min=abs(a-b)
print(ans)