Harryxun/stf_run huggingface dataset:
from fractions import gcd
mod = 10**9+7
n = int(input())
a = list(map(int(input().split())))
ans = 0
l = 1
for i in range(n):
    l = l*a[i]//gcd(l,a[i])
for i in a:
    ans = (ans + l*pow(i,mod-2,mod)) % mod
print(ans)

### FIXED CODE ###

from fractions import gcd
mod = 10**9+7
n = int(input())
a = list(map(int,input().split()))
ans = 0
l = 1
for i in a:
    l = l*i//gcd(l,i)
l %= mod
for i in a:
    ans = (ans +l*pow(i,mod-2,mod)) % mod
print(ans)
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        
N = listA[0][0]
M = listA[0][1]
ans = [0] * N
pena = [0] * N
        
        
for i in range(1, M-1):
    num=listA[i][0] -1
    res=listA[i][1]
    if(res=="WA" and ans[num] == 0):
        pena[num] =  pena[num]+1
    if(res=="AC"):
        ans[num] = ans[num] + 1                      
        
print('%d %d' % (sum(ans), sum(pena) ))

### FIXED CODE ###

listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(input().split())
    except:
        break;
        
N = int(listA[0][0])
M = int(listA[0][1])

ans = [0] * N
pena = [0] * N

for i in range(1, M+1):
    num=int(listA[i][0]) -1
    res=listA[i][1]
    if res=="WA" and ans[num] == 0:
        pena[num] =  pena[num]+1
    if res=="AC" and ans[num] == 0:
        ans[num] = 1
        
print('%d %d' % (sum(ans), sum(x*y for x,y in zip(ans,pena)  ) ))
from math import gcd, sqrt
from collections import Counter

n = int(input()) 
times = 0

# 公約数を求める
def gcd(tmpn):
    lists = []
    while True:
        end = True
        for i in range(2, int(sqrt(tmpn)) + 1):
            if tmpn % i == 0:
                lists.append(i)
                tmpn = tmpn // i
                end = False         
        if end:  
            lists.append(tmpn)
            break
    return lists
    
def gori(lists, num=1, ans=[]):
    if len(lists) == 0:
        ans.append(num)
        return ans
    for i in range(len(lists)):
        tmp = lists[0:i] + lists[i + 1:len(lists)]
        ans = gori(tmp, num * lists[i], ans)
        ans = gori(tmp, num, ans)
    return ans

# 1を除いた公約数の個数を出力する
a = Counter(gcd(n - 1))
times = sum(map(lambda x: x+1, a.values())) - 1

a = set(gori(gcd(n)))
a.remove(1)

for i in a:
    tmp = n // i
    if tmp < i:
        if tmp == 1:
            times += 1
        
    else:
        while True:
            if tmp < i:
                if tmp == 1:
                    times += 1
                    break
            if tmp % i == 0:
                tmp = tmp // i
                    
            else:
                if tmp % i == 1:
                    times += 1
                break

print(times)       


### FIXED CODE ###

from collections import Counter

n = int(input()) 
times = 0

def make_divisors(n):
    divisors = [n]
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort()
    return divisors
    
times = len(make_divisors(n - 1))
a = make_divisors(n)

for i in a:
    tmp = n // i
    if tmp == 1:
        times += 1 
        continue
    while tmp % i == 0:
        tmp = tmp // i
    if tmp % i == 1:
        times += 1 
    
print(times if n != 2 else 1)
import math

def p(n, r):
	if n < r:
		return 1
	return math.factorial(n) // math.factorial(n - r)

N,K = map(int,input().split())
E = [[] for _ in range(N)]
MOD = 10**9+7
#辺の定義
#辺E(u,v)の重みがw
for _ in range(N-1):
  u,v = map(int,input().split())
  u -= 1
  v -= 1
  E[u].append(v)
  E[v].append(u)

#colorが塗られたかどうか
color = [-1 for _ in range(N)]

#dfsで色を塗っていく
stack = []
color[u] = 1
ans = K
for i,v in enumerate(E[u]):
	stack.append(v)
	ans *= (K-i-1)
	ans %= MOD

while stack:
	u = stack.pop()
	color[u] = 1
	length = len(E[u])
	for v in E[u]:
		if color[v] == -1:
			stack.append(v)
		else:
			length -= 1
	ans *= p(K-2,length) % MOD
	ans %= MOD

#各頂点の色を出力
print(ans%MOD)

### FIXED CODE ###

import math
import sys

def p(n, r):
	if n < r:
		return 1
	return math.factorial(n) // math.factorial(n - r)

def main():
	input = sys.stdin.readline
	N,K = map(int,input().split())
	E = [[] for _ in range(N)]
	MOD = 10**9+7
	#辺の定義
	for _ in range(N-1):
	  u,v = map(int,input().split())
	  u -= 1
	  v -= 1
	  E[u].append(v)
	  E[v].append(u)

	if N == 1:
		print(K)
		sys.exit()
	#colorが塗られたかどうか
	color = [-1 for _ in range(N)]
	dp = [-1 for _ in range(N)]
	#dfsで色を塗っていく
	stack = []
	color[u] = 1
	ans = K
	for i,v in enumerate(E[u]):
		stack.append(v)
		ans *= (K-i-1)
		ans %= MOD

	while stack:
		u = stack.pop()
		color[u] = 1
		length = 0
		for v in E[u]:
			if color[v] == -1:
				stack.append(v)
				length += 1
		if dp[length] == -1:
			tmp = 1
			for i in range(K-1-length,K-1):
				tmp *= i
				tmp %= MOD
			#tmp = p(K-2,length) % MOD
			ans *= tmp
			dp[length] = tmp
		else:
			ans *= dp[length]
		ans %= MOD

	#各頂点の色を出力
	print(ans%MOD)

if __name__ == '__main__':
	main()
N,M,X=map(int, input().split())
A = list(int(M) for M in input().split())
i = 0
for i in range(M):
    if A[i]>X:
        i = i+1
print(i)
    


### FIXED CODE ###

A,B,C=map(int, input().split())
if C>=A and A+B>=C:
    print("YES")
else:
    print("NO")
w,h,x,y = map(int,input().split())

a = min(x,w-x)
s = h*a

b = min(y, h-y)
t = w*b

result = 0

if x == w/2 and y == h/2:
    result = 1

u = 0
if w == x and h == y:
    u = w*h/2
if x == 0 and y == h:
    u = w*h/2
if x == 0 and y == 0:
    u = w*h/2
if x == w and y == 0:
    u = w*h/2
 
v = 0
if x == 0 or x == w:
    temp = max(h-y,y)
    v = h*w/2

c = 0
if y/x == h/w:
    c = h*w/2

z = 0
try:
    if y == -h/w*x + h:
        z = h*w/2
except:
    pass

print(max(s,t,u,v,c,z),result)


### FIXED CODE ###

w,h,x,y = map(int,input().split())

a = min(x,w-x)
s = h*a

b = min(y, h-y)
t = w*b

result = 0

if x == w/2 and y == h/2:
    result = 1

print(h*w/2,result)
for i, b in enumerate(B):
    if b <= A[i]:
        r += b
    else:
        b -= A[i]
        r += A[i]
        if b <= A[i+1]:
            A[i+1] -= b
            r += b
        else:
            r += A[i+1]
            A[i+1]=0
            
print(r)

### FIXED CODE ###

n = int(input())
A= list(map(int, input().split()))
B= list(map(int, input().split()))
r = 0
for i, b in enumerate(B):
    if b <= A[i]:
        r += b
    else:
        b -= A[i]
        r += A[i]
        if b <= A[i+1]:
            A[i+1] -= b
            r += b
        else:
            r += A[i+1]
            A[i+1]=0
            
print(r)
# encoding:utf-8
import copy
import numpy as np
import random

n,q = map(int,input().split())
s = list(str(input()))
L = []
for i in range(q):
    l,r = map(int,input().split())
    L.append([l,r])

# count_ac = np.zeros([n])
count_ac = []
count = 0
i = 0
while (i<n):
    if s[i] == "A" and s[i+1] == "C":
        count_ac.append(count)
        count += 1
        count_ac.append(count)
        i += 2
    else:
        count_ac.append(count)
        i += 1


for i in range(q):
    ans = count_ac[L[i][1]-1]-count_ac[L[i][0]-1]
    print(int(ans))


### FIXED CODE ###

# encoding:utf-8
import copy
import numpy as np
import random

n,q = map(int,input().split())
s = list(str(input()))
L = []
for i in range(q):
    l,r = map(int,input().split())
    L.append([l,r])

# count_ac = np.zeros([n])
count_ac = []
count = 0
i = 0
while i < n-1:
    if s[i] == "A" and s[i+1] == "C":
        count_ac.append(count)
        count += 1
        count_ac.append(count)
        i += 2
    else:
        count_ac.append(count)
        i += 1

count_ac.append(count)


# print(count_ac)
for i in range(q):
    ans = count_ac[L[i][1]-1]-count_ac[L[i][0]-1]
    print(int(ans))
def f(hito, zahyo, mae=0):
  x[hito]=zahyo
  for tsugi in links[hito]:
    if tsugi[0]==mae:
      continue
      
    if x[tsugi[0]]==None:
      f(tsugi[0], zahyo+tsugi[1], hito)
    else:
      if x[tsugi[0]]==zahyo+tsugi[1]:
        pass
      else:
        print('No')
        exit()

N, M=map(int, input().split())
links=[[] for _ in range(N+1)]
for _ in range(M):
  l, r, d=map(int, input().split())
  links[l].append([r, d])
  links[r].append([l, -d])
  
x=[None]*(N+1)
for i in range(1, N+1):
  if x[i]==None:
    f(i, 0)
    
print('Yes')

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5)

def f(hito, zahyo):
  x[hito]=zahyo
  for tsugi in links[hito]:
    if x[tsugi[0]]==None:
      f(tsugi[0], zahyo+tsugi[1])
    else:
      if x[tsugi[0]]!=zahyo+tsugi[1]:
        print('No')
        exit()

N, M=map(int, input().split())
links=[[] for _ in range(N+1)]
for _ in range(M):
  l, r, d=map(int, input().split())
  links[l].append([r, d])
  links[r].append([l, -d])
  
x=[None]*(N+1)
for i in range(1, N+1):
  if x[i]==None:
    f(i, 0)
    
print('Yes')
N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()
Min = h[K] - h[0]
for i in range(N-K+1):
  if h[K+i] - h[i+1] < Min:
    Min = h[K+i] - h[K]
    
print(Min)

### FIXED CODE ###

N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()
Min = h[K] - h[0]
for i in range(N-K+1):
  if h[K+i-1] - h[i] < Min:
    Min = h[K+i-1] - h[i]
    
print(Min)
def main():
        goats =3
        n = input()
        list = [int(i) for i in input().split()]
        if (list[0]%3==0 or list[1] %3==0  or (list[0]+list[2])%3==0):
           print('Possible')
        else:
           print("Impossible")
     
     
    if __name__ == "__main__":
        main()

### FIXED CODE ###

def main():
    a, b = map(int, input().split())
    goats = 3
    if a%goats == 0 or b%goats == 0 or (a+b)%goats == 0:
        print("Possible")
    else:
        print("Impossible")


if __name__ == "__main__":
        main()
n = int(input())
x = str(input()")
x_int = np.array(list(map(int, x)))[::-1].dot(np.power(np.ones(n)*2, np.arange(n)))
for i in range(n):
    z_int = int(x_int + 2**(n-1-i)) if x[i] == "0" else int(x_int - 2**(n-1-i))
    print(calc_i(z_int, 0))

### FIXED CODE ###

N = int(input())
B = input()

B_1 = B.count("1")
mod_p1 = int(B,2) % (B_1+1)
if B_1 != 1:
    mod_m1 = int(B,2) % (B_1-1)

def calc_small(n, iter):
    iter += 1
    mod = n % bin(n).count("1")

    if mod == 0:
        return iter
    else:
        return calc_small(mod, iter)

for i in range(N):
    if B_1 == 1 and int(B[i]) == 1:
        print(0)
        continue
    mod = (mod_m1 - pow(2,N-i-1,B_1-1)) % (B_1-1) if int(B[i]) == 1 else (mod_p1 + pow(2,N-i-1,B_1+1)) % (B_1+1)
    iter = 1
    if mod == 0:
        print(iter)
    else:
        print(calc_small(mod, iter))
s = input()
n = 4
pre = int(s[:2])
suf = int(s[2:])
if pre > 12 and suf > 12:
  print('NA')
elif pre > 12 and suf <= 12 and suf > 0:
  print('YYMM')
elif pre <= 12 and suf > 12 and pre > 0:
  pritn('MMYY')
elif pre <= 12 and suf <= 12 and pre > 0 and suf > 0:
  print('AMBIGUOUS')
else:
  print('NA')

### FIXED CODE ###

s = input()
pre = int(s[:2])
suf = int(s[2:])
if 0 < pre <= 12 and 0 < suf <= 12:
  print('AMBIGUOUS')
elif 0 < suf <= 12:
  print('YYMM')
elif 0 < pre <= 12:
  print('MMYY')
else:
  print('NA')
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics
import heapq


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

data = getInputListInt()
N = data[0]
K = data[1]
MOD = 1000000000 + 7

# nCa
def choose(n, a):
    if n == 0 or a == 0: return 1
    x = 1
    y = 1
    for i in range(a):
        x *= n-i
        y *= i+1
    return x / y

for i in range(1, K+1, 1):
    blue = choose(K-1, i-1)
    red = choose(N-K-(i-1) +i, i)

    ans = (blue * red) % MOD
    print(int(ans))


### FIXED CODE ###

import sys

# import re
import math
import collections
# import decimal
# import bisect
# import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    def fast_pow(num, kata, mod):
        if kata == 0:
            return 0

        res = 1
        while kata > 0:
            if kata & 1 == 1:
                res = res * num % mod
            num = num * num % mod

            kata >>= 1
        return res

    # MODのCombination nがでかくても関係なくrに依存　r<10**6なら回せる
    MOD = 10 ** 9 + 7

    def choose(n, r):
        res = 1
        fac = 1
        for i in range(r):
            res *= n - i
            res %= MOD
            fac *= i + 1
            fac %= MOD
        return res * fast_pow(fac, MOD - 2, MOD) % MOD

    n, k = ns()

    for i in range(1, k + 1):
        blue_pair = choose(k - i + (i - 1), i - 1)
        red_pair = choose((n - k) + 1, i)
        print(blue_pair * red_pair % MOD)


if __name__ == '__main__':
    main()
=int(input())
r=n-1
for i in range(2,int(n**0.5)):
    if (n%i==0):
        s=n//i+i-2
        if s<r:
            r=s
print(r)


### FIXED CODE ###

n=int(input())
r=n-1
for i in range(1,int(n**0.5)+1):
    if (n%i==0):
        s=(n//i)+i-2
        if s<r:
            r=s
print(r)
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7

for i in range(60):
    c = sum([1 for ai in a if (a >> i) & 1])
    ans += (1 << i) * c * (n-c)
    ans % = mod
print(ans)

### FIXED CODE ###

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

ans = 0
P = 10**9+7
bit = [0 for i in range(70)]

# 各bit独立に1が何個あるか数える
for i in range(N):
    S = bin(A[i])
    for j in range(1,len(S)-1):
        if S[-1*j] == '1':
            bit[j-1] += 1

# 各bitの1の個数と0の個数の積が、XOR和が1になる数字の個数と一致
for i in range(70):
    ans += (2**i)*bit[i]*(N-bit[i])
    ans %= P

print(ans)
import functools
import fractions

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = set(list(map(int, input().split())))
  else:
    # N = 3
    # A = [7,6,8]
    # N = 3
    # A = [12,15,18]
    N = 2
    A = [1000000000,1000000000]

  x = 0
  for i in range(N):
    tmp = functools.reduce(fractions.gcd, A[0:i]+A[i+1:])
    if tmp > x:
      x = tmp
  
  print(x)
  
main()

### FIXED CODE ###

import functools
import fractions

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = list(map(int, input().split()))
  else:
    # N = 3
    # A = [7,6,8]
    N = 3
    A = [12,15,18]
    # N = 3
    # A = [1,1000000000,1000000000]

  AL = [0] * N    
  AR = [0] * N
  for i in range(N):
    if i != 0:
      AL[i] = fractions.gcd(AL[i-1],A[i])
    else:
      AL[i] = A[i]
    j = N - i - 1
    if j!= N - 1:
      AR[j] = fractions.gcd(AR[j+1],A[j])
    else:
      AR[j] = A[j]
      
  if 'get_ipython' in globals():   
    print(AL)
    print(AR)
  
  x = 0
  for i in range(N):
    if i == 0:
      tmp = AR[i+1]
    elif i == N - 1:
      tmp = AL[i-1]
    else:
      tmp = fractions.gcd(AL[i-1],AR[i+1])
    if tmp > x: x = tmp
  
  print(x)
    
main()
while True:
    a = int(input())
    b = int(input())
    print(len(str(a + b)))
          



### FIXED CODE ###

while True:
    try:
        a, b = map(int, input().split(" "))
        print(len(str(a + b)))
    except:
        break
t = int(input())
wlist = [0]*4
for i in range(t):
  w = input()
  if w == "AC":
    wlist[0] += 1
  elif w = "WA":
   	wlist[1] += 1
  elif w = "TEL":
    wlist[2] += 1
  else:
    wlist[3] += 1
print("AC x " + wlist[0])
print("WA x " + wlist[1])
print("TEL x " + wlist[2])
print("RE x " + wlist[3])  

### FIXED CODE ###

t = int(input())
wlist = [0]*4
for i in range(t):
    w = input()
    if w == "AC":
        wlist[0] += 1
    elif w == "WA":
        wlist[1] += 1
    elif w == "TLE":
        wlist[2] += 1
    else:
        wlist[3] += 1
print("AC x " + str(wlist[0]))
print("WA x " + str(wlist[1]))
print("TLE x " + str(wlist[2]))
print("RE x " + str(wlist[3]))
w = input()
cnt = collections.Counter()
while True:
    s = [1 if i.lower() == w else 'fin' if i == 'END_OF_TEXT' else 0 for i in input().split()]
    if 'fin' in s:
        break
print(s.count(1))


### FIXED CODE ###

w = input()
t = []
while True:
    s = [1 if i.lower() == w else 'fin' if i == 'END_OF_TEXT' else 0 for i in input().split()]
    t += s
    if 'fin' in s:
        break
print(t.count(1))
n=int(input())
x=list(map(int,list(input())))
def popcount(x):
  ret=0
  while x:
    if x%2==1:ret+=1
    x//=2
  return ret
def f(x):
  ret=0
  while x:
    x%=popcount(x)
    ret+=1
  return ret
from collections import Counter
xpop=Counter(x)[1]
xint_mi,xint_pl=0,0
for i,y in enumerate(x):
  xint_mi+=(pow(2,n-i-1,xpop-1)*y)%(xpop-1)
  xint_mi%=(xpop-1)
  xint_pl+=(pow(2,n-i-1,xpop+1)*y)%(xpop+1)
  xint_pl%=(xpop+1)


for i,y in enumerate(x):
  if y:
    yint=xint_mi-pow(2,n-i-1,xpop-1)
    ypop=xpop-1
    yint%=ypop
  else:
    yint=xint_pl+pow(2,n-i-1,xpop+1)
    ypop=xpop+1
    yint%=ypop
  #print(yint,ypop)
  print(f(yint)+1)


### FIXED CODE ###

n=int(input())
x=input()
import sys
sys.setrecursionlimit(10**7)
if n==1:
  print(0 if x=='1' else 1)
  exit()
def pc(x):
  a=bin(x)[2:]
  return a.count('1')
def func(x):
  if x==0:
    return 0
  else:
    return func(x%pc(x))+1
pcx=x.count('1')
if pcx==0:
  for _ in range(n):
    print(1)
else:
  x0,x1=0,0
  for i in range(n):
    if x[i]=='1':
      if pcx!=1:
        x0+=pow(2,n-1-i,pcx-1)
        x0%=pcx-1
      x1+=pow(2,n-1-i,pcx+1)
      x1%=pcx+1
  for i in range(n):
    ans=0
    if x[i]=='1':
      if pcx==1:
        print(0)
      else:
        xx=x0-pow(2,n-1-i,pcx-1)
        xx%=pcx-1
        print(func(xx)+1)
    else:
      xx=x1+pow(2,n-1-i,pcx+1)
      xx%=pcx+1
      print(func(xx)+1)
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
h,w,m=map(int,input().split())
l={}
u={}
hw=[list(map(int,input().split())) for _ in range(m)]
s=set()

for i in range(m):
    hr,wr=hw[i]
    if hr-1 in u:
        u[hr-1]+=1
    else:
        u[hr-1]=1
    if wr-1 in l:
        l[wr-1]+=1
    else:
        l[wr-1]=1
    s.add((hr-1)*w+wr-1)
resl=0
resu=0
cl=[]
cu=[]
for i in l:
    if resl<l[i]:
        resl=l[i]
        cl=[i]
    elif resl==l[i]:
        cl.append(i)
for i in u:
    if resu<u[i]:
        resu=u[i]
        cu=[i]
    elif resu==u[i]:
        cu.append(i)
ans=0

if len(cu)*len(cl)>=m:
    ans=resl+resu
else:
    for i in cu:
        for j in cl:
            if i*w+j in s:
                res=l[j]+u[i]-1
            else:
                res=l[i]+u[j]
            ans=max(res,ans)
print(ans)

### FIXED CODE ###

#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
h,w,m=map(int,input().split())
l={}
u={}
hw=[list(map(int,input().split())) for _ in range(m)]
s=set()

for i in range(m):
    hr,wr=hw[i]
    if hr-1 in u:
        u[hr-1]+=1
    else:
        u[hr-1]=1
    if wr-1 in l:
        l[wr-1]+=1
    else:
        l[wr-1]=1
    s.add((hr-1)*w+wr-1)
resl=0
resu=0
cl=[]
cu=[]
for i in l:
    if resl<l[i]:
        resl=l[i]
        cl=[i]
    elif resl==l[i]:
        cl.append(i)
for i in u:
    if resu<u[i]:
        resu=u[i]
        cu=[i]
    elif resu==u[i]:
        cu.append(i)
ans=0
if resu==m or resl==m :
  print(m)
  exit()
if len(cu)*len(cl)>m:
    ans=resl+resu
else:
    for i in cu:
        for j in cl:
            if i*w+j in s:
                res=resl+resu-1
            else:
                res=resl+resu
            ans=max(res,ans)
print(ans)
n, m = map(int, input().split())
datalist = [0 for i in range(n)]
ans = 0
root = [[] for i in range(n)]
for i in range(m):
    x, y, z = map(int, input().split())
    root[x - 1].append(y - 1)
    root[y - 1].append(x - 1)

def solve(now, root):
    global ans
    #print(now, ans)
    if datalist[now] == 0:
        ans += 1
    datalist[now] = 1
    for j in range(len(root[now])):
        if datalist[root[now][j]] == 0:
            datalist[root[now][j]] = 1
            solve(root[now][j], root)

for i in range(n):
    if datalist[i] == 0:
        #print(i,i,i)
        solve(i, root)

for i in datalist:
    if i == 0:
        ans += 1

#print(datalist)
print(ans )

### FIXED CODE ###

import sys
sys.setrecursionlimit(10000000)

def visit_tree(now, num):
    visited[now] = num
    for i in range(len(tree[now])):
        if not visited[tree[now][i]]:
            visit_tree(tree[now][i], num)

n, m = map(int, input().split())
tree = [[] for _ in range(n)]
for i in range(m):
    x, y, z = map(int, input().split())
    tree[x - 1].append(y - 1)
    tree[y - 1].append(x - 1)

visited = [0 for _ in range(n)]
num = 0
for i in range(n):
    if not visited[i]:
        num += 1
        visit_tree(i, num)

print(num)
n=int(input())
ans=1
a=list(map(int,input().split()))
for i in range(n):
  ans*=a[i]
if ans>=10**18:
  print(-1)
else:
  print(ans)


### FIXED CODE ###

a,b=map(int,input().split())
print(a*b)
n, x = map(int, input().split())
l = list(map(int, input().split()))

d = 0
ans = 0
for i in l:
    if d > x:
        break
    else:
        d += i
        ans += 1

if x > sum(d):
    ans += 1

print(ans)

### FIXED CODE ###

n, x = map(int, input().split())
l = list(map(int, input().split()))

d = 0
ans = 0
for i in l:
    if d > x:
        break
    else:
        d += i
        ans += 1

if x >= sum(l):
    ans += 1

print(ans)
w,h,x,y,r = map(input().split())
print(['No','Yes'][r<=x<=w-r and r<=y<=h-r])


### FIXED CODE ###

w,h,x,y,r = map(int,input().split())
print(['No','Yes'][r<=x<=w-r and r<=y<=h-r])
s=int(input())
s.sort()
flag=True
if s[0]==s[1]:
    if s[1]!=s[1]:
        if s[2]==s[3]:
            print("Yes")
            flag=False
if flag:
    print("No")


### FIXED CODE ###

s=list(input())
s.sort()
flag=True
if s[0]==s[1]:
    if s[1]!=s[2]:
        if s[2]==s[3]:
            print("Yes")
            flag=False
if flag:
    print("No")
import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
count = 0
for i in itertools.permutations([i + 1 for i in range(n)], n):
    if i == p:
        a = count
    elif i == q:
        b = count
    count += 1
print(abs(a - b))

### FIXED CODE ###

import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
count = 0
for i in itertools.permutations([i + 1 for i in range(n)], n):
    if i == p:
        a = count
    if i == q:
        b = count
    count += 1
print(abs(a - b))