Harryxun/stf_run huggingface dataset:
# ABC79 D - Wall
from scipy.sparse.csgraph import floyd_warshall
from itertools import permutations

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

C = floyd_warshall(C)  

cost = 0
for i in range(H):
    for a in A[i]:
        if a != -1:
            cost += C[a][1]

print(int(cost))

### FIXED CODE ###

from scipy.sparse.csgraph import floyd_warshall
from itertools import permutations

H, W = map(int, input().split())
C = [[0]*10 for _ in range(10)]
A = [[0]*W for _ in range(H)]

for i in range(10):
  C[i] = list(map(int, input().split()))

C = floyd_warshall(C)  

cost = 0
for i in range(H):
  A[i] = list(map(int, input().split()))
  for a in A[i]:
    if a != -1:
      cost += C[a][1]

print(int(cost))
N,M=map(int,input().split())
a=[]
b=[0]*N
for i in range(M):
    a.append(int(input()))
j=0
if a[0]==1:
    b[0]=0
    b[1]=1
elif a[0]==2:
    b[0]=1
    b[1]=1
else:
    b[0]=1
    b[1]=2
for i in range(N-2):
    if j==M-1 or ((i+2)!=a[j] and (i+1)!=a[j]):
        b[i+2]=b[i+1]+b[i]
    if j>0 and a[j]==a[j-1]+1:
        b[N-1]=0
    if j+1<M and a[j+1]==a[j]+1:
        b[N-1]=0
    elif (i+2)==a[j]:
        b[i+2]=b[i]
    elif j+1<M and (i+1)==a[j]:
        j+=1
        b[i+2]=b[i+1]
    elif (i+1)==a[j]:
        b[i+2]=b[i+1]
print(b[N-1]%1000000007,b)

### FIXED CODE ###

N,M=map(int,input().split())
a=[]
b=[0]*N
for i in range(M):
    a.append(int(input()))
if M==0:
    j=-1
else:
    j=0
if N==1:
    b[0]=1
elif M>0 and a[0]==1:
    b[0]=0
    b[1]=1
elif M>0 and a[0]==2:
    b[0]=1
    b[1]=1
else:
    b[0]=1
    b[1]=2
for i in range(N-2):
    if j==M-1 or (j>=0 and (i+2)!=a[j] and (i+1)!=a[j]):
        b[i+2]=b[i+1]+b[i]
    if j>0 and a[j]==a[j-1]+1:
        b[N-1]=0
    if j+1<M and a[j+1]==a[j]+1:
        b[N-1]=0
    elif j>=0 and (i+2)==a[j]:
        b[i+2]=b[i]
    elif j>=0 and j+1<M and (i+1)==a[j]:
        j+=1
        b[i+2]=b[i+1]
    elif j>=0 and (i+1)==a[j]:
        b[i+2]=b[i+1]
print(b[N-1]%1000000007)
N, K = 13, 1
S = "0000011100110"

# N, K = 2, 2
# S = "00"


# N, K = 1, 1
# S = "1"
#
#
# N, K = 5, 1
# S = "00010"
#
N, K = map(int,input().split())
S = input()

def calculate(n, k, s):
    s = list(s)

    result = [{'start': 0, 'end': 0}]
    for i in range(n):

        previous = s[i - 1]
        current = s[i]

        if i == 0:
            if s[i] == '1':
                result.append({'start': 0})
        else:
            if (current == '0') and (previous == '1'):
                res = result[-1]
                res.__setitem__('end', i)
                result[-1] = res

            if (current == '1') and (previous == '0'):
                result.append({'start': i})

            if i == n - 1 and s[i] == '1':
                res = result[-1]
                res.__setitem__('end', i + 1)
                result[-1] = res

    result.append({'start': n, 'end': n})
    maxValue = 0
    if len(result) > k:
        for i in range(len(result) - k):
            val = result[i + k]['end'] - result[i]['start']
            maxValue = max(val, maxValue)
    else:
        maxValue = max(maxValue, result[-1]['end'] - result[0]['start'])
    print(maxValue)


calculate(N, K, S)


### FIXED CODE ###

N, K = map(int,input().split())
S = input()

def calculate(n, k, s):
    s = list(s)

    result = [{'start': 0, 'end': 0}]
    for i in range(n):

        previous = s[i - 1]
        current = s[i]

        if i == 0:
            if s[i] == '1':
                result.append({'start': 0})
        else:
            if (current == '0') and (previous == '1'):
                res = result[-1]
                res.__setitem__('end', i)
                result[-1] = res

            if (current == '1') and (previous == '0'):
                result.append({'start': i})

        if i == n - 1 and s[i] == '1':
            res = result[-1]
            res.__setitem__('end', i + 1)
            result[-1] = res

    result.append({'start': n, 'end': n})


    # print(result)
    maxValue = 0
    if len(result) > k:
        for i in range(len(result) - k):
            val = result[i + k]['end'] - result[i]['start']
            maxValue = max(val, maxValue)
    else:
        maxValue = max(maxValue, result[-1]['end'] - result[0]['start'])


    print(maxValue)


calculate(N, K, S)
n, m = map(int, input().split())
ps = [list(input().split()) for _ in range(m)]

str_list = ["WA"] * n # 問題数分のリスト
int_list = [0] * n    # 問題数分のリスト
num = 0
ac = 0    

for p_, s in  ps: # p：問題番号 s：AC or WA
    p = int(p_) - 1
    if s == "AC":
        str_list[p] = "AC" # WAリスト
    else: # s!= WA
        if str_list[p] !="AC": # まだACされていない問題が、WAだったら
            int_list[p] += 1   # 問題ごとのWAの回数

for i in range(n): 
    if str_list[i] == "AC": ペナルティはACできた問題のみ
        num += int_list[i] # WAの回数
        ac += 1            # ACの数

print(ac, num)

### FIXED CODE ###

from collections import defaultdict

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

d = defaultdict(int)
ans = 0
pena = 0

for _ in range(m):
    p, s = input().split()
    if s == "AC":
        if d[p] == -1:
            continue
        else:
            ans += 1
            pena += d[p]
            d[p] = -1
    else:
        if d[p] == -1:
            continue
        else:
            d[p] += 1

print(ans, pena)
def main():
    W, H, x, y = map(int, f.input().split())
    ans = W * H / 2
    num = 1 if (2*x == W and 2*y == H) else 0
    print(ans, num)

  
if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    W, H, x, y = map(int, input().split())
    ans = W * H / 2
    num = 1 if (2*x == W and 2*y == H) else 0
    print(ans, num)
if __name__ == '__main__':
    main()
N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

dp = [[-1]*10 for i in range(N)]
mark = {}
Q = int(input())
col = [0]*(Q+1)
col[-1] = 0
C = []
for i in range(Q):
    v, d, c = map(int, input().split())
    col[i] = c
    C.append((v-1, d))

def dfs(v, d, idx):
    if idx < dp[v][d]:
        return
    dp[v][d] = idx
    if d:
        for w in G[v]:
            dfs(w, d-1, idx)

for i in range(Q-1, -1, -1):
    v, d = C[i]
    dfs(v, d, i)
print(*(col[max(e for e in dp[i])] for i in range(N)), sep='\n')

### FIXED CODE ###

N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

dp = [{-1: -1} for i in range(N)]
mark = {}
Q = int(input())
col = [0]*(Q+1)
col[-1] = 0
C = []
for i in range(Q):
    v, d, c = map(int, input().split())
    col[i] = c
    C.append((v-1, d))

def dfs(v, d, idx):
    if d <= max(dp[v]):
        return
    dp[v][d] = idx
    if d:
        for w in G[v]:
            dfs(w, d-1, idx)

for i in range(Q-1, -1, -1):
    v, d = C[i]
    dfs(v, d, i)
print(*(col[max(e.values())] for e in dp), sep='\n')
N,M,X,Y=map(int,input().split())
x=int(input().split())
y=int(input().split())

if (min(y,Y)-max(x,X))>0:
    print('No War')
    
else :
    print('War')

### FIXED CODE ###

N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))

x.append(X)
y.append(Y)

if (min(y)-max(x))>0:
    print('No War')
    
else :
    print('War')
a,b = input().split()
area = a*b
perimeter = (a + b) * 2
print(area, perimeter)


### FIXED CODE ###

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

print(a*b,(a+b)*2)
list1=[]
while True:
    x = str(input(""))
    if x == "0":
        break
    else:
        list1.append(x)

for i,v in enumerate(list1):
    x,y = map(int,v.split())
    if x < y:
        print(str(x) + " " + str(y))
    else:
        print(str(y) + " " + str(x))

### FIXED CODE ###

list1=[]
while True:
    x = input("")
    if x == "0 0":
        break
    else:
        list1.append(x)

for i,v in enumerate(list1):
    x,y = map(int,v.split())
    if x <= y:
        print(str(x) + " " + str(y))
    else:
        print(str(y) + " " + str(x))
n = list(map(int, input().split()))
s = b * n[1]
t = r * n[2]
u = 10**100
v = (s + t) * u
w = v.count("b", 0, n[0])
print(w)

### FIXED CODE ###

N, A, B = map(int, input().split())
C = A + B
D = N // C
E = N % C
if N <= A:
    print(N)
elif N <= C:
    print(A)
else:
    if E <= A:
        print(A*D + E)
    else:
        print(A*D + A)
a=raw_input()
b=raw_input()

if a>b:
 print(a-1)
else:
 print(a)


### FIXED CODE ###

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

if a<=b:
    print(a)
else:
    print(a-1)
s = input()
for i in s:
  s[i]=x
print(s)

### FIXED CODE ###

s = list(input())
n = len(s)
print('x'*n)
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[-1]*N
for i in range(N):
    C[i]=A[i]-B[i]
C.sort()

count=0
num=0
#print(C)

if (sum(C))<0:
    print(-1)
else:
    while C[0]<0:
        count+=1
        print(C)
        num+=C.pop(0)    
        if num<0:
            num+=C.pop(-1)
            count+=1
    print(count)

### FIXED CODE ###

# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=[-1]*N
for i in range(N):
    C[i]=A[i]-B[i]
C.sort()
 
count=0
num=0
#print(C)
 
if (sum(C))<0:
    print(-1)
else:
    while C[0]<0:
        count+=1
        num+=C.pop(0)    
        if num<0:
            num+=C.pop(-1)
            count+=1
        if len(C)==0:
            break
    print(count)
def main():
    N = int(input())
    L = list(map(int, input().split()))

    s1, s2 = 0,sum(W)
    ans = sum(W)

    for i in range(N):
        s1 += L[i]
        s2 -= L[i]
        ans = min(ans, abs(s1-s2))

    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    N = int(input())
    L = list(map(int, input().split()))

    s1, s2 = 0,sum(L)
    ans = sum(L)

    for i in range(N):
        s1 += L[i]
        s2 -= L[i]
        ans = min(ans, abs(s1-s2))

    print(ans)

if __name__ == "__main__":
    main()
s=set()
n=int(input())
for i in range(n):
    s.add(int(input()))
while len(s) != 1:
    l=list(cb(s,2))
    s = set([lcm(x,y) for x,y in l])
print(list(s)[0])

### FIXED CODE ###

def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a
def lcm(a, b):
    return a*b//gcd(a, b)
n=int(input())
t=[int(input()) for i in range(n)]
for i in range(n-1):
    t[i+1] = lcm(t[i],t[i+1])
print(t[n-1])
import sys

X,N = map(int,input().split())
P = list(map(int,input().split()))
if X < 1 or 100 < X:
    sys.exit()
if N < 0 or 100 < N:
    sys.exit()
P_number = count(P)
if P_number < 1 or 100 < P_number:
    sys.exit()

res = 100
count = 0
while i < N:
    if res > abs(X - P[i]):
        res = X - P[i] 
print(res)

### FIXED CODE ###

import sys

X,N = map(int,input().split())
P = list(map(int,input().split()))
if X < 1 or 100 < X:
    sys.exit()
if N < 0 or 100 < N:
    sys.exit()
if N == 0:
    print(X)
    sys.exit()

P_number = len(P)
if P_number < 1 or 100 < P_number:
    sys.exit()

res1 = 100
res2 = 100
res0 = 0
i = 0
j = 0
while i <= N:
    if (X - i) not in P:
        res1 = (X - i)
        break
    i += 1
while j <= N:
    if (X + j) not in P:
        res2 = (X + j)
        break
    j += 1
if i > j:
    res0 = res2
elif j > i:
    res0 = res1
elif i == j:
    res0 = res1
print(res0)
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=0
d={}
d[1]=0
dd={}
d[0]=1
now=1
while True:
    now=a[now-1]
    c+=1
    if now in d:
        break
    d[now]=c
    dd[c]=now
s=d[now]
if k<=s:
    print(dd[k])
    exit()
p=c-s
k-=s
k%=p
k+=s
print(dd[k])


### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
c=0
d={}
d[1]=0
dd={}
dd[0]=1
now=1
while True:
    now=a[now-1]
    c+=1
    if now in d:
        break
    d[now]=c
    dd[c]=now
s=d[now]
if k<=s:
    print(dd[k])
    exit()
p=c-s
k-=s
k%=p
k+=s
print(dd[k])
# _*_ coding:utf-8 _*_

import sys

input = sys.stdin.readline()
ans  = 1000

for c in input:
	s = input.split(f'{c}')
	ma = 0
	for i in range(len(s)):
		if ma < len(s[i]):
			ma = len(s[i])
	
	if ans > ma:
		ans = ma
		
print(ans) 

### FIXED CODE ###

# _*_ coding:utf-8 _*_

import sys

input = sys.stdin.readline().replace('\n','')
ans  = 1000

for c in input:
	s = input.split(c)
	ma = 0
	for i in range(len(s)):
		if ma < len(s[i]):
			ma = len(s[i])
	
	if ans > ma:
		ans = ma
		
print(ans,end='')
N, X = map(int, intpu().split())
if X <= N / 3:
    result = 3 * (N - X)
if N / 3 < X and X < N /2:
    result = 6 * X
if N / 2 <= X:
    result = 3 * X
print(result)

### FIXED CODE ###

N = int(input())
L = list(map(int, input().split()))
L.sort()
sum = 0
for i in range(N):
    x = L.pop(0)
    y = L.pop(0)
    sum += x
print(sum)
from math import sqrt

def F(t):
    return max(len(str(t[0])), len(str(t[1])))

N = long(input())
m = list(map(F,[(r,int(N / r)) for r in range(2, int(sqrt(N))) if N % r == 0]))
print(min(m)) if len(m) != 0 else print(len(str(N)))

### FIXED CODE ###

from math import sqrt

def F(t):
    return max(len(str(t[0])), len(str(t[1])))

N = int(input())
m = list(map(F,[(r,int(N / r)) for r in range(2, int(sqrt(N)) + 1) if N % r == 0]))
print(min(m) if len(m) != 0 else len(str(N)))
n, a, b = map(int, input().split())

P = 10**9 + 7
N = 2*10**5+2

f = [1]
for i in range(1, N):
  f.append(f[i-1]*i%P)

def modinv(a, mod):
    return pow(a, mod - 2, mod)

def comb(n,r):
  return ((f[n]*modinv(n-r, P))%P*modinv(r, P))%P

#print(a,b)
#print((n*modinv(n,P))%P)
#print(comb(n,b))

ans = ((n%P)*(n%P) - comb(n,a) - comb(n,b))%P - 1
print(int(ans))
  




### FIXED CODE ###

n, a, b = map(int, input().split())
MOD = 10**9 + 7
ans = pow(2, n, MOD)
ans -= 1 # select no flowers

def ncr(n, r, MOD):
  res = 1
  for i in range(r):
    res = res*(n-i)%MOD
  
  f = [1]*(r+1)
  inv = [1]*(r+1)

  for i in range(r):
    f[i+1] = f[i]*(i+1)%MOD
  
  inv[r] = pow(f[r], MOD-2, MOD)
  
  for i in range(r, 0, -1):
    inv[i-1] = inv[i]*i%MOD
    
  return res*inv[r]%MOD
    
ans -= ncr(n, a, MOD)
ans -= ncr(n, b, MOD)

print(ans%MOD)
a = int(input())
b = int(input())
c = int(input())
k = int(input())
s = 0
if  a + b >= k:
    s = a
else:
    s = a - c 
print(s)

### FIXED CODE ###

a, b, c, k = map(int, input().split())
s = 0
if a >= k:
    s = k
elif  a + b >= k:
    s = a
else:
    s = a - (k - a - b) 
print(s)
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
edges = [None]*N
edges[0] = 0
for _ in range(N-1):
    a, b = map(int, input().split())
    edges[max(a, b)-1] = min(a, b)-1

counts = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    counts[p-1] += x

print(counts[0], end=' ')
for i in range(1, N):
    counts[i] += counts[edges[i]]
    print(counts[i], end=' ')

### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline

def main():
    N, Q = map(int, input().split())
    # edges = [None]*N
    edges = [[] for _ in range(N)]
    # edges[0] = 0
    # edges[0].append = 0
    for _ in range(N-1):
        a, b = map(int, input().split())
        edges[b-1].append(a-1)
        edges[a-1].append(b-1)

    counts = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        counts[p-1] += x

    parent_nodes = deque()
    parent_nodes.append(0)
    visited_nodes = set()
    while parent_nodes:
        parent = parent_nodes.popleft()
        if parent in visited_nodes:
            continue
        visited_nodes.add(parent)
        for child in edges[parent]:
            if child in visited_nodes:
                continue
            counts[child] += counts[parent]
            parent_nodes.append(child)

    print(' '.join(list(map(str, counts))))

if __name__ == "__main__":
    main()
import sys
n ,k = map(int, input().split())
 
 
if n == k or k == 1:
    print(0)
    sys.exit()
    
def min_N(n, k):
    b = abs(n-k)
    if b == 0:
        print(0)
        sys.exit()
    elif b == 1:
        print(1)
        sys.exit()
    elif n < b:
        print(n)
        sys.exit()
    n = b
    min_N(n, k)

min_N(n, k)

### FIXED CODE ###

import sys
n ,k = map(int, input().split())
if n == k or k == 1:
    print(0)
    sys.exit()
else:
    n %= k
print(min(n, abs(n-k)))
import sys
input = sys.stdin.readline
from operator import setitem

def readlines(n):
    for _ in range(n):
        a, b = map(int, input().split())
        yield a, b

def main():
    n, q = map(int, input().split())
    edges = {i: 0 for i in range(n+1)}

    bigroot = False
    for a, b in readlines(n-1):
        if not bigroot and edges[b] > 0:
            edges = {v: k for k, v in edges.items()}
            bigroot = True

        if bigroot:
            edges[a] = b
        else:
            edges[b] = a

    counter = [0] * (n+1)

    for q, x in readlines(q):
        counter[q] += x

    iterator = range(n, 0, -1) if bigroot else range(1, n+1)
    for i in iterator:
        parent = edges[i]
        counter[i] += counter[parent]

    print(" ".join(map(str, counter[1:])))

main()

### FIXED CODE ###

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

def readlines(n):
    for _ in range(n):
        a, b = map(int, input().split())
        yield a, b

def main():
    n, q = map(int, input().split())
    edges = [[] for _ in range(n+1)]

    for a, b in readlines(n-1):
        edges[a].append(b)
        edges[b].append(a)

    counter = [0] * (n+1)
    for q, x in readlines(q):
        counter[q] += x

    def dfs(u, prev):
        for v in edges[u]:
            if v == prev:
                continue
            counter[v] += counter[u]
            dfs(v, u)

    dfs(1, 0)

    print(" ".join(map(str, counter[1:])))

main()
print(3*(int(input())**2)

### FIXED CODE ###

print(3*(int(input()))**2)
#c
a, b = map(int ,input().split())
from math import *
print(a*b//math.gcd(a, b))

### FIXED CODE ###

#c
a, b = map(int ,input().split())
from fractions import gcd
print(a*b//gcd(a, b))
a=int(input())
b=int(input())
if a*b%2==0:
    print('Even')
else:
    print('Odd')


### FIXED CODE ###

str=input().split(" ")


a=int(str[0])
b=int(str[1])

if a*b%2==0:
    print('Even')
else:
    print('Odd')
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

s_max = None
for n in range(N):
    s = 0
    p = n + 1
    for k in range(K):

        p = P[p-1]
        s += C[p-1]

        if not s_max:
            s_max = s
        if s > s_max:
            s_max = s


print(s_max)


### FIXED CODE ###

S = input()

print(S.count("R") if S != "RSR" else 1)
N = int(input())
H = list(map(int, input().split()))

idx = max(enumerate(H), key=lambda x: x[1])[0]

cmp = H[idx]-1
flg = 0

if idx!=N-1:
    for i in range(idx, N):
        if H[i]<cmp:
            flg = 1
    if flg==0:
        print('Yes')
    else:
        print('No')

else:
    idx = max(enumerate(H[0:N-1]), key=lambda x: x[1])[0]
    cmp = H[idx]-1
    flg = 0
    for i in range(idx, N-1):
        if H[i]<cmp:
            flg = 1
    if flg==0:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

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

idx = max(enumerate(H), key=lambda x: x[1])[0]

cmp = H[idx]-1
flg = 0

if N>1:
    if idx!=N-1:
        for i in range(idx, N):
            if H[i]<cmp:
                flg = 1
        if flg==0:
            print('Yes')
        else:
            print('No')

    else:
        idx = max(enumerate(H[0:N-1]), key=lambda x: x[1])[0]
        cmp = H[idx]-1
        flg = 0
        for i in range(idx, N-1):
            if H[i]<cmp:
                flg = 1
        if flg==0:
            print('Yes')
        else:
            print('No')
else:
    print('Yes')
n, k = map(int, input().split())
mod = 10 ** 9 + 7
premin = 0
premax = 0
ans = 0
list = [i for i in range(n + 1)]
for x in range(n + 2):
    if x < k: continue
    if k < x: ans += pre
    premin = sum(list[0 : x])
    premax = sum(list[n + 1 - x : n + 1])
    ans += (premax - premin + 1) % mod
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
mod = 10 ** 9 + 7
premin = 0
premax = 0
ans = 0
list = [i for i in range(n + 1)]
for x in range(n + 1):
    premin += list[x]
    premax += list[n - x]
    if x < k - 1: continue
    ans += (premax - premin + 1)
    if ans >= mod: ans %= mod
print(ans)
data = [int(input()) for i in range(3)]
N = data[0]
A = data[1]
B = data[2]
if N == 1:
    print("Hello World")
else:
    print(A + B)

### FIXED CODE ###

N = int(input())
if N == 1:
    print("Hello World")
else:
    A = int(input())
    B = int(input())
    print(A + B)
# seishin.py
from math import sqrt
n, s = map(int, open(0).read().split())

# s = n
if s == n:
    print(n+1)
    exit(0)

def f(b, n):
    res = 0
    while n:
        res += n % b
        n //= b
    return res

# 2 <= b <= sqrt(n)
for b in range(2, int(sqrt(n))+1):
    if f(b, n) == s:
        print(b)
        exit(0)

# sqrt(n) <= b <= n
for p in range(int(sqrt(n)), 0, -1):
    if (n - s) % p > 0:
        continue
    b = (n - s) // p + 1
    if f(b, n) == s:
        print(b)
        exit(0)
print(-1)

### FIXED CODE ###

# seishin.py
from math import sqrt
n, s = map(int, open(0).read().split())

# s = n
if s == n:
    print(n+1)
    exit(0)

def f(b, n):
    res = 0
    while n:
        res += n % b
        n //= b
    return res

# 2 <= b <= sqrt(n)
for b in range(2, int(sqrt(n))+1):
    if f(b, n) == s:
        print(b)
        exit(0)

# sqrt(n) <= b <= n
for p in range(int(sqrt(n)), 0, -1):
    if (n - s) % p > 0:
        continue
    b = (n - s) // p + 1
    if b*b <= n:
        continue
    if f(b, n) == s:
        print(b)
        exit(0)
print(-1)
from fractions import gcd
from functools import reduce
#from collections import deque
# from math import factorial
# import collections
import math
import sys
sys.setrecursionlimit(2000000)
# import itertools
# import statistics
# import numpy as np
n = input()
#n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

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


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


b = lcm_list(a)-1
f = 0
for i in a:
    f += b % i

print(f)


### FIXED CODE ###

from fractions import gcd
from functools import reduce
#from collections import deque
# from math import factorial
# import collections
import sys
sys.setrecursionlimit(2000000)
# import itertools
# import statistics
# import numpy as np
n = input()
#n, m = list(map(int, input().split()))
a = list(map(int, input().split()))


def lcm_base(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


b = lcm_list(a)-1
f = 0
for i in a:
    f += b % i

print(f)
import math
n = input()
a = list(map(int,input().split()))
ans = float("inf")
for i in a:
  ans = min(ans,len(bin(i)) - bin(i).rfind("1") - 1)
print(ans)	

### FIXED CODE ###

s = list(input())
ans = 0
for i in s:
  if i == "1":
    ans += 1
print(ans)
def gcd(a, b):
      while b > 0:
        a, b = b, a % b
      return a
     
    def nfac(n):
      if n % 2 == 0:
        while n % 2 == 0:
          n //= 2
        r = 2
      else:
        r = 1
      p = 3
      while p*p <= n:
        if n % p == 0:
          n //= p
          r += 1
          while n % p == 0:
            n //= p
        p += 2
      if n > 1:
        r += 1
      return r
     
    a, b = map(int, input().split())
    g = gcd(a, b)
    print(nfac(g))

### FIXED CODE ###

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

         
def nfac(n):
    if n % 2 == 0:
        while n % 2 == 0:
            n //= 2
        r = 2
    else:
        r = 1

    p = 3
    while p*p <= n:
        if n % p == 0:
            n //= p
            r += 1
            while n % p == 0:
                n //= p
        p += 2
    if n > 1:
        r += 1
    return r

         
a, b = map(int, input().split())
print(nfac(gcd(a,b)))