Harryxun/stf_run huggingface dataset:
import sys
sys.setrecursionlimit(1000000)

def dfs(x, y, sym):
	tile[x][y] = '.'
	for i in range(len(DX)):
		nx = x + DX[i]
		ny = y + DY[i]
		if nx>=0 and nx<N and ny>=0 and ny<M and tile[nx][ny]==sym:
			dfs(nx, ny, sym)

def solve():
	res = 0
	for i in range(N):
		for j in range(M):
			if not tile[i][j] == '.':
				if tile[i][j] == '@':
					dfs(i, j, '@')
					res += 1
				elif tile[i][j] == '#':
					dfs(i, j, '#')
					res += 1
				elif tile[i][j] == '*':
					dfs(i, j, '*')
					res += 1
	print(res)

index = 0	
counter=0 
DX = [-1, 0, 1, 0]
DY = [0, -1, 0, 1]

while True:
	counter+=1
	line = input()
	
	if ' ' in line:
		N = int(line.split(' ')[0])
		M = int(line.split(' ')[1])
		tile = [[0 for i in range(N)]for j in range(M)]
	else:
		tile[counter-2] = list(line)

	if N==0 and M==0:
		break

	if counter-1==M:
		solve()
		counter = 0

### FIXED CODE ###

# -*- coding:utf-8 -*-
import sys
def dfs(x, y, sym):
	tile[x][y] = "."
	for i in range(len(DX)):
		nx = x + DX[i]
		ny = y + DY[i]
		if (0<=nx and nx<N and 0<=ny and ny<M and tile[nx][ny] is sym):
			dfs(nx, ny, sym)

def solve():
	res = 0
	for i in range(N):
		for j in range(M):
			sym = tile[i][j]
			if tile[i][j] != ".":
				if tile[i][j] is sym:
					dfs(i, j, sym)
					res += 1
	print(res)

counter=0
DX = [-1,0,1,0]
DY = [0,-1,0,1]
sys.setrecursionlimit(10**7)
while True:
	line = input()
	if " " in line:
		nums = line.split(" ")
		N = int(nums[0])
		M = int(nums[1])
		tile = [[0 for i in range(M)] for j in range(N)]
	else:
		tile[counter-1] = list(line)
	if N is 0 and M is 0:
		break
	counter += 1
	if counter-1 is N:
		solve()
		counter = 0
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    A,B=mis()
    print(A*b if 0<A<10 and 0<B<10 else '-1')


if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    A,B=mis()
    print(A*B if 0<A<10 and 0<B<10 else '-1')


if __name__ == "__main__":
    main()
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

m = 0

for i in range(n):
  num = int(a[i])
  m += b[num - 1]
  
  if num != n and != n - 1:
    if int(a[i]) == int(a[i + 1]):
      m += c[num - 1]
    
print(m)
print(a[0])


### FIXED CODE ###

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

m = 0

for i in range(n):
  num = int(a[i])
  m += b[num - 1]
#  print(i, m)  #erase later
  if num != n and i != n - 1:
    if num + 1 == int(a[i + 1]):
      m += c[num - 1]
#      print('C point', m)  #erase later
print(m)
N,M,K = list(map(int,input().split()))

# DFSテンプレ、計算量=O(N+M)
# N:頂点の数
# M:辺の数

G = [[] for _ in range(N)]
# graphの入力
for _ in range(M):
    a,b = list(map(int,input().split()))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
# print("G:",G)

KG = [[] for _ in range(N)]
# block graphの入力
for _ in range(K):
    a,b = list(map(int,input().split()))
    KG[a-1].append(b-1)
    KG[b-1].append(a-1)
# print("KG:",KG)

# ここまでエラーなし。

def dfs(G,v):
    # global l
    # nを訪問済みにする
    seen[v] = 1
    # l += 1
    # print(v+1)
    seenV.append(v)
    # vから行ける各頂点next_vについて
    for next_v in G[v]:
        if seen[next_v] == 1:
            continue
        else:
            dfs(G,next_v)

# Adj_size = [0]*N
# 全頂点を未訪問に初期化。
Adj = [[] for _ in range(N)]
seen = [0]*N
Y = []
for v in range(N):
    # l = 0
    if seen[v] == 0:
        # 未探索ならdfs発動
        seenV = []
        dfs(G,v)
    """
        for sv in seenV:
            Adj[sv] = seenV
    
        print("dfs done !!!")
    print("v=",v+1,"seen:",seen)
    print("seenV:",seenV)
    print("Adj[",v,"] :",Adj[v])
    
    # 出力
    # y = Adj_size[v] - len(G[v])-1
    y = len(Adj[v]) - len(G[v]) - 1
    for k in KG[v]:
        if k in Adj[v]:
            y += -1
    # print("v=",v+1,"y=",y)
    Y.append(str(y))
    print("")

# print("ADj",Adj)
# print("Y",Y)
# print("G",G)

print(" ".join(Y))
"""




### FIXED CODE ###

def find(x):
    if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
 
def unite(x,y):
  x,y=find(x),find(y)
  if x!=y:
    if x>y:
        x,y=y,x
    par[x]+=par[y]
    par[y]=x
    
def same(x,y):
  return find(x)==find(y)
 
def size(x):
  return-par[find(x)]
 
N,M,K = map(int,input().split())
par=[-1]*N
B = [set() for _ in range(N)]
FF = [0]*N
for _ in range(M):
    a,b = map(int,input().split())
    unite(a-1,b-1)
    FF[a-1] += 1
    FF[b-1] += 1
# print(F)
for j in range(K):
    a,b = map(int,input().split())
    B[a-1].add(b-1)
    B[b-1].add(a-1)

Y = []
for i in range(N):
    y = size(i) - FF[i] -1
    for b in B[i]:
        if same(i,b):
            y += -1
    Y.append(str(y))
print(" ".join(Y))
N , K = map(int,input().split())
h = list(map(int,input().split()))
inf = float('inf')
dp = [inf] * N
if K == 1:
    ans = 0
    for i in range(N - 1):
        ans += abs(h[i + 1] - h[i])
    print(ans)
    exit()

for i in range(N):
    if i == 0:
        min_cost = 0
    elif i == 1:
        min_cost = abs(h[1] - h[0])
    else:
        corrent = h[i]
        tmp_min = min(abs(corret - h[i - K]) + dp[i - K] , abs(corrent - h[i - K + 1]) + dp[i - K + 1])
        for j in range(K - 2):
            tmp_min = min(abs(corrent - h[i - K + 2 + j]) + dp[i - K + 2 + j], tmp_min)
        min_cost = tmp_min
    dp[i] = min_cost
#print(dp)
print(dp[N - 1])

### FIXED CODE ###

import sys
input = sys.stdin.readline
N , K = map(int,input().split())
h = list(map(int,input().split()))
inf = float('inf')
dp = [inf] * N
if K == 1:
    ans = 0
    for i in range(N - 1):
        ans += abs(h[i + 1] - h[i])
    print(ans)
    exit()

for i in range(N):
    if i == 0:
        min_cost = 0
    elif i == 1:
        min_cost = abs(h[1] - h[0])
    else:
        current = h[i]
        tmp_min = min(abs(current - h[i - K]) + dp[i - K] , abs(current - h[i - K + 1]) + dp[i - K + 1])
        for j in range(K - 2):
            tmp_min = min(abs(current - h[i - K + 2 + j]) + dp[i - K + 2 + j], tmp_min)
        min_cost = tmp_min
    dp[i] = min_cost
#print(dp)
print(dp[N - 1])
s = input()
if s[2]=s[3] && s[4]=s[5]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

S = str(input())
if S[2]==S[3] and S[4]==S[5]:
  print("Yes")
else:
  print("No")
K = int(input())
N = int(input())
A = []

for i in range(N):
    A.append(int(input()))

B = []
for i in range(N-1):
    B[i] = int(A[i] - A[i+1])

B.append(int((K-A[0])-(A[N-1]-K)))

B.sort()

Big = B[N-1]

print(K-Big)



### FIXED CODE ###

K,N = map(int, input().split())
A =  [int(N) for N in input().split()]

B = []
for i in range(N-1):
    B.append(int(A[i+1] - A[i]))

B.append(int(A[0]+(K-A[N-1])))

B.sort()

Big = B[N-1]

print(K-Big)
import sys
import math

N = int(input())

list = []

for i in range(n):
    S, P = input().split()
    list.append((S, int(P), i+1))

list = sorted(list, key=lambda x:x[1],reverse = True) 
list = sorted(list, key=lambda x:x[0]) 
for j in range(N):
	print(list[j][2])


### FIXED CODE ###

import sys
import math

N = int(input())

list = []

for i in range(N):
    S, P = input().split()
    list.append((S, int(P), i+1))

list = sorted(list, key=lambda x:x[1],reverse = True) 
list = sorted(list, key=lambda x:x[0]) 
for j in range(N):
	print(list[j][2])
import math
a, b = map(int, input().split())
print(a*b//math.gcd(a, b))

### FIXED CODE ###

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

print(a*b//fractions.gcd(a, b))
L,R,d=list(map(int,(input().split())))
if ((R//d-L//d)==99):
  print(100)
elif(((R//d-L//d)==0))
  print(1)
else:
  print(R//d-L//d)

### FIXED CODE ###

L,R,d=list(map(int,(input().split())))
if (L==d):
  print(R//d-L//d+1)
elif L==R and L!=d:
  print(1)
else:
  print(R//d-L//d)
s = input()
f = int(s[0]+s[1])
l = int(s[2]+s[3])
if 1<= f <= 12:
    if 1<= l <= 12:
        ans = "AMBIGUOUS"
    else:
        ans = "MMYY"
if (f == 0) or (f>13):
    if 1<= l <= 12:
        ans = "YYMM"
    else:
        ans = "NA"
print(ans)

### FIXED CODE ###

S = input()
ff = int(S[:2])
ll = int(S[2:])
if 0<ff<=12 and 0<ll<=12:
    print("AMBIGUOUS")
elif (ff == 0 or ff>12) and 0<ll<=12:
    print("YYMM")
elif 0<ff<=12 and (ll>12 or ll== 0):
    print("MMYY")
else:
    print("NA")
while 1:
    try:
        d=int(input())
        if d==0:
            break
        x=d
        y=x**2
        S=d*y
        while S<=72000000:
            x+=d
            y=x**2
            de=72000000-S
            S+=d*y
        if de<(S-72000000):
            print(72000000-de)
        else:
            print(S)
    except EOFError:
        break

### FIXED CODE ###

import math
while 1:
    try:
        d=int(input())
        time=600//d
        S=0
        for i in range(time):
            x=i*d
            y=x**2
            S+=y*d
        print(S)
    except EOFError:
        break
import heapq
N, M = map(int,input().split())
L = [[] for _ in range(M)]
for _ in range(N):
    A, B = map(int,input().split())
    L[A-1].append(-B)
Q = []
ans = 0
for i in range(M):
    for j in L[i]:
        heapq.heappush(Q, j)
    try:
        ans -= heapq.heappop(Q)
    except:
        pass
print(ans)

### FIXED CODE ###

import heapq
N, M = map(int,input().split())
L = [[] for _ in range(M)]
for _ in range(N):
    A, B = map(int,input().split())
    try:
        L[A-1].append(-B)
    except:
        pass
Q = []
ans = 0
for i in range(M):
    for j in L[i]:
        heapq.heappush(Q, j)
    try:
        ans -= heapq.heappop(Q)
    except:
        pass
print(ans)
a = input()
 
if a[-1] = 's':
  print(a end='es')
else:
  print(a end='s')

### FIXED CODE ###

a = input()
 
if a[-1] == 's':
  print(a, end='es')
else:
  print(a, end='s')
from math import factorial

n,k=map(int, input().split())
mod=10**9+7

#def combinations_count(n,r):
#    return factorial(n) // (factorial(n-r)*factorial(r))

def comb(m,r):
    if m < 0 or r < 0 or m < r: return 0
    if m==0 or r==0: return 1
    a=factorial(m)%mod
    b=factorial(r)%mod
    c=factorial(m-r)%mod
    return (a*power_func(b,mod-2)*power_func(c,mod-2))%mod

def power_func(a,b):
    if b == 0: return 1
    if b%2==0:
        d=power_func(a,b//2)
        return d*d %mod
    if b%2==1:
        return(a*power_func(a,b-1))%mod

ans=0
for i in range(1,k+1):
    temp=comb(n-k+1,i)
    temp2=(float(i)**(k-i))%mod
    print(int(temp*temp2)%mod)

### FIXED CODE ###

from math import factorial

n,k=map(int, input().split())
mod=10**9+7

#def combinations_count(n,r):
#    return factorial(n) // (factorial(n-r)*factorial(r))

def comb(m,r):
    if m < 0 or r < 0 or m < r: return 0
    if m==0 or r==0: return 1
    a=factorial(m)%mod
    b=factorial(r)%mod
    c=factorial(m-r)%mod
    return (a*power_func(b,mod-2)*power_func(c,mod-2))%mod

def power_func(a,b):
    if b == 0: return 1
    if b%2==0:
        d=power_func(a,b//2)
        return d*d %mod
    if b%2==1:
        return(a*power_func(a,b-1))%mod

ans=0
for i in range(1,k+1):
    temp=comb(n-k+1,i)
    temp2=comb(k-1,i-1)
    print(int(temp*temp2)%mod)
import sys
N, M = map(int, input().split())
s = [0]
c = [0]
num = [0] * (N + 1)
reg = [0] * (N + 1)
if N > 1:
  num[1] = 1

for i in range(M):
  a, b = map(int, input().split())
  if N > 1 and a == 1 and b == 0:
    print (-1)
    sys.exit()

  s.append(a)
  c.append(b)

for i in range(1, M + 1):
  if reg[s[i]] == 1 and num[s[i]] != c[i]:
    print (-1)
    sys.exit()
  num[s[i]] = c[i]
  reg[s[i]] = 1

result = ""
for i in range(1, M + 1):
  result += str(num[i])
print (result)



### FIXED CODE ###

import sys
N, M = map(int, input().split())
num = [0] * (N + 1)
reg = [0] * (N + 1)
if N > 1:
  num[1] = 1

for i in range(M):
  s, c = map(int, input().split())
  if N > 1 and s == 1 and c == 0:
    print (-1)
    sys.exit()
  if reg[s] == 1 and num[s] != c:
    print (-1)
    sys.exit()
  num[s] = c
  reg[s] = 1

result = ""
for i in range(1, N + 1):
  result += str(num[i])
print (result)
from collections import defaultdict

n = int(input())
x, y = [0] * n, [0] * n
data = defaultdict(int)
for i in range(n):
    x[i], y[i] = map(int, input().split())

for i in range(n):
    for j in range(n):
        if i != j:
            data[x[j] - x[i], y[j] - y[i]] += 1

print(n - max(data.values()))

### FIXED CODE ###

from collections import defaultdict

n = int(input())
x, y = [0] * n, [0] * n
data = defaultdict(int)
for i in range(n):
    x[i], y[i] = map(int, input().split())

if n == 1:
    print(1)
    exit()
for i in range(n):
    for j in range(n):
        if i != j:
            data[x[j] - x[i], y[j] - y[i]] += 1

print(n - max(data.values()))
a,b=map(int,input().split)
print(int(a*b-a-b+1))

### FIXED CODE ###

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

m=a*b-a-b+1

print(int(m))
X, t = map(int, inputa().split())
print(X-t if X >=t else '0')

### FIXED CODE ###

X, t = map(int, input().split())
print(X-t if X >=t else '0')
import math
import functools

N = int( input() )
T = [ int(input()) for _ in range(N) ]

def lcm( x, y ):
    return x * y // math.gcd( x, y )

def lcm_list( numbers ):
    return functools.reduce( lcm, numbers, 1 )

if N == 1: print( T[0] )
else     : print( lcm_list(T) )

### FIXED CODE ###

import fractions
import functools

N = int( input() )
T = [ int(input()) for _ in range(N) ]

def lcm( x, y ):
    return x * y // fractions.gcd( x, y )

def lcm_list( numbers ):
    return functools.reduce( lcm, numbers, 1 )

if N == 1: print( T[0] )
else     : print( lcm_list(T) )
n = int(input())

for i in range(1, 10):
  if n % i ==0:
    if n/i < 10:
      print('Yes')
      brake
else:
  print('No')

### FIXED CODE ###

n = int(input())

for i in range(1, 10):
  if n % i ==0:
    if n/i < 10:
      print('Yes')
      break
else:
  print('No')
K=int(input())

#関数定義(最大公約数)
def gcd(*numbers):
    return reduce(math.gcd, numbers)

sum=0

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            sum+=(gcd(a, b, c))

print(sum)

### FIXED CODE ###

import math
from functools import reduce

K=int(input())

#関数定義(最大公約数)
def gcd(*numbers):
    return reduce(math.gcd, numbers)

sum=0

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            sum+=(gcd(a, b, c))

print(sum)
import bisect
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
ans = int(0)

N = I()
color = []
a = I()
maxcolor =[]
maxcolor.append(a)
lena = 1
for i in range(N-1):
    a = I()
    minmaxcolor = min(maxcolor)
    if a<=minmaxcolor:
        maxcolor.insert(0,a)
#        maxcolor.append(a)
        lena += 1
    else:
        acandi = bisect.bisect_left(maxcolor, a)
        maxcolor[acandi] = a
        """
        aupper = lena-1
        alower = int(0)
        acandi = aupper//2
        
        for _ in range(aupper+1):
            if maxcolor[acandi]>=a:
                alower = acandi
                acandi = (aupper+acandi+1)//2
            else:
                if aupper - alower <= 1:
                    maxcolor[acandi] = a
                    break
                else:
                    aupper = acandi
                    acandi = (acandi + alower) // 2
        """

#print(maxcolor)
ans = len(maxcolor)
print(ans)


### FIXED CODE ###

from collections import deque
import bisect
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
ans = int(0)

N = I()
color = []
a = I()
maxcolor =deque()
maxcolor.append(a)
lena = 1
for i in range(N-1):
    minmaxcolor = maxcolor[0]
    a = I()
    if a<=minmaxcolor:
        maxcolor.appendleft(a)
#        maxcolor.append(a)
        lena += 1
    else:
        acandi = bisect.bisect_left(maxcolor, a)
        maxcolor[acandi-1] = a
        """
        aupper = lena-1
        alower = int(0)
        acandi = aupper//2
        
        for _ in range(aupper+1):
            if maxcolor[acandi]>=a:
                alower = acandi
                acandi = (aupper+acandi+1)//2
            else:
                if aupper - alower <= 1:
                    maxcolor[acandi] = a
                    break
                else:
                    aupper = acandi
                    acandi = (acandi + alower) // 2
        """

#print(maxcolor)
ans = len(maxcolor)
print(ans)
cnt = 1
while input() != 0:
    print('Case '+str(cnt)+': '+input())
    cnt += 1


### FIXED CODE ###

cnt = 1
c = int(input())
while c != 0:
    print('Case ' + str(cnt) + ': ' + str(c))
    c = int(input())
    cnt += 1
# coding: utf-8

N=input()

print(int((N*N))-int(input()))

### FIXED CODE ###

N=int(input())

print((N*N)-int(input()))
def cin():  return list(map(int,input().split()))

N, M, Q = list(map(int,input().split()))
v = [[0 for _ in range(N)] for _ in range(N)]
p = [[0 for _ in range(2)] for _ in range(N)]

for i in range(M):
    a, b = cin()
    v[a - 1][b - 1] += 1;

for i in range(Q):
    a, b = cin()
    p[i][0] = a - 1;
    p[i][1] = b - 1;
    
def d2_add(a):
    w = len(a[0])
    h = len(a)
    da = [[0] * w for j in range(h)]
    da[0][0] = a[0][0]
    for i in range(1, w):
        da[0][i] = da[0][i - 1] + a[0][i]
    for i in range(1, h):
        cnt_w = 0
        for j in range(w):
            cnt_w += a[i][j]
            da[i][j] = da[i - 1][j] + cnt_w
    return da

def d2_calc(da, p, q, x, y):
    if p > x or q > y:  return 0
    if p == 0 and q == 0:  return da[x][y]
    if p == 0:  return da[x][y] - da[x][q - 1]
    if q == 0:  return da[x][y] - da[p - 1][y]
    return da[x][y] - da[p - 1][y] - da[x][q - 1] + da[p - 1][q - 1]

ret = d2_add(a)
for i in range(Q):
    ans = d2_calc(ret, p[i], p[i], q[i], q[i])
    print(ans)

### FIXED CODE ###

N, M, Q = list(map(int,input().split()))
L = []
R = []
for i in range(M):
    in1, in2 = map(int,input().split())
    L.append(in1 - 1)
    R.append(in2 - 1)
p = []
q = []
for i in range(Q):
    in1, in2 = map(int,input().split())
    p.append(in1 - 1)
    q.append(in2 - 1)
    
a = [[0 for _ in range(N)] for _ in range(N)]
for i in range(M):
    a[L[i]][R[i]] += 1
    
#da[i][j]:(0,0)~(i,j)の長方形の和
def da_gen(a):
    w = len(a[0])
    h = len(a)
    da = [[0] * w for j in range(h)]
    da[0][0] = a[0][0]
    for i in range(1, w):
        da[0][i] = da[0][i - 1] + a[0][i]
    for i in range(1,h):
        cnt_w = 0
        for j in range(w):
            cnt_w += a[i][j]
            da[i][j] = da[i - 1][j] + cnt_w
    return da

#da_calc(p,q,x,y):(p,q)~(x,y)の長方形の和
def da_calc(da, p, q, x, y):
    if p > x or q > y:
        return 0
    if p == 0 and q == 0:
        return da[x][y]
    if p == 0:
        return da[x][y] - da[x][q - 1]
    if q == 0:
        return da[x][y] - da[p - 1][y]
    return da[x][y] - da[p - 1][y] - da[x][q - 1]+da[p - 1][q - 1]

ret = da_gen(a)
for i in range(Q):
    ans = da_calc(ret, p[i], p[i], q[i], q[i])
    print(ans)
n = int(input())
print(min([sum(map(int, str(i) + str(n - i))) for i in range(1, n // 2)]))


### FIXED CODE ###

n = int(input())
print(min([sum(map(int, str(i) + str(n - i))) for i in range(1, n // 2 + 1)]))
import sys
 
stdin=sys.stdin
 
ni=lambda:int(ns())
na=lambda:list(map(int,stdin.readline().split()))
ns=lambda:stdin.readline().rstrip()  # ignore trailing spaces


n,q=na()
AB=[[int(x) for x in na()] for _ in range(n-1)]
PX=[[int(x) for x in na()] for _ in range(q)]

graph=[[] for _ in range(n+1)]
values=[0]*(n+1)

for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

for p,x in PX:
    values[p]+=x

#print(graph)

def dfs(x,parent,add):
    values[x]+=add
    for i in graph[x]:
        if i==parent:
            continue
        dfs(i,x,values[x])

dfs(1,0,0)

print(' '.join(map(str,values[1:])))


### FIXED CODE ###

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

# 遅延評価で加えてあげるだけ

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])

dfs(1,0,0)

answer = ' '.join(map(str,value[1:]))
print(answer)
from itertools import combinations

def main():
    S = input()
    lens = len(S)

    patterns = []
    ans = 0
    for i in range(2 ** (lens-1)):
        x = format(i, 'b').zfill(lens-1)

        stmt = S[0]
        for i, xi in enumerate(x):
            if xi == '1':
                stmt += '+'
            stmt += S[i+1]
        ans += eval(stmt)
    print(ans)



if __name__ == "__main__":
    main()

### FIXED CODE ###

from itertools import combinations

def main():
    S = input()
    n = len(S)
    a = [i for i in range(1, n)]
    ans = []
    for i in range(n):
        if i == 0:
            ans.append(int(S))
        else:
            k = list(combinations(a, i))
            for ki in k:  # ki: (1, 3)
                r = 0
                t = 0  # 一時記憶
                for j, sj in enumerate(S):
                    if j in ki:
                        r += t
                        t = int(sj)
                    else:
                        t = t * 10 + int(sj)
                r += t
                ans.append(r)

    # print(ans)
    print(sum(ans))


if __name__ == "__main__":
    main()
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict
import math as m

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

setrecursionlimit(8000)

def main():
	n, m = rli()
	G = [[] for i in range(n+1)]
	for _ in range(m):
		u, v = rli()
		G[u].append(v)
	ans = 0
	memo = [-1 for _ in range(n+1)]

	def longest(v):
		if memo[v] > -1:
			return memo[v]
		pathlen = 0
		for nbhr in G[v]:
			pathlen = max(pathlen, 1 + longest(nbhr))
		memo[v] = pathlen
		return pathlen

	for i in range(1, n+1):
		ans = max(ans, longest(i))

	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()

### FIXED CODE ###

from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict
import math as m

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

setrecursionlimit(10000)

def main():
	n, m = rli()
	G = [[] for i in range(n+1)]
	for _ in range(m):
		u, v = rli()
		G[u].append(v)
	ans = 0
	memo = [-1 for _ in range(n+1)]

	def longest(v):
		if memo[v] > -1:
			return memo[v]
		pathlen = 0
		for nbhr in G[v]:
			pathlen = max(pathlen, 1 + longest(nbhr))
		memo[v] = pathlen
		return pathlen

	for i in range(1, n+1):
		ans = max(ans, longest(i))

	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()
N = int(input())
Arr = list(map(int, input().split()))

Arr.sort(reverse=True)

i = 0
ans = 0
for a in arr:
  if i%2 == 0:
    ans += a
  else:
    ans -= a

print(ans)

### FIXED CODE ###

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

Arr.sort(reverse=True)

i = 0
ans = 0
for a in Arr:
  if i%2 == 0:
    ans += a
  else:
    ans -= a
  i += 1

print(ans)
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
n, m = lr()
X = np.array(lr())
Y = np.array(lr())
x_len = X[1:] - X[:-1]
y_len = Y[1:] - Y[:-1]

square = x_len[:, None] * y_len[None, :] % MOD
answer = (n-1) * (m-1) * square.sum() % MOD
print(answer%MOD)
# 43

### FIXED CODE ###

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
n, m = lr()
X = np.array(lr())
Y = np.array(lr())
coef_x = np.arange(n)*2 - (n-1)
X *= coef_x
xsum = (X%MOD).sum() % MOD
coef_y = np.arange(m)*2 - (m-1)
Y *= coef_y
ysum = (Y%MOD).sum() % MOD
answer = xsum * ysum % MOD
print(answer % MOD)