Harryxun/stf_run huggingface dataset:
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]

n,q = LI()

v = [[] for i in range(n)]
for i in range(n-1):
	a,b = LI()
	a -= 1
	b -= 1
	v[a].append(b)
	v[b].append(a)

f = [0]*n
for i in range(q):
	p,x = LI()
	p -= 1
	f[p] += x

def dfs(x,d,s):
	for y in v[x]:
		if d[y]:
			s += f[y]
			ans[y] = s
			d[y] = 0
			dfs(y,d,s)
			s -= f[y]

ans = [0]*n
d = [1]*n
d[0] = 0
ans[0] = f[0]
s = f[0]
dfs(0,d,s)
print(*ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

def LI(): return [int(x) for x in sys.stdin.readline().split()]

n,q = LI()

v = [[] for i in range(n)]
for i in range(n-1):
	a,b = LI()
	a -= 1
	b -= 1
	v[a].append(b)
	v[b].append(a)

f = [0]*n
for i in range(q):
	p,x = LI()
	p -= 1
	f[p] += x

def dfs(x,d,s):
	for y in v[x]:
		if d[y]:
			s += f[y]
			ans[y] = s
			d[y] = 0
			dfs(y,d,s)
			s -= f[y]

ans = [0]*n
d = [1]*n
d[0] = 0
ans[0] = f[0]
s = f[0]
dfs(0,d,s)
print(*ans)
def button(a,b):
    if a>b:
        return 2*int(a)-1
    if a<b:
        return 2*int(b)-1
    if a==b:
        return int(a)+int(b)
a = input()
b = input()
button(a,b)

### FIXED CODE ###

def button(a,b):
    if a==b:
        return int(a)+int(b)
    else:
        return 2*int(max(a,b))-1
a,b = map(int, input().split())
print(button(a,b))
//#define _GLIBCXX_DEBUG
//#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    int a[n];
    cout << (((n-k)+(k-2))/(k-1))+1 << "\n";
}

### FIXED CODE ###

import math

n,k = map(int,input().split())
a = list(map(int,input().split()))
print(math.ceil((n-k)/(k-1))+1)
from collections import deque
import sys
input = sys.stdin.readline

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

g = [[] for _ in range(n)]  # 隣接リスト

for _ in range(m):
    a, b = [int(x) for x in input().split()]
    g[a-1].append(b-1)
    g[b-1].append(a-1)


def bfs(u):
    queue = deque([u])
    d = [None] * n  # uからの距離の初期化
    d[u] = 0  # 自分との距離は0
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] is None:
                d[i] = d[v] + 1
                queue.append(i)
    return d


# 0からの各頂点の距離
d = bfs(0)
if len(d) != 0:
  print("Yes")
  for i in d[1:]:
    print(i)
else:
  print("No")

### FIXED CODE ###

n = int(input())
ho = int(str(n)[-1])

if ho in [2, 4, 5, 7, 9]:
    print('hon')
elif ho in [0, 1, 6, 8]:
    print('pon')
else:
    print("bon")
A, B = map(int, input(), split())

x = A + B
y = A - B
z = A * B
print(max(x, y, z))

### FIXED CODE ###

A, B = map(int, input(). split())

x = A + B
y = A - B
z = A * B
print(max(x, y, z))
A, B = map(int, input().split())

if A < 0 or b < 0:
    print(abs(A) + abs(B))
else:
    print(A * B)


### FIXED CODE ###

A, B = map(int, input().split())

add = A + B
sub = A - B
mul = A * B

if add > sub and add > mul:
    print(add)
elif sub > add and sub > mul:
    print(sub)
elif mul > add and mul > sub:
    print(mul)
else:
    print(add)
S = ["Sunny","Cloudy","Rainy"]
s = input()
p = 0
for i in range(len(S)):
    if(i == len(S)):
        print(S[0])
    if(S[i] == s):
        print(S[i+1])
        break

### FIXED CODE ###

S = ["Sunny","Cloudy","Rainy"]
s = input()
for i in range(len(S)):
    if(i == len(S)-1):
        print(S[0])
        break
    if(S[i] == s):
        print(S[i+1])
        break
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# 数値の読み込み
x = int(input())
y = int(intpu())

res = 0
if x < 0:
    res = res + 1
if y < 0:
    res = res + 1

res = res + (abs(y)-abs(x))

print(res)

### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# 数値の読み込み
x,y = [int(i) for i in input().split()]

res = 0


if abs(y) > abs(x):
    # |x| < |y|
    if x < 0:
        res = res + 1
    if y < 0:
        res = res + 1
    res = res + abs(abs(y)-abs(x))
else :
    # x > y
    if x > 0:
        res = res + 1
    if y > 0:
        res = res + 1
    res = res + abs(abs(y)-abs(x))


print(res)
s,w = map(int,input.split())
if s > w:
  print("saffe")
else:
  print("unsafe")

### FIXED CODE ###

s,w = map(int,input().split())
if s > w:
  print("safe")
else:
  print("unsafe")
n,k=map(int,input().split())
if(n>k):
    if(n%k==0):
        print(0)
    else:
        print(min((n%k),(n//k+1)*k-n))
elif(n==k):
    print(0)
else:
    if(k%n==0):
        print(n)
    else:
        if(k-n)<n:
            print(k-n)
        else:
            print(n)



### FIXED CODE ###

n,k=map(int,input().split())
if(n>k):
    if(n%k==0):
        print(0)
    else:
        print(min((n%k),(n//k+1)*k-n))
elif(n==k):
    print(0)
elif(n==0):
    print(0)
else:
    if(k%n==0):
        print(n)
    else:
        if(k-n)<=n:
            print(k-n)
        else:
            print(n)
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = []
for j in range(N):
    b = int(input())
    B.append(b)
A = np.array(A)
B = np.array(B)
boolean_matrix = np.isin(A, B)
if boolean_matrix.sum(axis=1).max() >= 3 or \
boolean_matrix.sum(axis=0).max() >= 3 or \
np.diag(boolean_matrix).sum() >= 3 or \
np.diag(np.fliplr(boolean_matrix)).sum() >= 3:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import numpy as np
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = []
for j in range(N):
    b = int(input())
    B.append(b)
A = np.array(A)
B = np.array(B)
boolean_matrix = np.isin(A, B)
if boolean_matrix.sum(axis=1).max() >= 3 or \
   boolean_matrix.sum(axis=0).max() >= 3 or \
   np.diag(boolean_matrix).sum() >= 3 or \
   np.diag(np.fliplr(boolean_matrix)).sum() >= 3:
    print('Yes')
else:
    print('No')
loops = int(input())
LIST = [int(input()) for _ in range(loops)]

print(max(LIST) - min(LIST))

### FIXED CODE ###

# coding: utf-8
loops = int(input())
LIST = list(map(int, input().split()))

print(max(LIST) - min(LIST))
N = int(input())
H = np.array(map(int, input().split()))
tmp=[]
for i in range(len(H)-1):
    tmp.append(all([all(H[:i]<=[H[i]]), all([H[i]]<=H[i+1:])]))
print(sum(tmp))

### FIXED CODE ###

import numpy as np
N = int(input())
H = np.array(list(map(int, input().split())))
tmp = []
for i in range(1, len(H)):
    tmp.append(all(H[:i]<=H[i]))
print(sum(tmp)+1)
"""
the condition is quite simple actually.
each element of A and B must multiply to the same value.
to minimise the total of B, simply make that value as small
as possible (since A is fixed).

lcm(2, 3, 4) = 12
therefore B is
12/2, 12/3, 12/4
and the sum of B is
12/2 + 12/3 + 12/4

lcd of a list is loop: lcd(partial, new_value)
lcd(a, b) = ab / gcd(a, b)
"""

def gcd(x, y):
  return 1


def lcm(list_ints):
    lcm_ongoing = 1
    for val in list_ints:
        lcm_ongoing = int(round(val*lcm_ongoing/gcd(val, lcm_ongoing)))
    return lcm_ongoing


def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = sum(int(round(lcm_of_A/value)) for value in A)
    modulo_value = int(int(10e9)+7)
    return ans % modulo_value


if __name__ == "__main__":
    test1 = \
"""3
2 3 4"""
    test2 = \
"""5
12 12 12 12 12"""
    test3 = \
"""3
1000000 999999 999998"""
    test = test3
    # N = int(test.split("\n")[0])
    # A = list(map(int, test.split("\n")[1].split()))
    N = int(input())
    A = list(map(int, input().split()))
    print(flatten(N, A))


### FIXED CODE ###

"""
the condition is straightforward.
each element of A and B must multiply to the same value.
to minimise the total of B, simply make that value as small
as possible (since A is fixed).

lcm(2, 3, 4) = 12
therefore B is
12/2, 12/3, 12/4
and the sum of B is
12/2 + 12/3 + 12/4

lcd of a list is loop: lcd(partial, new_value)
lcd(a, b) = ab / gcd(a, b)
"""

from fractions import gcd


def lcm(list_ints):
    lcm_ongoing = 1
    for val in list_ints:
        lcm_ongoing = val*lcm_ongoing//gcd(val, lcm_ongoing)
    return lcm_ongoing


def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = sum(lcm_of_A//value for value in A)
    modulo_value = int(int(10e8)+7)
    return ans % modulo_value


if __name__ == "__main__":
    test1 = \
"""3
2 3 4"""
    test2 = \
"""5
12 12 12 12 12"""
    test3 = \
"""3
1000000 999999 999998"""
    test = test3
    # N = int(test.split("\n")[0])
    # A = list(map(int, test.split("\n")[1].split()))
    N = int(input())
    A = list(map(int, input().split()))
    print(flatten(N, A))
from collections import deque

INF = float("inf")

H, W, K = map(int, input().split())
A = [list(input()) for _ in range(H)]

Si, Sj = (0, 0)
for i, a in enumerate(A):
    if "S" in a:
        Si, Sj = (i, a.index("S"))
        break

dist = [[INF] * W for _ in range(H)]
dist[Si][Sj] = 0


ans = INF

Q = deque([(Si, Sj)])
while Q:
    i, j = Q.popleft()

    ans = min(
        ans,
        1 + (i + K - 1) // K,
        1 + (j + K - 1) // K,
        1 + (H - 1 - i + K - 1) // K,
        1 + (W - 1 - j + K - 1) // K
    )

    if dist[i][j] == K:
        continue

    distance = dist[i][j] + 1

    for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        ni, nj = i + di, j + dj

        if not (0 <= ni < H or 0 <= nj < W) and A[ni][nj] == "#":
            continue

        if dist[ni][nj] > distance:
            dist[ni][nj] = distance
            Q.append((ni, nj))

print(ans)


### FIXED CODE ###

from collections import deque

INF = float("inf")

H, W, K = map(int, input().split())
A = [list(input()) for _ in range(H)]

Si, Sj = (0, 0)
for i, a in enumerate(A):
    if "S" in a:
        Si, Sj = (i, a.index("S"))
        break

dist = [[INF] * W for _ in range(H)]
dist[Si][Sj] = 0


ans = INF

Q = deque([(Si, Sj)])
while Q:
    i, j = Q.popleft()

    ans = min(
        ans,
        1 + (i + K - 1) // K,
        1 + (j + K - 1) // K,
        1 + (H - 1 - i + K - 1) // K,
        1 + (W - 1 - j + K - 1) // K
    )

    if dist[i][j] == K:
        continue

    distance = dist[i][j] + 1

    for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        ni, nj = i + di, j + dj

        if not (0 <= ni < H and 0 <= nj < W and A[ni][nj] == "."):
            continue

        A[ni][nj] = "#"

        if dist[ni][nj] > distance:
            dist[ni][nj] = distance
            Q.append((ni, nj))

print(ans)
n = int(input())
if n==1:
  print("Hello World")
else:
  i = [int(input()) for i in range(3)]
  print(i[0]+i[1])

### FIXED CODE ###

n = int(input())
if n==1:
  print("Hello World")
else:
  i = [int(input()) for i in range(2)]
  print(i[0]+i[1])
while True:
    (n, r) = [int(x) for x in input().split()]
    if n==0 and r==0:
        exit()
    cards = [n-i for i in range(n)]
    for _ in range(r):
        (p, c) = [int(x) for x in input().split()]
        cards = cards[p-1:c] + cards[p-1:p-1+c] + cards[p-1+c:]
    print(cards[0])

### FIXED CODE ###

while True:
    (n, r) = [int(x) for x in input().split()]
    if n==0 and r==0:
        exit()
    cards = [n-i for i in range(n)]
    for _ in range(r):
        (p, c) = [int(x) for x in input().split()]
        cards = cards[p-1:p-1+c] + cards[:p-1] + cards[p-1+c:]
    print(cards[0])
n = int(input())
num = 1
while num * (num + 1) <= 2 * n:
  num += 1
now = n
for i in range(num,0,-1):
  if now >= i:
    print(i)
    now -= i

### FIXED CODE ###

s = str(input())
if len(s) == 2:
  print(s)
else:
  print(s[2] + s[1] + s[0])
N,T=map(int, input().split())
ans=10**9
for i in range(N):
  c,t=map(int, input().split())
  if t<=T:
    ans=min(ans,c)
if ans=10**9:
  print("TLE")
else:
  print(ans)

### FIXED CODE ###

N,T=map(int, input().split())
ans=10**9
for i in range(N):
  c,t=map(int, input().split())
  if t<=T:
    ans=min(ans,c)
if ans==10**9:
  print("TLE")
else:
  print(ans)
bingo = []
for _ in range(3):
    bingo.append(list(map(int,input().split())))

cl = [[0,0,0],[0,0,0],[0,0,0]]

n = int(input())
st = set()
for _ in range(n):
    st.add(int(input()))

for _ in range(len(st)):
    for i in range(3):
        for j in range(3):
            if bingo[i][j] in st:
                cl[i][j] = 1

if sum(cl[0]) == 3 or sum(cl[1]) == 3 or sum(cl[2]) == 3:
    print('Yes')
elif sum(cl[:][0]) == 3 or sum(cl[:][1]) == 3 or sum(cl[:][2]) == 3:
    print('Yes')
elif cl[0][0]+cl[1][1]+cl[2][2] == 3 or cl[0][2]+cl[1][1]+cl[0][2] == 3:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import sys

n,m = map(int, input().split())
num = [0]*n
count = [0]*n

for _ in range(m):
    b,c = map(int, input().split())
    if num[b-1] != c and count[b-1] > 0:
        print(-1)
        sys.exit()
    count[b-1]+=1
    num[b-1] = c    

if n == 3 and num[0] == 0 and count[0] == 0:
    num[0] = 1
elif n == 3 and num[0] == 0 and count[0]>0:
    print(-1)
    sys.exit()
elif n == 2 and num[0] == 0 and count[0] == 0:
    num[0] = 1
elif n == 2 and num[0] == 0 and count[0] >  0:
    print(-1)
    sys.exit()

ans = ""
for i in range(n):
    ans+=str(num[i])
print(ans)
weat= input()
seaS = 'S'
seaR = 'R'
a = 0
b = 0
c = 0
imput = 0
for alp in wea:
  if a == 0:
    if alp == seaS:
      a = 1
    if alp == seaR:
      a = 2
  if b == 0 and a != 0:
    if alp == seaS:
      b = 1
    if alp == seaR:
      b = 2
  if c == 0 and a != 0 and b != 0:
    if alp == seaS:
      c = 1
    if alp == seaR:
      c = 2
if a or b or c == 2:
  imput = 1
if a and b == 2 or b and c == 2:
  imput = 2
if a and b and c == 3:
  imput = 3

print(imput)


### FIXED CODE ###

weat= input()
imput = 0
if weat == 'SSS':
  imput = 0
if weat == 'SSR' or weat == 'RSS' or weat == 'SRS' or weat == 'RSR':
  imput = 1
if weat == 'SRR' or weat == 'RRS':
  imput = 2
if weat == 'RRR':
  imput = 3

print(imput)
num_str = input()
odd_num = 0
if (len(num_str) == 2):
  odd_num = 9
else if (len(num_str) == 3):
  odd_num = 9 + (int(num_str) - 99)
else if (len(num_str) == 4):
  odd_num = 909
else if (len(num_str) == 5):
  odd_num = 909 + (int(num_str) - 9999)
else:
  odd_num = 90909
print(odd_num)

### FIXED CODE ###

num_str = input()
if len(num_str) == 1:
  odd_num = int(num_str)
elif len(num_str) == 2:
  odd_num = 9
elif len(num_str) == 3:
  odd_num = 9 + (int(num_str) - 99)
elif len(num_str) == 4:
  odd_num = 909
elif len(num_str) == 5:
  odd_num = 909 + (int(num_str) - 9999)
else:
  odd_num = 90909
  
print(odd_num)
n = int(input())
P = [i for i in range(n)]
cnt = 0
for i in range(1:n-1):
    if (P[i-1] < P[i] < P[i+1]) or (P[i-1] > P[i] > P[i+1]):
        cnt += 1
print(cnt)

### FIXED CODE ###

    
n = int(input())
    
P = list(map(int, input().split()))
cnt = 0
for i in range(1, n-1):
    if (P[i-1] < P[i] < P[i+1]) or (P[i-1] > P[i] > P[i+1]):
        cnt += 1
    
print(cnt)
import sys
input = sys.stdin.readline

def main():
    n , m = map( int, input().split() )
    Sets = []

    Dicto = [ -1 for i in range(n + 1)]

    for i in range( m ):
        a , b = map( int , input().split() )
        if Dicto[a] == -1 and Dicto[b] == -1:
            Sets.append( set( [a,b] ) )
            x_i = len(Sets)
            Dicto[ a ] = x_i - 1
            Dicto[ b ] = x_i - 1
        elif Dicto[ a ] != -1 and Dicto[ b ] == -1:
            Sets[ Dicto[a] ].add( b )
            Dicto[ b ] = Dicto[a]
        elif Dicto[ b ] != -1 and Dicto[ a ] == -1:
            Sets[ Dicto[b] ].add( a )
            Dicto[ a ] = Dicto[b]
        elif Dicto[ b ] != -1 and Dicto[ a ] != -1 and Dicto[ a ] != Dicto[ b ]:
            print('!!' , Dicto[ a ] , Dicto[ b ])
            if Dicto[ b ] > Dicto[ a ]:
                set_x = Sets.pop( Dicto[b] )
                Sets[ Dicto[a] ] |= ( set_x )
                l_set_x = list( set_x )
                for j in l_set_x:
                    Dicto[j] = Dicto[a]

            else:
                set_x = Sets.pop( Dicto[a] )
                Sets[ Dicto[b] ] |= ( set_x )
                l_set_x = list( set_x )
                for j in l_set_x:
                    Dicto[j] = Dicto[b]

    #print(Sets)
    #print(Dicto)

    max_len = 1

    for i in range( len(Sets) ):
        if max_len < len( Sets[i] ):
            max_len = len( Sets[i] )

    print(max_len)


main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    n , m = map( int, input().split() )
    Sets = []

    Dicto = [ -1 for i in range(n + 1)]

    for i in range( m ):
        a , b = map( int , input().split() )
        if Dicto[a] == -1 and Dicto[b] == -1:
            Sets.append( set( [a,b] ) )
            x_i = len(Sets)
            Dicto[ a ] = x_i - 1
            Dicto[ b ] = x_i - 1
        elif Dicto[ a ] != -1 and Dicto[ b ] == -1:
            Sets[ Dicto[a] ].add( b )
            Dicto[ b ] = Dicto[a]
        elif Dicto[ b ] != -1 and Dicto[ a ] == -1:
            Sets[ Dicto[b] ].add( a )
            Dicto[ a ] = Dicto[b]
        elif Dicto[ b ] != -1 and Dicto[ a ] != -1 and Dicto[ a ] != Dicto[ b ]:
            if Dicto[ b ] > Dicto[ a ]:
                set_x = Sets[Dicto[b]]
                Sets[ Dicto[a] ] |= ( set_x )
                l_set_x = list( set_x )
                for j in l_set_x:
                    Dicto[j] = Dicto[a]

            else:
                set_x = Sets[Dicto[a]]
                Sets[ Dicto[b] ] |= ( set_x )
                l_set_x = list( set_x )
                for j in l_set_x:
                    Dicto[j] = Dicto[b]

    #print(Sets)
    #print(Dicto)

    max_len = 1

    for i in range( len(Sets) ):
        if max_len < len( Sets[i] ):
            max_len = len( Sets[i] )

    print(max_len)


main()
S,T = input().split()
A,B = int(input().split())
U = input()
if U == S:
  	print(A-1,B)
elif U == T:
    print(A,B-1)
    

### FIXED CODE ###

S,T = input().split()
A,B = map(int,input().split())
U = input()
if U == S:
  	print(A-1,B)
elif U == T:
    print(A,B-1)
k, n = map(int,input().split())
a = list(map(int, input().split()))
ans1 = max(a) - min(a)
for i in range (0,n):
    if a[i] >= (k/2):
        a[i] = a[i] - k
ans2 = abs(max(a) - min(a))
print(min(ans1,ans2))

### FIXED CODE ###

s = input()
if s[2] == s[3] and s[4] == s[5]:
  print("Yes")
else:
  print("No")
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
for i in range(n-1,-1,-1):
    temp=0
    for j in range(2*i,n,i): temp+=ans[j]
    if a[i]!=temp%2: ans[i]=1
print(sum(ans))                                 
for i in range(n):
    if ans[i]==1: print(i+1,end=" ")

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=[0]*(n+1)
for i in range(n,0,-1):
    temp=0
    for j in range(i,n+1,i): temp+=ans[j]
    if a[i-1]!=temp%2: ans[i]=1
print(sum(ans))           
for i in range(n+1):
    if ans[i]==1: print(i,end=" ")
R,C,k=map(int,input().split())
h=[]
w=[]
v=[]

for i in range(k):
  ss,tt,uu=map(int,input().split())
  h.append(ss-1)
  w.append(tt-1)
  v.append(uu)
  
dp=[[[0]*(C+1) for i in range(R+1)] for _ in range(k+1)]

for i in range(k):
  for s in range(R+1):
    cnt=0
    for t in range(C+1):
      if h[i]>s or w[i]>t:
        dp[i+1][s][t]=dp[i][s][t]

      else:
        s==h[i] and t==w[i]:
          

      if dp[i+1][s][t]!=dp[i+1][s][t-1]:
        cnt+=1

print(dp[-1][-1][-1])

### FIXED CODE ###

r,c,k=map(int,input().split())
lst=[[0]*(c+1) for i in range(r+1)]
for i in range(k):
  s,t,u=map(int,input().split())
  lst[s][t]=u


dp1=[[0]*(c+1) for i in range(r+1)]
dp2=[[0]*(c+1) for i in range(r+1)]
dp3=[[0]*(c+1) for i in range(r+1)]

for i in range(1,r+1):
  for j in range(1,c+1):
    dp1[i][j]=max(dp1[i][j-1],dp1[i-1][j]+lst[i][j],dp2[i-1][j]+lst[i][j],dp3[i-1][j]+lst[i][j])
    dp2[i][j]=max(dp2[i][j-1],dp1[i][j-1]+lst[i][j])
    dp3[i][j]=max(dp3[i][j-1],dp2[i][j-1]+lst[i][j])

print(max(dp1[-1][-1],dp2[-1][-1],dp3[-1][-1],0))
import math
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
Nl = list(range(1, N+1))
p = list(itertools.permutations(Nl,N))
c1 = 1
c2 = 1
for v in range(math.factorial(N)):
    if list(p[v]) == P:
        break
    else:
        c1 += 1
for v in range(math.factorial(N)):
    if list(p[v]) == Q:
        break
    else:
        c2 += 1
print(abs(c1-c2))

### FIXED CODE ###

import itertools
import math
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
Nl = list(range(1, N+1))
p = list(itertools.permutations(Nl,N))
NN = math.factorial(N)
c1 = 1
c2 = 1
for v in range(NN):
    if list(p[v]) == P:
        break
    else:
        c1 += 1
for v in range(NN):
    if list(p[v]) == Q:
        break
    else:
        c2 += 1
print(abs(c1-c2))
N = int(input())
D = list(map(int,input().split()))
TotalList = []

for A in range(N-1):
  for B in range(A+1):
    D(A)*D(B) = K
    TotalList.append(K)

print(sum(TotalList))

### FIXED CODE ###

N = int(input())
D = list(map(int,input().split()))
TotalList = 0

for A in range(N-1):
  for B in range(A+1,N):
    TotalList += D[A]*D[B]
    

print(TotalList)
s = input()

def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            print(f + "=7")
            exit()
    else:
        dfs(i + 1, f + "+" + s[i + 1], sum + int(s[i + 1]))
        dfs(i + 1, f + "-" + s[i + 1], sum - int(s[i + 1])


dfs(0, s[0], int(s[0]))

### FIXED CODE ###

s = input()

for bit in range(1 << 3):
    ans = int(s[0])
    f = s[0]

    for i in range(3):
        if bit & (1 << i):
            ans += int(s[i + 1])
            f += "+"
        else:
            ans -= int(s[i + 1])
            f += "-"
        f += s[i + 1]

    if ans == 7:
        print(f + '=7')
        break
S=input()
K=float(input())
lis=list(S)
ss=set(lis)

if len(ss)==1:
  print(S[0])
else:
  if K<=len(S):
    check_list=lis[:K]
    check_set=set(check_list)
    if len(check_set)==1:
      print(check_list[0])
    else:
      for num in lis:
        if int(num)!=1:
          print(int(num))
        break            
  else:
    for num in lis:
      if int(num)!=1:
        print(int(num))
        break

### FIXED CODE ###

S=input()
K=float(input())
lis=list(S)
ss=set(lis)

if len(ss)==1:
  print(S[0])
else:
  if K<=len(S):
    check_list=lis[:int(K)]
    check_set=set(check_list)
    if len(check_set)==1:
      print(check_list[0])
    else:
      for num in lis:
        if int(num)!=1:
          print(int(num))
          break            
  else:
    for num in lis:
      if int(num)!=1:
        print(int(num))
        break
n,m = map(int,input().split())

par = [[] for i in range(n)]
op = [[]for i in range(n)]
for i in range(n+m-1):
    x,y = map(int,input().split())
    x-=1
    y-=1
    par[y].append(x)
    op[x].append(y)

res = [-1]*n
x = -1

for i in range(n):
    if len(par[i])==0:
        res[i] = 0
        x = i
        break


used = [0]*n
used[x]=1
def g(x):
    for pe in par[x]:
        if used[pe]==0:
            return False
    return True
#xの下のusedとresを埋める
def f(x):
    for e in op[x]:
        if used[e]==0 and g(e):
            used[e]=1
            res[e]=x+1
            f(e)
f(x)
for i in range(n):
    print(res[i])

### FIXED CODE ###

from collections import deque

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

up = [[] for i in range(n)]
down= [[]for i in range(n)]
for i in range(n+m-1):
    a,b = map(int,input().split())
    a -=1
    b -=1
    up[b].append(a)
    down[a].append(b)

res = [-1]*n
root = -1

for i in range(n):
    if len(up[i])==0:
        res[i] = 0
        root = i
        break

#0なら不使用
used = [0]*n
used[root]=1

#yの親に不使用が一つも存在しなければTrue
def g(y):
    for pe in up[y]:
        if used[pe]==0:
            return False
    return True
    
#zの下のusedとresを埋める
def f(z):
    for e in down[z]:
        if used[e]==0 and g(e):
            res[e]=z+1
            tank2.append(e)
            usedtank.append(e)
c = 1
tank = deque([root])
tank2 = deque([root])
usedtank = []
while c != n:
    tank = tank2
    tank2 = deque([])
    usedtank = []
    while len(tank)!=0:
        f(tank.popleft())
    for usede in usedtank:
        used[usede]=1
    c += len(tank2)
    
for i in range(n):
    print(res[i])
a, b = map(int, input().split())

print(int(a*b))

### FIXED CODE ###

a, b = input().split()

a = int(a)
b_unchi = b.split(".")
b_int = int(b_unchi[0])
b_float = int(b_unchi[1])
bbb = b_int * 100 + b_float
s = a * bbb
print(s // 100)
salmonize
n = int(input())
l = []
for i in range(1,n+1):
  s,p = input().split()
  l.append((s,-int(p),i))
l.sort()
for x in l:
  print(x[2])


### FIXED CODE ###

N = int(input())
l = []

for i in range(N):
  s,p=input().split()
  p=100-int(p)
  l.append((s,p,i+1))
l.sort()
for i in range(N):
  print(l[i][2])