Harryxun/stf_run huggingface dataset:
a = [list(map(int, input().split())) for i in range(3)]
output =[[0,0,0],[0,0,0],[0,0,0]]
n = int(input())
for k in range(n):
    b=int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j]==b:
                output[i][j]=1
for i in range(3):
    if output[i][0]*output[i][1]*output[i][2]==1:
        check=True
    elif output[0][i]*output[1][i]*output[2][i]==1:
        check=True
if output[0][0]*output[1][1]*output[2][2]==1:
    check=True
elif output[2][0]*output[1][1]*output[0][2]==1:
    check=True
if check==True:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

a = [list(map(int, input().split())) for i in range(3)]
output =[[0,0,0],[0,0,0],[0,0,0]]
n = int(input())
check=False
for k in range(n):
    b=int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j]==b:
                output[i][j]=1
for i in range(3):
    if output[i][0]*output[i][1]*output[i][2]==1:
        check=True
    elif output[0][i]*output[1][i]*output[2][i]==1:
        check=True
if output[0][0]*output[1][1]*output[2][2]==1:
    check=True
elif output[2][0]*output[1][1]*output[0][2]==1:
    check=True
if check==True:
    print('Yes')
else:
    print('No')
import math
n = int(input())
a = list(map(int,input().split()))

right_gcd = [0]*(n)
left_gcd = [0]*(n)
right_gcd[n-1] = a[n-1]
left_gcd[0] = a[0]

for i in range(n-1,0,-1):
    right_gcd[i-1] = math.gcd(right_gcd[i],a[i-1])

for i in range(n-1):
    left_gcd[i+1] = math.gcd(left_gcd[i],a[i+1])

gcd = [0]*n
for i in range(n):
    if i == 0:
        gcd[i] = right_gcd[1]
    elif i == n-1:
        gcd[i] = left_gcd[n-2]
    else:
        gcd[i] = math.gcd(left_gcd[i-1],right_gcd[i+1])

print(max(gcd))


### FIXED CODE ###

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

def gcd(a,b):
    while b != 0:
        a,b = b,a%b
    return a

right_gcd = [0]*(n)
left_gcd = [0]*(n)
right_gcd[n-1] = a[n-1]
left_gcd[0] = a[0]

for i in range(n-1,0,-1):
    right_gcd[i-1] = gcd(right_gcd[i],a[i-1])

for i in range(n-1):
    left_gcd[i+1] = gcd(left_gcd[i],a[i+1])

except_gcd = [0]*n
for i in range(n):
    if i == 0:
        except_gcd[i] = right_gcd[1]
    elif i == n-1:
        except_gcd[i] = left_gcd[n-2]
    else:
        except_gcd[i] = gcd(left_gcd[i-1],right_gcd[i+1])

print(max(except_gcd))
a = list(map(int, input().split()))
s = sorted(a).reverse
ans = [s[i+1]-s[i] for i in range(2)]
print(sum(ans))

### FIXED CODE ###

a = list(map(int, input().split()))
s = sorted(a, reverse=True)
ans = [s[i]-s[i+1] for i in range(2)]
print(sum(ans))
N = int(input())
S = str(input())
RGB = [0] * 3
for i in range(N):
  if S[i] == "R":
    RGB[0] += 1
  elif S[i] == "G":
    RGB[1] += 1:
  else:
    RGB[2] += 1
    
ans = RGB[0] * RGB[1] * RGB[2]

for i in range(1, 2000):
  for j in range(1, N + 1):
    if (j + 2 * i) <= N:
      if S[j - 1] != S[j + i - 1]:
        if S[j + 2 * i - 1] != S[j + i - 1]:
          if S[j - 1] != S[j + 2 * i - 1]:
            ans -= 1
            
print(max(ans, 0))
  

### FIXED CODE ###

N = int(input())
S = str(input())
R, G, B = 0, 0, 0
for i in range(N):
  if S[i] == "R":
    R += 1
  elif S[i] == "G":
    G += 1
  else:
    B += 1
    
ans = R * G * B 

for i in range(1, 2000):
  for j in range(1, N - 2 * i + 1):
    if S[j - 1] != S[j + i - 1]:
      if S[j + 2 * i - 1] != S[j + i - 1]:
        if S[j - 1] != S[j + 2 * i - 1]:
          ans -= 1
            
print(max(ans, 0))
def main():
    n = int(input())
    res = 0

    for (a, k) in [[int(x) for x in input().split()] for _ in range(n)]:
        while a >= k:
            m, u, v = a // k, (a - k * m), (m + 1)
            if a % k == 0 or u % v == 0:
                res ^= m
                break
            x = (u // v)
            a -= (x + 1) * v

    print('Takahashi' if res != 0 else 'Aoki')


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n, m = map(int, input().split())
    print(compute(min(n, m), max(n, m)))


def compute(n, m):
    if n == 1 and m == 1:
        return 1
    if n == 1:
        return max(0, m - 2)
    return (n - 2) * (m - 2)


if __name__ == "__main__":
    main()
# -*- coding: utf-8 -*-
 
n = int(input())
a =list(map(int, input().split()))

N = sum(a)
r = float('inf')
x = 0

for i in range(N-1):
    x += a[i]
    y = N - x
    if r > abs(x -y):
        r = abs(x -y)
print(r)

### FIXED CODE ###

# -*- coding: utf-8 -*-
 
n = int(input())
a =list(map(int, input().split()))

N = sum(a)
r = float('inf')
x = 0
 
for i in range(n-1):
    x += a[i]
    y = N - x
    if r > abs(x -y):
        r = abs(x -y)
print(r)
import fraction
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

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

for i in range(n):
    max = gcd_list(a[-i])
    if max > ans:
        ans = max
        
print(ans)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from fractions import gcd

n, *a = map(int, read().split())
b = a[::-1]
cumsum_m = [0] * (n - 1)
cumsum_p = [0] * (n - 1)
cumsum_m[0] = b[0]
cumsum_p[0] = a[0]
for i in range(1, n - 1):
    cumsum_p[i] = gcd(cumsum_p[i - 1], a[i])
    cumsum_m[i] = gcd(cumsum_m[i - 1], b[i])
ans = max(cumsum_m.pop(), cumsum_p.pop())
for p, m in zip(cumsum_p, cumsum_m[::-1]):
    v = gcd(p, m)
    if ans < v:
        ans = v
print(ans)
n, k = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
print(len([x for x in h if x >= k])

### FIXED CODE ###

N = float(input())
if N % 2 == 0:
  print(1/2)
else:
  print((N+1)/(2*N))
n,q = input().split()
n = int(n)
q = int(q)
T = [0] * (n+1)
A = [0] * (n+1)
B = [0] * (n+1)
P = [0] * (q+1)
X = [0] * (q+1)
to = [] * n+1
cnt = [[] for i in range(n+1)] 
for i in range(1,n):
    A[i],B[i] = [int(j) for j in input().split()]
    to[A[i]].append(B[i])
    to[B[i]].append(A[i])
for i in range(1,q+1):
    P[i],X[i] = [int(j) for j in input().split()]
    T[P[i]] = X[i]
NIL = -1

q =deque()
q.append((1,0,NIL))
while len(q)>0:
    p,x,prev = q.pop()
    x += T[p]
    cnt[p] = x
    for i in to[p]:
        if i != prev:
            q.append((i,x,p))

print(*cnt)


### FIXED CODE ###

from collections import deque

n,q = input().split()
n = int(n)
q = int(q)
T = [0] * (n+1)

to = [[] for i in range(n+1)]
cnt = [0] * (n)
for i in range(1,n):
    a,b = [int(j) for j in input().split()]
    to[a].append(b)
    to[b].append(a)
for i in range(1,q+1):
    P,X = [int(j) for j in input().split()]
    T[P] += X
NIL = -1

q =deque()
q.append((1,0,NIL))
while len(q)>0:
    p,x,prev = q.pop()
    x += T[p]
    cnt[p-1] = x
    for i in to[p]:
        if i != prev:
            q.append((i,x,p))
print(*cnt)
N = int(input())

x_list=[]
y_list=[]
h_list=[]

for i in range(N):
	x,y,h=map(int, input().split())
	x_list.append(x)
	y_list.append(y)
	h_list.append(h)

i = -1	
for h in h_list:
	i += 1
	if h >= 1:
		H = abs(cx - x_list[i])+abs(cy - y_list[i])+h
		break
		
for cy in range(101):
	for cx in range(101):
		for i in range(N):
			h = max(H-abs(cx - x_list[i])-abs(cy - y_list[i]), 0)
			H_list.append(h) 
			if h != H:
				break 
		if len(H_list) == N:
			print(str(cx)+' '+str(cy)+' '+str(H_list[0]))
			break		
	else:
		continue
	break

### FIXED CODE ###

N = int(input())

x_list=[]
y_list=[]
h_list=[]


def all_same(items):
	return all(map(lambda x: x == items[0], items))

for i in range(N):
	x,y,h=map(int, input().split())
	x_list.append(x)
	y_list.append(y)
	h_list.append(h)
		
for cy in range(101):
	for cx in range(101):
		n = -1	
		for h in h_list:
			n += 1
			if h >= 1:
				H = abs(cx - x_list[n])+abs(cy - y_list[n])+h
				h_now_list=[]
				break
		for i in range(N):
			h_now = max((H-abs(cx - x_list[i])-abs(cy - y_list[i])), 0)
			h_now_list.append(h_now)
			if h_now != h_list[i]:
				break	
			else:
				if len(h_now_list)==N:
					print(str(cx)+' '+str(cy)+' '+str(H))
					break
	else:
		continue
	break
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import combinations
from collections import Counter
def main():
    n=int(input())
    XY=[tuple(map(int,input().split())) for i in range(n)]
    lis=list(combinations(XY,2))
    PQ=[]
    for l in lis:
        if l[0][0]<l[1][0]:
            PQ.append((l[1][0]-l[0][0],l[1][1]-l[0][1]))
        else:
            PQ.append((l[0][0]-l[1][0],l[0][1]-l[1][1])) 
    x=Counter(PQ).most_common(1)[0][1]
    print(n-x)

if __name__=='__main__':
    main()

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import combinations
from collections import Counter
def main():
    n=int(input())
    if n==1:
        print(1)
        sys.exit()
    XY=[tuple(map(int,input().split())) for i in range(n)]
    XY.sort()
    lis=list(combinations(XY,2))
    PQ=[]
    for l in lis:
        PQ.append((l[1][0]-l[0][0],l[1][1]-l[0][1]))
    x=Counter(PQ).most_common(1)[0][1]
    print(n-x)

if __name__=='__main__':
    main()
N = int(input())
res = 0
for i in range(1,N+1):
    if i%15==0:
        dp = 0
    elif i%5==0:
        dp = 0
    elif i%3==0:
        dp = 0
    else :å
        dp = i
    res = res+dp
print(res)

### FIXED CODE ###

N = int(input())
res = 0
for i in range(1,N+1):
    if i%15==0:
        dp = 0
    elif i%5==0:
        dp = 0
    elif i%3==0:
        dp = 0
    else :
        dp = i
    res = res+dp
print(res)
N = int(input())
if N % 2 == 0:
    print(N // 2, N, N)
for h in range(1, 3500+1):
    hN = h * N
    for n in range(h, 3500+1):
        b = (4 * h * n - n * N - hN)
        if b > 0:
            continue
        a = (n * hN)
        if a % b == 0:
            print(h, n, a // b)
            quit()


### FIXED CODE ###

N = int(input())
if N % 2 == 0:
    print(N // 2, N, N)
    quit()
for h in range(1, 3500+1):
    hN = h * N
    for n in range(h, 3500+1):
        b = (4 * h * n - n * N - hN)
        if b <= 0:
            continue
        a = (n * hN)
        if a % b == 0:
            print(h, n, a // b)
            quit()
N = int(input())
p_list  = list(map(int,input().strip().split(" ")))

c = 1
if p_list == [p_list[0]]*N:
    print(len(p_list))

elif p_list == sorted(p_list):
    print(1)

elif p_list == sorted(p_list, reverse=True):
    print(len(p_list))

else:
    for i in range(1, N):
        p_list_min = min(p_list[:i])
            if p_list[i] <= p_list_min:
                c += 1
        

print(c)


### FIXED CODE ###

N = int(input())
p_list  = list(map(int,input().strip().split(" ")))

ans = 1
mi = p_list[0]

for i in range(1, N):
    if mi >= p_list[i]:
        ans += 1
        mi = p_list[i]
        
print(ans)
A,B,K = map(int,input().split())

l = list(range(A,B+1))
res = set(l[:K] + l[-K:])
for i in sorted(set(res)):
    print(i)

### FIXED CODE ###

a,b,k=map(int,input().split())
if a+k-1>=b-k+1:
    for i in range(a,b+1):
        print(i)
else:
    for i in range(a,a+k):
        print(i)
    for i in range(b-k+1,b+1):
        print(i)
H,N=map(int,input().split())
AB=[]
for _ in range(N):
    a,b=map(int,input().split())
    AB.append((a,b))
AB.sort()
amax=AB[-1][0]
dp=[0]*(H+1)
for i in range(1,H+1):
    for a,b in AB:
        if dp[i]==0:
            dp[i]=dp[max(i-a,0)]+b
        else:
            dp[i]=min(dp[i],dp[i-a]+b)
print(dp[H])

### FIXED CODE ###

H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
x=max(a for a,b in ab)
dp=[0]*(H+x)
for i in range (1,H+x):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(dp[H])
from functools import lru_cache


@lru_cache
def factorial(n):
    if n == 0:
        return 1
    return n * factorial(n-1)


@lru_cache
def combination(n, k):
    return factorial(n) // factorial(k) // factorial(n - k)


k = int(input())
s = input()
MOD = 10**9+7

ans = 0
for i in range(k + 1):
    tmp = combination(i + len(s) - 1, len(s) - 1)
    tmp *= pow(25, i, MOD)
    tmp *= pow(26, k - i, MOD)
    tmp %= MOD
    ans += tmp
    ans %= MOD
print(ans)


### FIXED CODE ###

MOD = 10**9+7

k = int(input())
s = input()
MAX = k + len(s)

factorial = [0] * (MAX + 1)
factorial[0] = 1
for i in range(1, MAX + 1):
    factorial[i] = factorial[i-1] * i % MOD


ifactorial = [0] * (MAX + 1)
ifactorial[MAX] = pow(factorial[MAX], MOD - 2, MOD)
for i in range(MAX, 0, -1):
    ifactorial[i - 1] = ifactorial[i] * i % MOD

pow25 = [1] * (k + 1)
pow26 = [1] * (k + 1)
for i in range(k):
    pow25[i + 1] = pow25[i] * 25
    pow25[i + 1] %= MOD
    pow26[i + 1] = pow26[i] * 26
    pow26[i + 1] %= MOD


def combination(n, k):
    ret = factorial[n] * ifactorial[k] * ifactorial[n - k]
    return ret % MOD


ans = 0
for i in range(k + 1):
    tmp = combination(i + len(s) - 1, len(s) - 1)
    tmp *= pow25[i]
    tmp %= MOD
    # tmp *= pow(25, i, MOD)
    tmp *= pow26[k - i]
    # tmp *= pow(26, k - i, MOD)
    tmp %= MOD
    ans += tmp
    ans %= MOD
print(ans)
from scipy.special import comb
n,m=map(int,input().split())
print(int(comb(n+m,2)-n*m))

### FIXED CODE ###

import math
n,m=map(int,input().split())
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
print(combinations_count(n+m,2)-n*m)
import sys
import math
import bisect

def main():
    n = int(input())
    if n % (n % 9) == 0:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
import math
import bisect

def query(n):
    ans = 0
    for c in str(n):
        val = ord(c) - ord('0')
        ans += val
    return ans

def main():
    n = int(input())
    if n % query(n) == 0:
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()
#!/usr/bin/env python

def func():
    n,m = [int(i) for i in input().split(" ")]
    pibot = 10**(m-1)
    dic = {}

    for i in range(m):
        tmp = [int(i) for i in input().split(" ")]

        if tmp[0] not in dic.keys():
            dic[tmp[0]] = tmp[1]
        else:
            if dic[tmp[0]] != tmp[1]:
                print("-1")
                return

    a = [0] * m
    for key in dic.keys():
        a[key-1] = dic[key]

    tmp_s = ""
    for i in a:
        tmp_s += str(i)

    if int(tmp_s) < pibot:
        print("-1")
        return
    else:
        print(tmp_s)

    print("")

if __name__ == "__main__":
    func()

### FIXED CODE ###

#!/usr/bin/env python

n, m = input().split(" ")
n = int(n)
m = int(m)
s_len = []
c_len = []
dig = 10**(n-1)

for i in range(m):
    tmp = input().split(" ")
    s_len.append(int(tmp[0]))
    c_len.append(int(tmp[1]))

for i in range(0, dig*10):
    flag = False
    if len(str(i)) < n:
        continue
    for j,s in enumerate(s_len):
        if str(i)[s-1] != str(c_len[j]) and flag == False:
            flag = True
            break
    if flag==False:
        print(i)
        exit()

print("-1")
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 1
if a[0] == 0:
  print(0)
else:
  while a[0] == 1:
    a.remove(1)
  for i in range(len(a)):
    ans *= a[i]
    if ans > 10**18:
      print("-1")
      exit()
    elif i == len(a)-1:
      print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 1
if a[0] == 0:
  print(0)
else:
  for i in range(len(a)):
    ans *= a[i]
    if ans > 10**18:
      print("-1")
      exit()
    elif i == len(a)-1:
      print(ans)
n, m = map(int, input().split())
d = []
for _ in range(n):
    a, b = map(int, input().split())
    d.append((b, a))
d.sort(reverse=True)

cnt = m
ans = 0
i = 0
while i < n or cnt > 0:
    if d[i][1] <= cnt:
        ans += d[i][0]
        i += 1
        cnt -= 1
    else:
        i += 1
    if i == n-1 or cnt == 0:
        break        

print(ans)



### FIXED CODE ###

import heapq
n, m = map(int, input().split())
d = [[] for _ in range(m)]
for _ in range(n):
    a, b = map(int, input().split())
    if a <= m:
        d[a-1].append(-b)

t = []
heapq.heapify(t)
ans = 0
for i in range(m):
    for dd in d[i]:
        heapq.heappush(t, dd)
    if t:
        ans += heapq.heappop(t)*(-1)
print(ans)
N=int(input())
L=[[] for _ in range(N+1)]
for a in range(N-1):
    u,v,w=map(int,input().split())  #これで良いのか
    L[u].append((v,w))
    L[v].append((u,w))

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

def dfs(x,cur=0):
    global L
    global color

    color[x]=cur
    for next in L[x]:
        if color[next[0]]!=-1:
            continue
        if next[1]%2==0:
            dfs(next[0],cur)
        if next[1]%2==1:
            dfs(next[0],1-cur)

dfs(1)
for b in range(1,N+1):
    print(color[b])







### FIXED CODE ###

from collections import deque

N=int(input())
L=[[] for _ in range(N+1)]
for a in range(N-1):
    u,v,w=map(int,input().split())  #これで良いのか
    L[u].append((v,w))
    L[v].append((u,w))

dist=[-1]*(N+1)
q=deque()
color=[-1]*(N+1)

dist[1]=0
q.append(1)
color[1]=0
while q:
    now=q.popleft()
    for next in L[now]:
        if dist[next[0]]==-1:
            q.append(next[0])
            dist[next[0]]=dist[now]+next[1]
            if dist[next[0]]%2==0:
                color[next[0]]=0
            else:
                 color[next[0]]=1

for b in range(1,N+1):
    print(color[b])
s = input()
t = input()
x = 0
for i in 3:
  x += s[i-1]!=t[i-1]
print(x)

### FIXED CODE ###

s = input()
t = input()
x = 0
for i in range(3):
  x += s[i-1]==t[i-1]
print(x)
N, M = map(int, input().split())
P = [input().split() for i in range(M)]
k3, k2, k1 = 0, 0, 0

if N == 3:
    for i in range(M):
        if P[i][0] == '1':
            if k3 != 0:
                k3 = min(k3, int(P[i][1]))
            else:
                k3 = int(P[i][1])
        elif P[i][0] == '2':
            if k2 != 0:
                k2 = min(k2, int(P[i][1]))
            else:
                k2 = int(P[i][1])
        else:
            if k1 != 0:
                k1 = min(k1, int(P[i][1]))
            else:
                k1 = int(P[i][1])
    ans = k3 * 100 + k2 * 10 + k1
    ans = ans if M > 0 and len(str(ans)) == 3  else - 1
    print(ans)

elif N == 2:
    for i in range(M):
        if P[i][0] == '1':
            print(-1)
            exit(1)
        elif P[i][0] == '2':
            if k2 != 0:
                k2 = min(k2, int(P[i][1]))
            else:
                k2 = int(P[i][1])
        else:
            if k1 != 0:
                k1 = min(k1, int(P[i][1]))
            else:
                k1 = int(P[i][1])

    ans = k3 * 100 + k2 * 10 + k1
    ans = ans if M > 0 and len(str(ans)) == 2  else - 1
    print(ans)
        
        
else:
    for i in range(M):
        if P[i][0] == '1' or P[i][0] == '2':
            print(-1)
            exit(1)
        else:
            if k1 != 0:
                k1 = min(k1, int(P[i][1]))
            else:
                k1 = int(P[i][1])

    ans = k3 * 100 + k2 * 10 + k1
    ans = ans if M > 0 and len(str(ans)) == 1  else - 1
    print(ans)

### FIXED CODE ###


def solve(x):
    x = str(x)
    if len(x) != N:
        return False
    for s, c in P:
        if x[s - 1] != str(c):
            return False
    return True

if __name__ == "__main__":
    N, M = map(int, input().split())
    P = [list(map(int, input().split())) for i in range(M)]
    ans = 10**N
    for i in range(10 ** N - 1, -1, -1):
        if solve(i):
            ans = min(ans, i)
            
    print(ans if ans != 10**N else -1)
# 初期入力
import numpy as np 
N,Q = (int(x) for x in input().split())
aa=0  
bb=0
a=[0] 
b=[0]
ki_kouzou =np.zeros((N+1,N+1),dtype=int)

for i in range(1,N): #木の構造を入力
    aa,bb = (int(x) for x in input().split())
    ki_kouzou[aa,bb] =1
    a.append(aa) 
    b.append(bb)

#葉から根に向かい構造足していく
for i in range(N-1,0,-1):
    ki_kouzou[a[i],:] +=ki_kouzou[b[i],:]

for i in range(1,N+1): #各頂点は必ずフラグ立つ
    ki_kouzou[i,i] =1

# ポイント入力
p=[] ; x=[]
pp=0 ; xx=0
for i in range(Q):
    pp,xx = (int(x) for x in input().split())
    p.append(pp)
    x.append(xx)

#ポイント計算
point =np.zeros((N+1),dtype=int)
for i in range(Q):
    point +=ki_kouzou[p[i]] *x[i]

print(*point[1:])

### FIXED CODE ###

from collections import OrderedDict
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
#初期データ、構造
N,Q = (int(x) for x in input().split())
connection ={i:set() for i in range(1,N+1)}
for i in range(N-1):
    a,b = (int(x) for x in input().split())
    connection[a].add(b)
    connection[b].add(a)
#point =OrderedDict({i:0 for i in range(1,N+1)})
point ={i:0 for i in range(1,N+1)}
for i in range(Q):
    p,x = (int(x) for x in input().split())
    point[p] +=x

def DFS(now,prev = -1):
    for next in connection[now]:
        if next == prev:
            continue
        point[next] +=point[now] 
        DFS(next,now)

DFS(1)
print(*point.values())
print(''.join(input().split().reverse()))

### FIXED CODE ###

print(''.join(reversed(input().split())))
# coding: utf-8
import time
import re
import math
import fractions

def main():
    n=int(input())
    A=[]
    A.append(list(map(int,input().split())))
    A.append(list(map(int,input().split())))
    if len(A[0])%2==0:
        total=sum(A)
        mn=1e9
        for a in range(2):
            for b in range(n):
                if((a==0 and b==0) or (a==1 and b==n-1)):return
                mn=min([mn,A[a][b]])
        print(total-mn)
    else:
        print(sum(A))
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global n,A,s,memo,mx,mn,L,B



### FIXED CODE ###

# coding: utf-8
import time
import re
import math
import fractions

def main():
    global N,A
    N=int(input())
    A=[]
    A.append(list(map(int,input().split())))
    A.append(list(map(int,input().split())))
    print(hoge(0,0,0))
def hoge(x,y,total):
    global N,A
    if (x==N-1 and y==1):return total+A[y][x]
    if(x>=N or y>=2):return -1e9
    total+=A[y][x]
    return max([hoge(x+1,y,total),hoge(x,y+1,total)])
    
    
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global n,A,s,memo,mx,mn,L,B
N, M = map(int, input().split())

reward = [[] for _ in range(M)]

for i in range(N):
    a, b = map(int, input().split())

    if a > M:
        continue
    c[m - a].append(b)

import heapq

h = []
heapq.heapify(h)
ans = 0

for i in range(M - 1, -1, -1):
    for b in c[i]:
        heapq.heappush(h, -b)
    if len(h) > 0:
        ans += -1 * heapq.heappop(h)

print(ans)

### FIXED CODE ###

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

c = [[] for _ in range(M)]

for i in range(N):
    a, b = map(int, input().split())

    if a > M:
        continue
    c[M - a].append(b)

import heapq

h = []
heapq.heapify(h)
ans = 0

for i in range(M - 1, -1, -1):
    for b in c[i]:
        heapq.heappush(h, -b)
    if len(h) > 0:
        ans += -1 * heapq.heappop(h)

print(ans)
a = int(input())
b = [int(i) for i in input.split()]

max_num = max(b)
min_num = min(b)

print(max_num - min_num)

### FIXED CODE ###

a = int(input())
b = [int(i) for i in input().split()]

max_num = max(b)
min_num = min(b)

print(max_num - min_num)