Harryxun/stf_run huggingface dataset:
x,y,a,b,c = (int(x) for x in input().split())

from bisect import insort

p_list = []
q_list = []
r_list = []

for value in input().split():
  value = int(value)
  if len(p_list) >= x:
    if p_list[-1*(x-1)-1] < value:
      insort(p_list,value)
      p_list = p_list[-1*(x+1)-1:]
  else:
    insort(p_list,value)

for value in input().split():
  value = int(value)
  if len(q_list) >= y:
    if q_list[-1*(y-1)-1] < value:
      insort(q_list,value)
      q_list = q_list[-1*(y+1)-1:]
  else:
    insort(q_list,value)
  
for value in input().split():
  value = int(value)
  if len(r_list) >= x+y:
    if r_list[-1*(x+y)-1] < value:
      insort(r_list.value)
      r_list = r_list[-1*(x+y+1)-1:]
  else:
    insort(r_list,value)
  
red = 0
green = 0
white = 0

sum_num = 0

for i in range(1,x+y+1):
  if red < x:
  	red_num = p_list[(red*-1)-1]
  else:
    red_num = 0
  if green < y:
  	green_num = q_list[(green*-1)-1]
  else:
    green_num = 0
  if white < c:
  	white_num = r_list[(white*-1)-1]
  else:
    white_num = 0
  
  max_p = max([red_num,green_num,white_num])
  sum_num += max_p
  if max_p == white_num:
    white += 1
  elif max_p == red_num:
    red += 1
  elif max_p == green_num:
    green += 1

print(sum_num)

### FIXED CODE ###

x,y,a,b,c = (int(x) for x in input().split())

from bisect import insort

p_list = list(map(int,input().split()))
q_list = list(map(int,input().split()))
r_list = list(map(int,input().split()))


p_list.sort()
q_list.sort()
r_list.sort()

red = 0
green = 0
white = 0

sum_num = 0

for i in range(1,x+y+1):
  if red < x:
  	red_num = p_list[(red*-1)-1]
  else:
    red_num = 0
  if green < y:
  	green_num = q_list[(green*-1)-1]
  else:
    green_num = 0
  if white < c:
  	white_num = r_list[(white*-1)-1]
  else:
    white_num = 0
  
  max_p = max([red_num,green_num,white_num])
  sum_num += max_p
  if max_p == white_num:
    white += 1
  elif max_p == red_num:
    red += 1
  elif max_p == green_num:
    green += 1

print(sum_num)
print(chr(ord(str(input())+1)))

### FIXED CODE ###

print(chr(ord(str(input()))+1))
from collections import defaultdict
n, m = map(int, input().split())
switch = defaultdict(list)
for i in range(m):
    s = list(map(int, input().split()))[1:]
    switch[i] = s
p = list(map(int, input().split()))

output = 0
for h in range(2**n):
    flag = 1
    padding = f'0{n}b'
    bit = format(h, padding)
    for i, v in enumerate(p):
        cnt = 0
        for j in switch[i]:
            if bit[j-1] == '1':
                cnt += 1
        if cnt % 2 != v:
            flag = 0
    if flag == 1:
        output += 1
print(output)


### FIXED CODE ###

from collections import defaultdict
n, m = map(int, input().split())
switch = defaultdict(list)
for i in range(m):
    s = list(map(int, input().split()))[1:]
    switch[i] = s
p = list(map(int, input().split()))

output = 0
for h in range(2**n):
    flag = 1
    padding = '0{}b'.format(n)
    bit = format(h, padding)
    for i, v in enumerate(p):
        cnt = 0
        for j in switch[i]:
            if bit[j-1] == '1':
                cnt += 1
        if cnt % 2 != v:
            flag = 0
    if flag == 1:
        output += 1
print(output)
ans = [1,2,3]
remove(int(input()))
remove(int(input()))

print(ans)

### FIXED CODE ###

ans = [1,2,3]
a = int(input())
b = int(input())
ans.remove(a)
ans.remove(b)

print(ans[0])
# M回の操作終了後に N枚のカードに書かれた整数の合計の最大値を求めてください。
# で操作はB_j 枚以下の任意のカードをC_jに置き換えるという処理ができる。
# つまり、元のカードの値Aをソートして、小さいものから順にC_jの大きいもので並び替えれば良い
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b_c = [list(map(int,input().split())) for _ in range(m)]
b_c.sort(key = lambda x:x[1], reverse=True) # c でソートする
pos = 0
ans = sum(a)
for i in range(m): # 一応最後までb_c をループするようにして、c よりも元のカードが大きくなったらbreakする
  if a[pos + b_c[i][0] - 1] > b_c[i][1]:
    for j in range(b_c[i][0]): #　何番目までは入れ替えた方が特か判定
      if a[pos + j] > b_c[i][1] or pos + j >= n:
        break
      else:
        ans += b_c[i][1] - a[pos + j] # 置き換えによる増加量
    break
  else:
    for j in range(b_c[i][0]): #　
      ans += b_c[i][1] - a[pos + j]
    pos += b_c[i][0]
print(ans)
# 最初はエラー : b_c[i][0]をb_c[0]でやっていたから
# 次は値がおかしい。sortがb_cは逆順（大きいものから順に）にする必要がある
# そのためには, reverse=True を入れる
# しかし、これでも入力例2で異なる答え、入力例4でエラーが出る。


### FIXED CODE ###

#!/usr/bin/env python3
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = [0]*m
c = [0]*m
for i in range(m):
    b[i],c[i] = map(int,input().split())
c,b = zip(*sorted(zip(c,b)))#c でソートする
# 整数列a からmin からc にb枚まで帰る操作を繰り返した時のsumのmaxを求める
# C の大きい順から、Nを超えないまで並べていく
# もし、そのtotalがN を超える場合は、そのできた配列とaをソートしたものを比べて、
# aをソートしたものの方が大きいところがあれば修正する
# もしtotla がNを超えないなら、小さい順から置き換えたもののそのままでOK
# 実装としては、ソートしたaを前から順番にc[i]より大きいか比べていく
cb = 0
idx = 0
for i in range(n):
    if cb == m:break
    else:
        if a[i] < c[m-1-cb]:a[i] = c[m-1-cb]
        idx += 1
        if idx == b[m-1-cb]:
            idx = 0
            cb += 1
print(sum(a))
import numpy as np
N = int(input())

edge = np.zeros((N,N))
color = [0] * (N)

for i in range(N-1) :
    u , v , w = map(int,input().split())
    edge[u-1,v-1] = w
    edge[v-1,u-1] = w

stack = [(0,0)] # (頂点 , 距離)

while len(stack) > 0 :
    v , d = stack.pop()

    if d % 2 == 0 :
        color[v] = '1'
    else :
        color[v] = '0'

    for u , w in enumerate(edge[v]) :
        if w > 0 and color[u] == 0 :
            stack.append((u,d+w))

for i in color :
    print(i)

### FIXED CODE ###

from collections import deque

N = int(input())

edge = [[] for _ in range(N)]
check = [False] * N
dist = [0] * N

for i in range(N-1) :
    u , v , w = map(int,input().split())
    edge[u-1].append((v-1,w))
    edge[v-1].append((u-1,w))

q = deque([0])

while q :
    current = q.popleft()
    if check[current] :
        continue

    check[current] = True
    for ad , w in edge[current] :
        if not check[ad] :
            q.append(ad)
            dist[ad] = dist[current] + w

for w in dist :
    print(w % 2)
a,b,c=map(int,input().split())
ans=a[0]+b[0]+c[0]
print(ans)

### FIXED CODE ###

a,b,c=map(str,input().split())
ans=a[0]+b[0]+c[0]
print(ans)
def isOver(a,b):
    return True if (a[0]-b[0])**2 + (a[1]-b[1])**2 <= 4.0 else False
 
def largestGroup(mtrx,num):
    mx = 1
    ls = [num]
    for i in mtrx[num]:
        if i == num:
            continue
        m = youKnow(mtrx,ls,i)
        mx = max(mx,m)
    return mx
 
def youKnow(mtrx,ls,num):
    mx = len(ls)
    if set(ls) <= set(mtrx[num]):
        if num not in ls:
            ls.append(num)
        for i in list(set(mtrx[num])-set(ls)):
            m = youKnow(mtrx,ls,i)
            mx = max(mx,m)
    return mx
 
while True:
    print "OK"
    max_over = 0
    n = int(raw_input())
    if n == 0: break
    seals = [map(float, raw_input().split(",")) for i in range(n)]
    overs = []
    for i in range(n):
        over = []
        for j in range(n):
            if isOver(seals[i],seals[j]):
                over.append(j)
        overs.append(over)
         
    ref = [i for i in range(n)]
    for i in ref:
        num_over = largestGroup(overs,i)
        for j in overs[i]:
            ref.remove(j)
        if num_over > max_over:
            max_over = num_over
    print max_over

### FIXED CODE ###

def isOver(array,x,y):
	return True if (array[0]-x)**2+(array[1]-y)**2 <= 1.01 else False
	
while True:
    mx = 0
    n = int(raw_input())
    if n == 0: break
    seals = [map(float, raw_input().split(",")) for i in range(n)]
    x = 0
    while x < 10.0:
    	y = 0.0
    	while y < 10.0:
    		num = 0
    		for seal in seals:
    			if isOver(seal,x,y):
    				num += 1
    		mx = max(mx,num)
    		y += 0.1
        x += 0.1
    print mx
from fractions import gcd
from math import gcd

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

M = max(A)

g = A[0]
for a in A:
    g = gcd(g, a)

if K <= M and K % g == 0:
    print ('POSSIBLE')
else:
    print ('IMPOSSIBLE')

### FIXED CODE ###

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

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

n = A[0]
for i in A:
    n = gcd(n, i)

flag = False
for i in A:
    if i >= K and (i - K) % n == 0:
        flag = True
        break
    else:
        pass

if flag:
    print ('POSSIBLE')
else:
    print ('IMPOSSIBLE')
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll (i)=0;(i)<(n);(i)++)

bool is(string s, int i, int j) {
    for (int l = 0; l <= j - i; l++) {
        if (s[l + i] != s[j - l]) {
            return false;
        }
    }
    return true;
}

int main() {
    string s;
    cin >> s;
    int n;
    n = s.size();
    if (is(s, 0, (n - 1) / 2 - 1) && is(s, 0, n - 1) && is(s, (n + 3) / 2 - 1, n - 1)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

### FIXED CODE ###

s = input()

def isk(s):
    n = len(s)
    for i in range(n):
        if s[i] != s[n - 1 - i]:
            return False
    return True
n = len(s)
if isk(s) and isk(s[:(n - 1) // 2]) and isk(s[(n + 3) // 2 - 1:]):
    print('Yes')
else:
    print("No")
pass1 = str(input())
    pass2 = str(input())
    
    pass2_org = pass2[0:-1]
    
    if pass1 == pass2_org:
        print(f'Yes')
    else:
        print(f'No')

### FIXED CODE ###

pass1 = str(input())
pass2 = str(input())
  
pass2_org = pass2[0:-1]
  
if pass1 == pass2_org:
    print(f'Yes')
else:
    print(f'No')
s=list(map(int,input().split())
for i in range(5):
  if s[i]==0:
     print(i+1)
     exit()
  else:
     pass

### FIXED CODE ###

a=[]
a=input().split()
for i in range(5):
 if a[i]=='0':
   print(str(i+1))
 else:
   pass
card ={'S': [0]*13,
       'H': [0]*13,
       'C': [0]*13,
       'D': [0]*13
}

n = int(input())

for i in range(1,n+1):
    m,num = input().split()
    num = int(num)
    card[m][num-1] =1

for c in ["S","H","C","D"]:
    for j in range(1,14):
        if (card[c][i]==0):
            print(m,str(j))


### FIXED CODE ###

card ={'S': [0]*13,
       'H': [0]*13,
       'C': [0]*13,
       'D': [0]*13
}

n = int(input())

for i in range(1,n+1):
    m,num = input().split()
    num = int(num)
    card[m][num-1] =1

for c in ["S","H","C","D"]:
    for j in range(1,14):
        if (card[c][j-1]==0):
            print(c,str(j))
n = int(input())
a = list(map(int,input().split()))
l = sum(a)
b = list()
t = 0
ans = 10**10
for i in a:
    t += i
    n.append(t)
for j in b:
    x = abs(l-(2*j))
    if x < ans:
        ans = x

print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
l = sum(a)
b = list()
t = 0
ans = 10**10
for i in a:
    t += i
    b.append(t)
for j in b:
    x = abs(l-(2*j))
    if x < ans:
        ans = x

print(ans)
N,K = map(int,input().split())
S = input()

h = 0
for i in range(len(S)-1):
  if s[i] == S[i+1]:
    h += 1
h += 2*K
print(min(N-1, h))


### FIXED CODE ###

N,K = map(int,input().split())
S = input()

h = 0
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    h += 1
h += 2*K
print(min(N-1, h))
n, x = map(int, input().split())
c = list(map(int, input().split()))
c = set([abs(x-c[i]) for i in range(n)])
l = min(c)
f = set()
for i in range(1, l+1):
    if l % i == 0:
        f.add(i)
for i in range(len(f), 0, -1):
    d = True
    for item in c:
        if item % i != 0:
            d = False
    if d:
        print(i)
        break

### FIXED CODE ###

a, b = map(int, input().split())
if (a*b)%2 == 0:
    print("No")
else:
    print("Yes")
# (10-x) ways: (0,x)-(9-x,9) -> (-x, x)
# (x) ways:    (10-x,0)-(9,x-1) -> (10-x, -10 + x)

def solve(D):

  leading_zeros = 0
  while D[-1] == 0:
    D.pop()
    leading_zeros += 1

  r = 1
  if len(D) >= 2:
    h,t = D.popleft(), D.pop()
    c = h + t

    if not D:
      r = t - (leading_zeros == 0) if c == 9 else 0
    elif 9 <= c <= 10:
      r = t - (leading_zeros == 0)
      c -= 10
      D[0] += c*10
      D[-1] += 1
      i = len(D)-1
      while i > 0 and D[i] == 10:
        D[i] = 0
        D[i-1] += 1
        i -= 1

  while len(D) > 2:
    h,t = D.popleft(), D.pop()
    c = h + t

    if -1 <= c <= 0:
      r *= 10-t
      D[0] += c*10
    elif 9 <= c <= 10:
      r *= t
      c -= 10
      D[0] += c*10
      D[-1] += 1
      i = len(D)-1
      while i > 0 and D[i] == 10:
        D[i] = 0
        D[i-1] += 1
        i -= 1
    else:
      r = 0
      D.clear()

  if len(D) == 2:
    h,t = D.popleft(), D.pop()
    c = h + t
    if c == 0:
      r *= 10 - t
    elif c == 9:
      r *= t
    else:
      r = 0

  if len(D) == 1:
    r *= 10 if D[0] == 0 else 0

  if r != 0 and leading_zeros > 0:
    r *= 9
    r *= 10**(leading_zeros-1)

  return r


from collections import deque
from random import randint


D = deque(map(int,input()))
r = solve(D.copy())

Q = D.copy()
for d in D:
  Q.appendleft(0)
  temp = solve(Q.copy())
  r += temp

if r == 0:
  Q = D.copy()
  for d in D:
    Q.append(0)
    r = solve(Q.copy())
    if r != 0:
      break

print(r)

### FIXED CODE ###

# (10-x) ways: (0,x)-(9-x,9) -> (x, -x)           <- This should never happens when D > 0
# (x) ways:    (10-x,0)-(9,x-1) -> (x-10, 10 - x)

def solve(d, k, outer):
  if k <= 1:
    return 10**k if d == 0 else 0
  # if d >= 10**k:
  #   return 0

  t = (-d)%10 # 10-d%10 doesn't work when d = 10
  d -= t*10**(k-1) - t
  return (10-t-outer)*solve(abs(d//10), k-2, 0)

D = int(input())
result = 0
for k in range(1,20):
  result += solve(D, k, 1)

print(result)
N_M = list(map(int, input().split()))
N = N_M[0]
M = N_M[1]
dis = []
for _ in range(M):
    dis.append(input())

dp = [0 for i in range(N+2)]
dp[0] = 1
if 1 in dis:
    dp[1] = 0
else :
    dp[1] = 1

for i in range(N):
    if i+2 in dis:
        dp[i+2]=0
    else:
        if i in dis :
            dp[i+2]=dp[i+1]
        if i+1 in dis :
            dp[i+2]=dp[i]
        else :
            dp[i+2]=dp[i]+dp[i+1]

print(dp[N])

### FIXED CODE ###

input_time = list(map(int, input().split()))
input_time_sort = sorted(input_time)
print(input_time_sort[0]+input_time_sort[1])
a,b,c=map(str,input().split())
d,e,f=map(str,input().split())
ans="NO"
if a==f and b==e and c==d:
  ans="YES"
print(ans)

### FIXED CODE ###

a = input()
b = input()
if a[0]==b[2] and a[1]==b[1] and a[2]==b[0]:
  print("YES")
else:
  print("NO")
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from Queue import Queue


def main():
    num = int(stdin.readline())

    L = []
    for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()[2:]])

    d = [-1] * num
    d[0] = 0
    q = Queue()javascript:void(0)
    q.put(0)
    while not q.empty():
        u = q.get()
        for v in L[u]:
            if d[v-1] < 0:
                d[v-1] = d[u] + 1
                q.put(v-1)

    for i, v in enumerate(d):
        print(i+1, v)


main()

### FIXED CODE ###

#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
from Queue import Queue


def main():
    num = int(stdin.readline())

    L = []
    for _ in xrange(num):
        L.append([int(s) for s in stdin.readline().split()[2:]])

    d = [-1] * num
    d[0] = 0
    q = Queue(100)
    q.put(0)
    while not q.empty():
        u = q.get()
        for v in L[u]:
            if d[v-1] < 0:
                d[v-1] = d[u] + 1
                q.put(v-1)

    for i, v in enumerate(d):
        print(i+1, v)


main()
N,X = map(int, input().split())
D=0
L=list(map(int, input().split()))
i=0
while (D<=X):
  D+=L[i]
  i+=1
  if i>N:
    break
print(i)
  
  


### FIXED CODE ###

N,X = map(int, input().split())
D=0
L=list(map(int, input().split()))
i=0
while (D<=X)and(i<N+1):
  if (i<N):
    D+=L[i]
  i+=1
#  if i>N:
 #   break
print(i)
N, M = map(int, input().split())
keta = ['?']*N

for _ in range(M):
    s, c = map(int, input().split())        
    if keta[s-1] == '?' or keta[s-1] == c:
        keta[s-1] = c
    else:
        return -1
if keta[0] == 0:
    return -1

keta = [0 if num == '?' else num for num in keta]

print(''.join(map(str, keta)))

### FIXED CODE ###

def check():
    N, M = map(int, input().split())
    keta = ['?']*N
    
    for _ in range(M):
        s, c = map(int, input().split())      
        if keta[s-1] == '?' or keta[s-1] == c:
            keta[s-1] = c
        else:
            return -1
    if keta[0] == 0 and N !=1:
        return -1
    
    keta = [0 if num == '?' else num for num in keta]
    
    if N == 1:
        return keta[0]
    
    keta = [1 if i==0 and num==0 else num for i,num in enumerate(keta)]
    
    return ''.join(map(str, keta))
  
print(check())
import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
answer="No"

#文字が全部0
if all(a==0 for a in A):
  answer="Yes"

#0aa0aaという並びに出来る
#0がN/3個,aが2N/3個で数字は二種類
elif len(c)==2 and N%3==0:
  if all(AA[:third]==0):
    answer="Yes"
     
#abc,abc...,abcという並びに出来る
#aがN/3個,bがN/3個,cがN/3個で数字は三種類
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    if bin(AA[0]^AA[third])==bin(AA[2*third]) and \
    (AA[third]^AA[2*third])==bin(AA[0]) and \
    (AA[2*third]^AA[0])==bin(AA[third]):
      answer="Yes"
    
print(answer)


### FIXED CODE ###

import collections
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(A)
c=collections.Counter(A)
third=N//3
answer="No"

#文字が全部0
if all(a==0 for a in A):
  answer="Yes"

#0aa0aaという並びに出来る
#0がN/3個,aが2N/3個で数字は二種類
elif len(c)==2 and N%3==0:
  if all(a==0 for a in AA[:third]):
    answer="Yes"
     
#abc,abc...,abcという並びに出来る
#aがN/3個,bがN/3個,cがN/3個で数字は三種類
elif len(c)==3 and N%3==0:
  if A.count(AA[0])==third and \
  A.count(AA[third])==third and \
  A.count(AA[2*third])==third:
    if bin(AA[0]^AA[third])==bin(AA[2*third]) and \
    bin(AA[third]^AA[2*third])==bin(AA[0]) and \
    bin(AA[2*third]^AA[0])==bin(AA[third]):
      answer="Yes"
    
print(answer)
n, m = map(int, input().split())
ship = []
for i in range(m):
    ship[i] = tuple(map(int, input().split()))

for i in range(m):
    if ship[i][0] == 1:
        for j in range(i+1, m):
            if ship[i][1] == ship[j][0] and ship[j][1] == n or ship[i][1] == ship[j][1] and ship[j][0] == n:
                print("POSSIBLE")
                exit()
    elif ship[i][1] == 1:
        for j in range(i+1, m):
            if ship[i][0] == ship[j][0] and ship[j][1] == n or ship[i][0] == ship[j][1] and ship[j][0] == n:
                print("POSSIBLE")
                exit()

print("IMPOSSIBLE")


### FIXED CODE ###

n, m = map(int, input().split())
ship_1 = [False]*(n+1)
ship_n = [False]*(n+1)
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        ship_1[b] = True
    elif b == n:
        ship_n[a] = True

for i in range(len(ship_1)):
    if ship_1[i] and ship_n[i]:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")
kazulist = []
for i in range(100):
    kazulist.append(i+1)

a = list(input().split(" "))
target = int(a[0])
syokyo = int(a[1])

b = list(input().split(" "))
for i in b:
    kazulist.pop(int(i))

saisyosa = 100
kotae = 0
for i in kazulist:
    sa = target - int(i)
    if sa < 0:
        sa *= -1
    if sa < saisyosa:
        saisyosa = 0
        kotae = i

print(i)


### FIXED CODE ###

kazulist = []
for i in range(-100,200):
    kazulist.append(i)
 
a = list(input().split(" "))
target = int(a[0])
syokyo = int(a[1])

if syokyo != 0:
    b = list(input().split(" "))
    for i in b:
        kazulist.remove(int(i))
 
saisyosa = 100
kotae = 0
for i in kazulist:
    sa = target - int(i)
    #print(sa)
    if sa < 0:
        sa *= -1
    if sa < saisyosa:
        saisyosa = sa
        kotae = i
 
print(kotae)
N, Q = map(int, input().split())
A = [''] * (N+1)
C = [0] * (N+1)
for i in range(N-1):
  a, b = map(int, input().split())
  if len(A[a]) == 0:
    A[a] = [b]
  else:
    A[a].append(b)

def AddPX(n, x):
  C[n] += x
  for i in A[n]:
    AddPX(i, x)
  
for i in range(Q):
  p, x = map(int, input().split())
  AddPX(p, x)
print (" ".join(map(str, C[1:])))

### FIXED CODE ###

from collections import deque
from collections import defaultdict
N, Q = map(int, input().split())
C = [0]* N
D = defaultdict(set)
for i in range(N-1):
  a, b = map(int, input().split())
  D[a-1].add(b-1)
  D[b-1].add(a-1)
for i in range(Q):
  p, x = map(int, input().split())
  C[p-1] += x

Q = deque([])
Q.append(0)
vstd = set()

while len(Q)>0:
  a = Q.popleft()
  vstd.add(a)
  for b in D[a]:
    if b in vstd:
      continue
    C[b] += C[a]
    Q.append(b)

print (" ".join(map(str, C)))
// space 区切りの文字を入力として、Yが存在すれば、Four, else Threeを出力

#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  char s[n]; // 配列の初期化はs[n] n：要素数
  int ans = 0; // if ans == 0, Three
  for (int i=0;i < n ;i++){
    cin >> s[i];
    //cout << s[i];
    //charで比較するときは''にする、""だと文字列
    if ( s[i] == 'Y' ){
      ans = 1;
      break;
    }
  }
  if ( ans == 0){
    cout << "Three" << endl;
  }
  else{
    cout << "Four" << endl;
  }
}
        


### FIXED CODE ###

n = int(input())
s = list(map(str,input().split()))
ans = 0
for i in range(len(s)):
    if s[i] == "Y":
        ans = 1
        break
if ans == 0:
    print("Three")
else:
    print("Four")
l = raw_input().split()
Q = int(l[0])
X = []
D = []
N = []
for i in range(Q):
    l = raw_input().split()
    X.append(int(l[0]))
    D.append(int(l[1]))
    N.append(int(l[2]))

# print(Q, X, D, N)

for i in range(Q):
    x = X[i]
    d = D[i]
    n = N[i]
    cds = [0]*n
    cds[0] = 1
    cds_tmp = [0]*n
    ans = x
    # print(x, d, n)
    for j in range(1, n):
      #  print('j={}'.format(j), cds)
        cds_tmp[0] = cds[0]
        for k in range(1, j + 1):
            cds_tmp[k] += cds[k - 1] * j
            cds_tmp[k] %= 1000003
     #       print(k, cds[k - 1], cds_tmp)
        cds = [c for c in cds_tmp]
    ans = 0
    for i in range(n):
        ans += x**(n - i) * cds[i] * (d**i)
        ans %= 1000003
    print(ans)


### FIXED CODE ###

mod = 10**6 + 3

fac = [0]*mod
fac[0] = 1
for i in range(1, mod):
    fac[i] = fac[i - 1] * i
    fac[i] %= mod

def gcd(a, b):
    def calc(a, b, first, second):
        if a < b:
            a, b = b, a
        r = a % b
        q = -(a - r)//b
        if r == 0:
            return b, second
        # first += q * second
        first = [x + q * y for (x, y) in zip(first, second)]
        return calc(r, b, second, first)
    first = [1, 0]
    second = [0, 1]
    return calc(a, b, first, second)

def mod_inv(n, mod):
    table = gcd(n, mod)
    inv = table[1][1]
    if inv < 0:
        inv += mod
    return inv

def mod_pow(x, n, mod):
    ret = 1
    while n > 0:
        if n & 1 != 0:
            ret *= x
            ret %= mod
        x *= x
        x %= mod
        n >>= 1
    return ret

l = input().split()
Q = int(l[0])
X = []
D = []
N = []
for i in range(Q):
    l = input().split()
    X.append(int(l[0]))
    D.append(int(l[1]))
    N.append(int(l[2]))


for i in range(Q):
    x = X[i]
    d = D[i]
    n = N[i]
    if d == 0:
        print(mod_pow(x, n, mod))
        continue
    inv_d = mod_inv(d, mod)
    x_d = (x * inv_d) % mod
    # print(i, x, d, n, inv_d, x_d, x_d + n - 1)
    if x_d + n - 1 >= mod:
        print(0)
        continue
    ans1 = fac[x_d + n - 1]
    ans2 = fac[x_d - 1]
    # print(ans1, ans2)
    ans = ans1 * mod_inv(ans2, mod)
    ans %= mod
    d_n = mod_pow(d, n, mod)
    ans = ans * d_n
    ans %= mod
    print(ans)
n=(int)(input())
a=[]
for i in range(2, n):
  temp = i ** 2
  while(temp <= n):
    a.append(temp)
    temp *= i
a = sorted(set(a))
#print(a)
print(list(i for i in a if i <= n)[-1])

### FIXED CODE ###

n=(int)(input())
a=[1]
for i in range(2, n):
  temp = i ** 2
  while(temp <= n):
    a.append(temp)
    temp *= i
a = sorted(set(a))
#print(a)
print(list(i for i in a if i <= n)[-1])
import math
N,X=[int(i) for i in input().split()]
a=[abs(int(i)-X) for i in input().split()]
c=max(a)
for i in range(len(a)):
    c=math.gcd(c,a[i])
print(c)

### FIXED CODE ###

from fractions import gcd
from functools import reduce
 
N,X=map(int, input().split())
x=map(int, input().split())

lis=[abs(j-X) for j in x]

print(reduce(gcd,lis))