Harryxun/stf_run huggingface dataset:
#解説方針#解法1
from collections import deque
#標準入力
N = int(input())
mod = 10 ** 9 + 7
L = [[] for i in range(N + 1)] #dfs用
AB = [0] * (N - 1)
for i in range(N - 1):
  a, b = map(int, input().split())
  L[a].append(b)
  L[b].append(a)
  AB[i] = [a, b]
#print(L)
#逆元計算
P = 10 ** 9 + 7
N2 = 2 * 100000 + 1
inv_t = [0]+[1]
for i in range(2,N2):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

#各辺がSに含まれる確率を求める
def dfs(c, d):#辺をつなぐ2頂点を変数にとる
  q = deque([c])
  visited = [0] * (N + 1)
  visited[c] = 1
  visited[d] = 1
  ans = 1
  while q:
    e = q.pop()
    for i in L[e]:
      if visited[i] == 0:
        visited[i] = 1
        ans += 1
        q.append(i)
  #print(ans , N - ans)
  pro = (1-((1/2) ** ans)) * (1-((1/2) ** (N - ans)))
  return pro      

#頂点の個数の期待値にする。
#基本的に辺の数+1だが、黒の頂点が一つもない1パターン(確率 1 / 2**N)だけ別に考慮
x = 0
for i in range(N - 1):
  x += dfs(AB[i][0], AB[i][1])
x = x + 1 - (N / 2) - (1/2) ** N
#print(x)#期待値があっていることを確認
  
y = int(2 ** N * x)
z = 2 ** N
T = True
while T:
  if (y % 2 == 0) and (z % 2 == 0):
    y /= 2
    z /= 2
  else:
    T = False
    
#ここで x = y / (2 ** N)の形にする
y, z = y % mod, int(z % mod)
y = y % z
print(y, z)
ans = inv_t[z] * 1
print(int(ans))



### FIXED CODE ###

#解説方針#解法1
#https://qiita.com/ZhangChaoran/items/71fab0e4b8647a93d3a0
from collections import deque
from heapq import heappop, heappush
#標準入力
N = int(input())
MOD = 10 ** 9 + 7
L = [[] for i in range(N + 1)] #dfs用
for i in range(N - 1):
  a, b = map(int, input().split())
  L[a].append(b)
  L[b].append(a)

#木の探索
parent = [0] * (N + 1)
order = []
stack = [1]
while stack:
    x = stack.pop()
    order.append(x)  # 行きがけ順探索リスト
    for y in L[x]:
        if y == parent[x]:
            continue
        parent[y] = x  # 親ノードを記録
        stack.append(y)
#print(order, parent)

half = pow(2, MOD - 2, MOD)
power_inv = [1] * (N + 1)#2 ** N の逆元の集合
size = [1] * (N + 1)
for i, v in enumerate(order[::-1], 1):#iが1から
    p = parent[v]
    x = size[v]  # vの子孫ノード数（自分も含む）をとる
    size[p] += x  # 親にノード数を加算
    power_inv[i] = power_inv[i - 1] * half % MOD  # [1, 1/2, 1/4, ...]
#print(size)
# 辺iがSに含まれるための必要十分条件による辺の個数の期待値 
# (1 - (1/2) ** i)(1 - (1/2) ** (N - i))を展開して計算
# 根である1の頂点以外は、ある頂点とその親を結ぶ辺を考えた際
# i と N - i個の頂点に別れるので,size[2:]でOK
ans = sum((1 - power_inv[i] - power_inv[N - i] + power_inv[N]) %
          MOD for i in size[2:])  
#ans = sum((1 - (1/2) ** i- (1/2) ** (N - i) + (1/2) ** N) for i in size[2:])  
#print(ans)
ans += 1  # 木の頂点の個数は辺の個数+1
# -「すべての辺が含まれない、つまり空グラフの場合の誤加算」-N/2
ans -= power_inv[N] + N * power_inv[1]  
#ans -= N * power_inv[1]  
ans %= MOD

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

c=list(map(int,input().split()))

total = 0

for i in range m:
    total += c[i]

if((n-total) >= 0):
    print(n-total)
else:
    print(-1)

### FIXED CODE ###

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

c=list(map(int,input().split( )))


total = 0

for i in range(m):
    total += c[i]

if((n-total) >= 0):
    print(n-total)
else:
    print(-1)
def tri(a,b,c):
	if a^2 == b^2 + c^2:
		return true
	else:
		return false
for time in range(int(input())):
	x,y,z = [int(i) for i in input().split()]
	if tri(x,y,z) or tri(y,z,x) or tri(z,x,y):
		print(???YES???)
	else:
		print(???NO???)

### FIXED CODE ###

def tri(a,b,c):
	return a**2 == b**2 + c**2
for time in range(int(input())):
	x,y,z = [int(i) for i in input().split()]
	if tri(x,y,z) or tri(y,z,x) or tri(z,x,y):
		print("YES")
	else:
		print("NO")
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *                # alpha = ascii_lowercase
from random import *                # l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from sys import stdin
from sys import maxsize
from operator import *                # d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter        # d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def solve(grid):
	H,W = len(grid),len(grid[0])
	q = []
	dist = [0]*H
	for i in range(H):
		dist[i] = []
	for i in range(H):
		for j in range(W):
			if(grid[i][j] == '#'):
				q.append([i,j])
				grid[i][j] = 0
	maxx = 0
	while(q):
		qq = []
		for i,j in q:
			for r,c in [[i+1,j],[i-1,j],[i,j+1],[i,j-1]]:
				if(0 <= r < H and 0 <= c < W and grid[r][c] == '.'):
					grid[r][c] = grid[i][j] + 1
					maxx = max(maxx,grid[r][c])
					qq.append([r,c])
		q = qq
	return maxx

H,W = map(int, stdin.readline().rstrip().split())
grid = []
for h in range(H):
	s = list(input())
	grid.append(s)
ans = solve(grid)
print(ans)



### FIXED CODE ###

# ANSHUL GAUTAM
# IIIT-D

'''

'''

def solve(grid):
	H,W = len(grid),len(grid[0])
	q = []
	dist = [0]*H
	for i in range(H):
		dist[i] = []
	for i in range(H):
		for j in range(W):
			if(grid[i][j] == '#'):
				q.append([i,j])
				grid[i][j] = 0
	maxx = 0
	while(q):
		qq = []
		for i,j in q:
			for r,c in [[i+1,j],[i-1,j],[i,j+1],[i,j-1]]:
				if(0 <= r < H and 0 <= c < W and grid[r][c] == '.'):
					grid[r][c] = grid[i][j] + 1
					maxx = max(maxx,grid[r][c])
					qq.append([r,c])
		q = qq
	return maxx

H,W = map(int, raw_input().split())
grid = []
for h in range(H):
	s = list(raw_input())
	grid.append(s)
ans = solve(grid)
print(ans)
N = int(input())
A = list(map(int, input().split()))
#A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
#A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
#C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while low + 1 < high:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        if A[mid1] >= B[i]:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while low + 1 < high:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        if C[mid2] > B[i]:
            high = mid2
    mid2 = high
    total = total + (mid1 + 1) * (N - mid2)

print(total)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
#A = [int(x) for x in input().split()]
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
A = [-float('inf')] + A + [float('inf')]
B.sort()
C.sort()
C = [-float('inf')] + C + [float('inf')]

total = 0

for i in range(N):
    low = 0
    high = N + 1
    while high - low > 1:
        mid1 = (low + high) // 2
        if A[mid1] < B[i]:
            low = mid1
        else:
            high = mid1
    mid1 = low
    low = 0
    high = N + 1
    while high - low > 1:
        mid2 = (low + high) // 2
        if C[mid2] <= B[i]:
            low = mid2
        else:
            high = mid2
    mid2 = high
    total += mid1 * (N + 1 - mid2)

print(total)
a = input().split()
if a[6] < 4:
  print("Heisei")
elif a[6] == 4 and a[8] < 3:
  print("Heisei")
else:
  print("TBD")

### FIXED CODE ###

a = input().split("/")
if int(a[1]) < 4:
  print("Heisei")
elif int(a[1]) == 4 and int(a[2]) <= 30:
  print("Heisei")
else:
  print("TBD")
A, B = list(map(int, input().split()))

ba = B - A 
if A % 2 == 0:
	ja = "j0"
else:
	ja = "j1"

if B % 2 == 0:
	jb = "j0"
else:
	jb = "j1"

a = A
b = B
a2 = ""
b2 = ""

if a == 0:
	a2 = "0"
else:
	while True:
		if a % 2 == 0:
			a2 += "0"
		else:
			a2 += "1"
		a = int(a // 2)
		if a == 1:
			a2 += "1"
			break
if b == 0:
	b2 = "0"
else:
	while True:
		if b % 2 == 0:
			b2 += "0"
		else:
			b2 += "1"
		b = int(b // 2)
		if b == 1:
			b2 += "1"
			break

a2 += "0" * (len(b2) - len(a2))
c2 = 0

if a2[0] == "0":
	if ba % 4 == 2 or ba % 4 == 1:
		c2 += 1
	else:
		c2 += 0

if a2[0] == "1":
	if ba % 4 <= 1:
		c2 += 1
	else:
		c2 += 0

for i in range(1, len(a2)):
	n = 0
	if a2[i] == "1":
		if ja == "j1":
			n += 1

	if b2[i] == "1":
		if jb == "j0":
			n += 1

	if n % 2 == 0:
		c2 += 0
	else:
		c2 += 2 ** i

print(c2)


### FIXED CODE ###

H, W = list(map(int, input().split()))
h, w = list(map(int, input().split()))
print((H - h) * (W - w))
N=int(input())
W=map(int,input())
total=sum(W)
diff=total
for w in W:
	if abs(diff-2*w) < diff:
   		diff = diff-2*w
    else:
    	break
print(diff)  

### FIXED CODE ###

N=int(input())
W=list(map(int,input().split()))
total=sum(W)
diff=total
for i in range(N):
    if abs(diff-2*W[i]) < diff:
        diff = diff-2*W[i]
    else:
        break
print(abs(diff))
n = input()
print "",
for i in range(1,n+1):
	if i%3==0 or str(i).count.('3'):
		print i

### FIXED CODE ###

n=input()
print"",
for i in range(1,n+1):
	if i%3==0 or str(i).count('3'):
		print i,
[print(n) for n in max_name] [print(n) for n in max_name] n = int(input())
name = {}
for _ in range(n):
    st = str(input())
    if st in name:
        tmp = name[st] + 1
        name[st] = tmp
    else:
        name[st] = 1

max_val = max(name.values())
max_name = [k for k, v in name.items() if v==max_val]
max_name.sort
for n in max_name:
    print(n)

### FIXED CODE ###

n = int(input())
name = {}
for i in range(n):
    st = str(input())
    if st in name:
        tmp = name[st] + 1
        name[st] = tmp
    else:
        name[st] = 1

max_val = max(name.values())
max_name = [k for k, v in name.items() if v==max_val]
max_name = sorted(max_name)

for n in max_name:
    print(n)
import itertools

dx = (0, 0, 0, 1,-1, 1, 1,-1,-1,-2, 2, 0, 0)
dy = (0, 1,-1, 0, 0, 1,-1, 1,-1, 0, 0,-2, 2)
dd = (5, 9, 13)

def drop(fab, used, size_list):
    for xy in range(100):
        y = xy%10
        x = xy//10
        size = size_list[used]
        check = True
        for i in range(size):
            if fab[y + dy[i] + 2][x + dx[i] + 2] == 0:
                check = False
        if check:
            for i in range(size):
                fab[y + dy[i] + 2][x + dx[i] + 2] -= 1
            if sum(map(sum, fab)):
                result = drop(fab, used + 1, size_list)
                if result:
                    result.append([x, y, dd.index(size) + 1])
                    return result
                for i in range(size):
                    fab[y + dy[i] + 2][x + dx[i] + 2] += 1
            else:
                return [[x, y, dd.index(size) + 1]]
    return False

fab = [[0 for i in range(14)] for j in range(14)]

n = int(input())

for i in range(10):
    fab[i + 2][2:12] = list(map(int, input().split()))

s = sum(map(sum, fab))
d_all = list(itertools.combinations_with_replacement([5,9,13], n))
d_list = [l for l in d_all if sum(l) == s]

ans = [0 for i in range(n)]
for d in d_list:
    d_tmp = sorted(d)[::-1]
    ans = drop(fab, 0, d_tmp)
    if ans:
        for a in ans:
            print(*a)
        break



### FIXED CODE ###

import itertools

dx = (0, 0, 0, 1,-1, 1, 1,-1,-1,-2, 2, 0, 0)
dy = (0, 1,-1, 0, 0, 1,-1, 1,-1, 0, 0,-2, 2)
dd = (5, 9, 13)

def drop(fab, start, used, size_list):
    for xy in range(start, 100):
        y = xy%10
        x = xy//10
        size = size_list[used]
        for i in range(size):
            if not fab[y + dy[i] + 2][x + dx[i] + 2]:
                break
        else:
            for i in range(size):
                fab[y + dy[i] + 2][x + dx[i] + 2] -= 1
            if sum(map(sum, fab)):
                if size == size_list[used + 1]:
                    result = drop(fab, xy, used + 1, size_list)
                else:
                    result = drop(fab, 0, used + 1, size_list)
                if result:
                    result.append([x, y, dd.index(size) + 1])
                    return result
                for i in range(size):
                    fab[y + dy[i] + 2][x + dx[i] + 2] += 1
            else:
                return [[x, y, dd.index(size) + 1]]
    return False

fab = [[0 for i in range(14)] for j in range(14)]

n = int(input())

for i in range(10):
    fab[i + 2][2:12] = list(map(int, input().split()))

s = sum(map(sum, fab))
d_all = list(itertools.combinations_with_replacement([5,9,13], n))
d_list = [l for l in d_all if sum(l) == s]

ans = [0 for i in range(n)]
for d in d_list:
    d_tmp = sorted(d)[::-1]
    ans = drop(fab, 0, 0, d_tmp)
    if ans:
        for a in ans:
            print(*a)
        break
a,b=int(input().split())
if a-b＊2<=0:
  
  print(0)
else:
  print(a-b＊2)
  


### FIXED CODE ###

a,b=map(int,input().split())
if a-b*2<=0:
  
  print(0)
else:
  print(a-b*2)
import math
import numpy as np
n,x=map(int,input().split())
li=np.array(input().split(),dtype=np.int64)

li=abs(li-x)

if len(li)==1:
    print(li[0])
else:
    mini=math.gcd(li[0],li[i+1])
    for i in range(1,n):
        gc=math.gcd(mini,li[i])
        mini=min(mini,gc)
    print(mini)
    

### FIXED CODE ###

import fractions
import numpy as np
n,x=map(int,input().split())
li=np.array(input().split(),dtype=np.int64)

li=abs(li-x)

if n==1:
    print(li[0])
else:
    ans=0
    for i in li:
        ans=fractions.gcd(ans,i)
    print(ans)
N,A,B=map(int,input().split())

print(sum(i in i range(1,N+1)
         if A<=sum(map(int,str(i)<=B)))

### FIXED CODE ###

N,A,B=map(int,input().split())
print(sum(i for i in range(1,N+1) if A<=sum(map(int,str(i)))<=B))
def main():
  size = int(input())
  array = []
  for i in range(size):
    array.append(list(map(int, input().split()))
                    
  flg = "Yes"           
  pre_time = 0
  pos = [0, 0] 
  for i in range (size):
    time = array[i][0] - pre_time
    distance = abs(array[i][1]-pos[0]) + abs(array[i][2]-pos[1])
    
    if time == distance or ((distance<time) and (time-distance)%2 == 0):
      pre_time = array[i][0]
      pos = array[i][1:]
    else:
      flg = "No"
                    
  print(flg)
                    
main()

### FIXED CODE ###

def main():
  size = int(input())
  array = []
  for i in range(size):
    array.append(list(map(int, input().split())))
                    
  flg = "Yes"           
  pre_time = 0
  pos = [0, 0] 
  for i in range (size):
    time = array[i][0] - pre_time
    distance = abs(array[i][1]-pos[0]) + abs(array[i][2]-pos[1])
    
    if time == distance or ((distance<time) and (time-distance)%2 == 0):
      pre_time = array[i][0]
      pos = array[i][1:]
    else:
      flg = "No"
                    
  print(flg)
                    
main()
def addTimesheet(ts, a, b):
    for i in range(0, len(ts)):
        if(not ts[i] is 1):
            ts[i] = 1
            a -= 1
        if(a is 0):
            break
    if(not a is 0):
      return ts, False
    return ts, True

n = int(input())
a = []
b = []
for i in range(0, n):
    str = input().split(" ")
    a.append(int(str[0]))
    b.append(int(str[1]))

timesheet = [0]*max(b)

for ia, ib in zip(a, b):
    timesheet, flag = addTimesheet(timesheet, ia, ib)
    if(flag is False):
    	break
if(flag is True):
	print("Yes")
else:
    print("No")

### FIXED CODE ###

import numpy as np
    
N  = int(input())
    
AB = []
time = 0
    
for _ in range(N):
    AB.append(list(map(int, input().split())))
    
AB = np.array(AB)
    
sorted_AB = AB[AB[:,1].argsort(), :]
    
for i in range(N):
    time += sorted_AB[i,0]
    
    if time > sorted_AB[i,1]:
        print('No')
        exit()
    
print('Yes')
S=int(input())
W=int(input())
if W>=S:
  print("unsafe")
else:
  print("safe")

### FIXED CODE ###

S,W = map(int,input().split())
 
if S<=W:
  print('unsafe')
else:
  print('safe')
ant_list = []   # (pos, direction)

N, L, T = list(map(int, input().split()))
for i in range(N):
    pos, direction = list(map(int, input().split()))
    ant_list.append(Ant(pos, direction))

for t in range(T):
    clide_ant_list = get_colide_ants(ant_list)
    for ant in colide_ant_list:
        ant.change_direction()

    for ant in ant_list:
        ant.move()

    clide_ant_list = get_colide_ants(ant_list)
    for ant in colide_ant_list:
        ant.change_direction()
        ant.move()

def get_colide_ants(ant_list):
    colide_ant_list = []
    sorted(ant_list, key=lambda ant: ant.pos)
    len_ant_list = len(ant_list)
    for i in range(len_ant_list-1):
        if ant_list[index].pos == ant_list[index+1].pos:
            colide_ant_list.append((ant_list[i], ant_list[i+1]))
            
    return colide_ant_list
    

class Ant:
    def __init__(self, pos, direction):
        self.pos = pos
        self.direction = direction

    def move():
        if direction == 1:
            self.pos += 1
        else:
            self.pos -= 1

        if self.pos >= L:
            self.pos = self.pos - L
        if self.pos < 0:
            self.pos += L + self.pos

    def change_direction():
        if direction == 1:
            direction = 2
        else:
            direction = 1
        


### FIXED CODE ###

N, L, T = list(map(int, input().split()))

X = []
W = []
X_after = []
for _ in range(N):
    x, w = list(map(int, input().split()))
    if w == 1:
        x_a = (x + T) % L
    else:
        x_a = (x - T) % L
        x_a = x_a if x_a >= 0 else L + x_a
    X.append(x)
    W.append(w)
    X_after.append(x_a)

n_colide = 0
for i in range(1, N):
    if W[0] == 1 and W[i] == 2:
        dist = X[i] - X[0]
        n_colide += 2 * (T - (dist / 2)) // L + 1
    elif W[0] == 2 and W[i] == 1:
        dist = (L + X[0]) - X[i]
        n_colide += 2 * (T - (dist / 2)) // L + 1

if W[0] == 1:
    num_a0 = n_colide % N
else:
    num_a0 = N - (n_colide % N)

num_a0 = int(num_a0)

x_a0 = X_after[0]
X_after = sorted(X_after)
i = X_after.index(x_a0)
if W[0] == 1 and X_after.count(x_a0) == 2:
    i += 1
X_after = X_after[i-num_a0:] + X_after[:i-num_a0]

for x_a in X_after:
    print(x_a)
A,B=map(int,input().split())
import math
print(A*B//(math.gcd(A,B)))

### FIXED CODE ###

import fractions
A,B=map(int,input().split())
print(A*B//(fractions.gcd(A,B)))
S = input()
K = int(input())
 
if K == 1:
  print(int(S[0]))
elif len(S) == 1:
  print(int(S))
elif S[:K] == "1"*K:
  print(1)
else:
  for i in range(K+1):
    if S[i] != "!":
      print(int(S[i]))
      break

### FIXED CODE ###

S = input()
K = int(input())
 
one = True
for i in range(K):
  if S[i] != "1":
    print(int(S[i]))
    one = False
    break
if one:
  print(1)
n,k=map(int,input().split())
s=[0,0,0]

for i in range(k):
  d=int(input())
 
  List=list(map(int,input().split()))
  for i in range(d):
    s[List[i]-1]=1
print(n-sum(s))


### FIXED CODE ###

n,k=map(int,input().split())
s=[]
for i in range(n):
  s.append(0)


for i in range(k):
  d=int(input())
 
  List=list(map(int,input().split()))
  for i in range(d):
    s[List[i]-1]=1
print(n-sum(s))
import sys, os, re
from pprint import pprint
from math import sin, cos, sqrt, radians

n, m = list(map(int, sys.stdin.readline().strip().split()))
g = [[] for x in range(n)]

for i in range(n):
    x, y = list(map(int, sys.stdin.readline().strip().split()))
    x -= 1
    y -= 1
    g[x].append(y)
    g[y].append(x)

ans = {0: -1}

print("Yes")


### FIXED CODE ###


import sys, os, re
from pprint import pprint
from math import sin, cos, sqrt, radians

n, m = list(map(int, sys.stdin.readline().strip().split()))
g = [[] for x in range(n)]

for i in range(m):
    x, y = map(int, sys.stdin.readline().strip().split())
    x -= 1
    y -= 1
    g[x].append(y)
    g[y].append(x)

if [] in g:
    print("No")
    exit(0)

ans = {0: -1}
tmp = [0]

while len(ans) < n:
    tmp_next = []
    for k in tmp:
        for node in g[k]:
            if node not in ans:
                ans[node] = k
                tmp_next.append(node) 
                flag = True

        tmp = tmp_next
        if flag == False:
            break

    """
    flag = False    
    for k, v in list(ans.items()):
        for node in g[k]:
            if node not in ans:
                ans[node] = k
                flag = True
    if flag == False:
        break
    """

print("Yes")
for i in range(1, n):
    print(ans[i]+1)
a, b, c, d = map(int,input().split())
if a + b > c + d:
  prtin("Left")

elif a + b < c + d:
  print("Right")

else:
  print("Balansed")

### FIXED CODE ###

a, b, c, d = map(int,input().split())
if a + b > c + d:
  print("Left")
 
elif a + b < c + d:
  print("Right")
 
else:
  print("Balanced")
import sys
sys.setrecursionlimit(10**6)
from heapq import heappop, heappush

icase=0
if icase==0:
    n=int(input())
    xy=[[0]*2 for i in range(n)]
    for i in range(n):
        xy[i]=list(map(int,input().split()))
elif icase==1:    
    n=3
    xy=[[1, 5], [3, 9], [7, 8]]
elif icase==2:    
    n=6
    xy=[[8, 3], [4, 9], [12, 19], [18, 1], [13, 5], [7, 6]]

xy = list(map(list, set(map(tuple, xy))))
xy.sort()
xy=xy[:n*2]

pair_lst = [i for i in range(n)]
que=[]
for i in range(n-1):
    for j in range(i+1,n):
        wi=min(abs(xy[i][0]-xy[j][0]),abs(xy[i][1]-xy[j][1]))
        heappush(que,(wi,i,j))

def find(x):
    if x == pair_lst[x]:
        return x
    else:
        tmp = find(pair_lst[x])
        pair_lst[x] = tmp
        return tmp

length_sum = 0
while que:
    w, s, t = heappop(que)
    root_s = find(s)
    root_t = find(t)
    if root_s != root_t:
        pair_lst[root_s] = root_t
        length_sum += w

print(length_sum)    

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
from heapq import heappop, heappush,heapify

icase=0
if icase==0:
    n=int(input())
    xy=[[0]*2 for i in range(n)]
    x=[0]*n
    y=[0]*n
    for i in range(n):
#        xy[i]=list(map(int,input().split()))
        x[i],y[i]=map(int,input().split())
elif icase==1:    
    n=3
#    xy=[[1, 5], [3, 9], [7, 8]]
    x=[1, 3, 7]
    y=[5, 9, 8]
elif icase==2:    
    n=6
#    xy=[[8, 3], [4, 9], [12, 19], [18, 1], [13, 5], [7, 6]]
    x=[8, 4, 12,18,13,7]
    y=[3, 9, 19, 1, 5, 6]

xi=[[0]*2 for i in range(n)]
yi=[[0]*2 for i in range(n)]
for i in range(n):
    xi[i]=[x[i],i]
    yi[i]=[y[i],i]
    
xi.sort()
x=xi
y=yi.sort()
y=yi

pair_lst = [i for i in range(n)]
que=[]
for i in range(n-1):
    wi=x[i+1][0]-x[i][0]
    heappush(que,(wi,x[i][1],x[i+1][1]))
    wi=y[i+1][0]-y[i][0]
    heappush(que,(wi,y[i][1],y[i+1][1]))

def find(x):
    if x == pair_lst[x]:
        return x
    else:
        tmp = find(pair_lst[x])
        pair_lst[x] = tmp
        return tmp

icnt=0
length_sum = 0
while que:
    w, s, t = heappop(que)
#    print(w,s,t)
    root_s = find(s)
    root_t = find(t)
    if root_s != root_t:
        pair_lst[root_s] = root_t
        length_sum += w
        icnt+=1
#        print(icnt)

print(length_sum)
for i in range(n):
    ans *= a[i]
        if ans > 10**18:
            print(-1)
            exit:
        
    exit:
print(ans)

### FIXED CODE ###

n = int(input())
s = list(map(int,input().split()))
ans = 1

if 0 in s:
    print(0)
else:    
    for i in range(n):
        ans *= s[i]
        if ans > 10 ** 18:
            ans = -1
            break
    print(ans)
x ** 3

### FIXED CODE ###

x = input()
print(x ** 3)
n = int(input())
A = list(map(int,input().split()))

v = (A[1]-A[0]) / abs(A[1]-A[0])
ans = 1
i = 2
while i < n:
    if (A[i] - A[i-1]) * v < 0:
        v *= -1
        ans += 1
        i += 2
        if i == n+1:
            ans += 1
    else:
        i += 1
print(ans)

### FIXED CODE ###

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

# i = 0
# def w(i):
#     # print(i)
#     if A[i] - A[i-1] == 0:
#         return 0
#     else:
#         return (A[i]-A[i-1]) / abs(A[i]-A[i-1])
# v = w(1)
# ans = 1

# i = 2
# while i < n:
#     print(i)
#     nv = w(i)
#     if nv * v < 0:
#         ans += 1
#         i += 2
#         v = 0
#         if i == n:
#             print("p")
#             ans += 1
#     else:
#         i += 1
#     if nv != 0:
#         v = nv

B = []
for i in range(1, n):
    if A[i] != A[i-1]:
        B.append(int((A[i]-A[i-1]) / abs(A[i]-A[i-1])))
# print(B)

ans = 1
t = 0
m = 0
for i in range(len(B)):
    # print(i)
    if B[i] * t < 0:
        # print("p")
        ans += 1
        t = 0
        if i == len(B):
            ans += 1
    else:
        t = B[i]

print(ans)
k=int(input())
n=min(k,50)
a=list(range(n))
for i in range(n):
  a[i]+=(k+n-1)//n
for i in range(k%n):
  a[i]+=n
  for j in range(n):
    if i==j:continue
    a[j]-=1
print(n)
print(*a)

### FIXED CODE ###

k=int(input())
n=min(k+2,50)
a=list(range(n))
for i in range(n):
  a[i]+=k//n
for i in range(k%n):
  a[i]+=n
  for j in range(n):
    if i==j:continue
    a[j]-=1
print(n)
print(*a)
N, i = map(input().split())
print(N - i + 1)

### FIXED CODE ###

N, i = map(int, input().split())
print(N - i + 1)