Harryxun/stf_run huggingface dataset:
from scipy.sparse.csgraph import dijkstra, bellman_ford, csgraph_from_dense, NegativeCycleError
from itertools import permutations

INF = float("inf")

N, M, P, *ABC = map(int, open(0).read().split())

D = [[0] * N for _ in range(N)]
E = [[0] * N for _ in range(N)]
for a, b, c in zip(*[iter(ABC)] * 3):
    D[a - 1][b - 1] = c
    E[a - 1][b - 1] = P - c

T = dijkstra(D)
for a, b in permutations(range(N), 2):
    if T[b][N - 1] == INF:
        E[a][b] = 0

try:
    G = bellman_ford(csgraph_from_dense(E), indices=0)
    ans = max(0, -int(G[N - 1]))
except NegativeCycleError:
    ans = -1

print(ans)


### FIXED CODE ###

def main():
    INF = float("inf")

    N, M, P, *ABC = map(int, open(0).read().split())

    F = [[] for _ in range(N)]
    B = [[] for _ in range(N)]
    E = [(a - 1, b - 1, P - c) for a, b, c in zip(*[iter(ABC)] * 3)]

    for a, b, c in E:
        F[a].append(b)
        B[b].append(a)

    S = {0}
    stack = [0]
    while stack:
        s = stack.pop()
        for v in F[s]:
            if v not in S:
                stack.append(v)
                S.add(v)

    T = {N - 1}
    stack = [N - 1]
    while stack:
        s = stack.pop()
        for v in B[s]:
            if v not in T:
                stack.append(v)
                T.add(v)

    ok = S & T

    D = [INF] * N
    D[0] = 0

    def bellman_ford(N):
        for _ in range(N):
            update = False
            for a, b, c in E:
                if a in ok and b in ok and D[b] > D[a] + c:
                    D[b] = D[a] + c
                    update = True
            if not update:
                return False
        return True

    bellman_ford(N)

    print(-1 if bellman_ford(1) else max(-D[-1], 0))



if __name__ == '__main__':
    main()
import sympy
x=int(input())
r=sympy.nextprime(x)
print(r)


### FIXED CODE ###

x = int(input())
while any(x % i < 1 for i in range(2, x)): 
    x += 1
print(x)
import math

N = int(input())
A = list(map(int,input()))
B = []
M = math.ceil(math.log(N,2)) 

for i in range(N):
  a = 0
  for j in range(1,M+1,1):
    a += math.floor((N-1)/(2**j))-math.floor((i)/(2**j))-math.floor((N-1-i)/(2**j))
  if a == 0:
    B.append(1)
  else:
    B.append(0)
    
b = 0
for i in range(N):
  b += B[i]*A[i]
if b % 2 == 1:
  print(1)
else:
  for i in range(N):
    if A[i] == 2:
      print(0)
      break
  else:
    for i in range(N):
      A[i] = (A[1]-1)//2
    for i in range(N):
      a = 0
      C = []
      for j in range(1,M+1,1):
        a += math.floor((N-1)/(2**j))-math.floor((i)/(2**j))-math.floor((N-1-i)/(2**j))
      if a == 0:
        C.append(1)
      else:
        C.append(0)
    
    for i in range(N):
      b += C[i]*A[i]
    if b % 2 == 1:
      print(2)
    else:
      print(0)

### FIXED CODE ###

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


def g(m):
    if data[0][0] == '.':
        a = 0
    else:
        a = 1

    for i in range(1, m, 1):
        if data[0][i] == '.':
            continue
        elif data[0][i] == '#' and data[0][i - 1] == '.':
            a += 1
        else:
            continue
    return a


def h(n):
    if data[0][0] == '.':
        a = 0
    else:
        a = 1

    for i in range(1, n, 1):
        if data[i][0] == '.':
            continue
        elif data[i][0] == '#' and data[i - 1][0] == '.':
            a += 1
        else:
            continue
    return a

A = [0] + [g(i) for i in range(1,W+1)]
B = [0] + [h(i) for i in range(1,H+1)]
C = [[0]*(W+1) for i in range(H+1)]

for n in range(1,H+1):
    for m in range(1,W+1):
        if n == 1:
            C[n][m] = A[m]
        elif m == 1:
            C[n][m] = B[n]
        else:
            if data[n - 1][m - 1] == '.':
                C[n][m] = min(C[n - 1][m], C[n][m - 1])
            elif data[n - 2][m - 1] == '.':
                if data[n - 1][m - 2] == '.':
                    C[n][m] = min(C[n - 1][m] + 1, C[n][m - 1] + 1)
                else:
                    C[n][m] =  min(C[n - 1][m] + 1, C[n][m - 1])
            else:
                if data[n - 1][m - 2] == '.':
                    C[n][m] = min(C[n - 1][m], C[n][m - 1] + 1)
                else:
                    C[n][m] = min(C[n - 1][m], C[n][m - 1])


print(C[H][W])
n = int(input())
sum =0
for j in range(n):
  i,c = input().split()
  if c =="BTC":
    sum+=float(i)*380000
  else:
    sum+=i
print(sum)

### FIXED CODE ###

n = int(input())
sum =0
for j in range(n):
  i,c = input().split()
  if c =="BTC":
    sum+=float(i)*380000
  else:
    sum+=int(i)
print(sum)
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328

### FIXED CODE ###

from collections import deque

N, M, Q = map(int, input().split())
queries = [list(map(int, input().split())) for _ in range(Q)]
patterns = []

ptn = deque([])
for i in range(M):
  ptn.append([i])
while len(ptn) > 0:
  p = ptn.pop()
  if len(p) < N:
    for i in range(p[-1], M):
      ptn.append(p+[i])
  else:
    patterns.append(p)
answer = 0
for p in patterns:
  point = 0
  for a, b, c, d in queries:
    if p[b-1]-p[a-1] == c:
      point += d
  answer = max(answer, point)
print(answer)
import sys

def main(argv):
    result = 0
    ball = int(argv[0])
    people = int(argv[1])

    if people <= 1:
        return 0

    if ball > people:
        result = ball - people
        result += 1
        
    else:
        return 0

    result -= 1

    return result


if __name__ == '__main__':
    print(main(sys.argv[1:]))

### FIXED CODE ###

import sys

def main():
    inputData = input().strip().split(" ")
    result = 0
    ball = int(inputData[0])
    people = int(inputData[1])

    if people <= 1:
        return 0

    if ball > people:
        result = ball - people
        result += 1

    else:
        return 0

    result -= 1

    return result


if __name__ == '__main__':
    print(main())
#ALDS1_4-D Allocation
from collections import deque

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    while(w):
        tmp = w.popleft()
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp

    c+=1
    if c>k:
        return False
    else:
        return True
    
n,k = input().split()
w = deque()

for i in range(int(n)):
    w.append(int(input()))

p = max(w)

while(1):
    x=w.copy()
    '''
    if(pIsAccptbl(x,int(k),p)):
        print(p)
        break
    else:
        p+=1
    '''
    break

### FIXED CODE ###

from collections import deque

def isPa(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

def MaxInP(w,k,p):
    maxinp = 0
    tmp = 0
    d = deque(w)
    while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
    return maxinp

n,k = [int(x) for x in input().split()]
w = deque()
for i in range(n):
    w.append(int(input()))
    
mean = int(sum(w)/k)
maxinp = MaxInP(w,k,mean)

if k == 1:
    print(mean)
else:
    minP = mean
    maxP = maxinp
    while(True):
        m = int ((minP + maxP)/2)
        if ( isPa(w,k,m) ):
            maxP = m
        else:
            minP = m
        if (minP+1 == maxP or minP == maxP):
            print(maxP)
            break
a, b, c = map(int,input().split())

if c-a-b > 0 and 4*a*b < (c-a-b)(c-a-b):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a, b, c = map(int,input().split())
 
if c-a-b > 0 and 4*a*b < (c-a-b)*(c-a-b):
  print("Yes")
else:
  print("No")
i=input()
j=input()
count_num=0
for k in range(3):
  if i[k]==j[k]:
    count_num+=1
print(conut_num)

### FIXED CODE ###

i=input()
j=input()
count_num=0
for k in range(3):
  if i[k]==j[k]:
    count_num+=1
print(count_num)
N = input()
A_raw = input()
A = [int(i) for i in A_raw.split(' ')]
cnt = 0
first = 0
xsum_old = 0
r_old = 0
for l in range(0, N):
    xsum = xsum_old
    first = A[l]
    cnt += r_old - l
    print(cnt, l, r_old)
    for r in range(r_old, N):
        if xsum & A[r] > 0:
            xsum_old = xsum - first
            r_old = r
            break
        xsum += A[r]
        cnt += 1
print(cnt)

### FIXED CODE ###

N = int(input())
A_raw = input()
A = [int(i) for i in A_raw.split(' ')]
cnt = 0
first = 0
xsum_old = 0
r_old = 0
for l in range(0, N):
    xsum = xsum_old
    first = A[l]
    cnt += r_old - l
    isBreak = False
    for r in range(r_old, N):
        if xsum & A[r] > 0:
            xsum_old = xsum - first
            r_old = r
            isBreak = True
            break
        xsum += A[r]
        cnt += 1
    if isBreak == False:
        r_old = r
print(cnt)
from itertools import combinations
from math import gcd

N, K=map(int, input().split())
an=list(map(int,input().split()))

m = max(an)
g = max(map(lambda x:gcd(x[0],x[1]), combinations(an, 2)))

if K <=m and k % g == 0:
    print ('POSSIBLE')
else:
    print ('IMPOSSIBLE')

### FIXED CODE ###

from functools import reduce
from fractions import gcd

N, K=map(int, input().split())
an=list(map(int,input().split()))

m = max(an)
g = reduce(lambda x, y: gcd(x, y), an)

if K <=m and K % g == 0:
    print ('POSSIBLE')
else:
    print ('IMPOSSIBLE')
n=int(input())

list=list(map(int,input().split()))
for i in range(1,N):
    v=A[i]
    j=i-1
    while j>=0 and A[j]>v:
        A[j+1]=A[j]
        j=j-1
        A[j+1]=v
    for i in range(len(A)):
        if i!=len(A)-1:
            print(A[i],end=' ')
        else :
            print(A[i])





### FIXED CODE ###

n=int(input())

list=list(map(int,input().split()))
for i2 in range(len(list)):
    if i2!=len(list)-1:
        print(list[i2],end=' ')
    else :
        print(list[i2])

for i in range(1,n):
    v=list[i]
    j=i-1
    while j>=0 and list[j]>v:
        list[j+1]=list[j]
        j=j-1
    list[j+1]=v
    for i2 in range(len(list)):
        if i2!=len(list)-1:
            print(list[i2],end=' ')
        else :
            print(list[i2])
S = input()
N = len(S)
non_x = []
s_notx = []
for i, s in enumerate(S):
    if s != 'x':
        non_x.append(i)
        s_notx.append(s)
s_notx = ''.join(s_notx)
if s_notx != s_notx[::-1]:
    print(-1)
    quit()

ans = 0
L = len(non_x)
if L % 2 == 0:
    left, right = L // 2 - 1, L // 2
else:
    left = right = L // 2
left, right = left - 1, right + 1
for i in range(left + 1):
    l, r = left - i, right + i
    ans += abs((non_x[l + 1] - non_x[l]) - (non_x[r] - non_x[r - 1]))
ans += abs(non_x[0] - (N - non_x[-1] - 1))
print(ans)


### FIXED CODE ###

S = input()
N = len(S)
non_x = []
s_notx = []
for i, s in enumerate(S):
    if s != 'x':
        non_x.append(i)
        s_notx.append(s)
s_notx = ''.join(s_notx)
if s_notx != s_notx[::-1]:
    print(-1)
    quit()
if not non_x:
    print(0)
    quit()
ans = 0
L = len(non_x)
if L % 2 == 0:
    left, right = L // 2 - 1, L // 2
else:
    left = right = L // 2
left, right = left - 1, right + 1
for i in range(left + 1):
    l, r = left - i, right + i
    ans += abs((non_x[l + 1] - non_x[l]) - (non_x[r] - non_x[r - 1]))
ans += abs(non_x[0] - (N - non_x[-1] - 1))
print(ans)
time = list(map(int, input(),split()))
sum = time[0] + time[1]
if sum > time[1] + time[2]:
  sum = time[1] + time[2]
if sum > time[0] + time[2]:
  sum = time[0] + time[2]
print(sum)

### FIXED CODE ###

time = list(map(int, input().split()))
sum = time[0] + time[1]
if sum > time[1] + time[2]:
  sum = time[1] + time[2]
if sum > time[0] + time[2]:
  sum = time[0] + time[2]
print(sum)
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [10 ** 9 + 7] * (n + k + 10)
dp[0] = 0

for i in range(n):
    for j in range(k + 1):
        if dp[i + j] == 10 ** 9 + 7:
            dp[i + j] = dp[i] + abs(h[i] - h[i - j])
        else:    
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - dp[i + j]))

print(dp[n - 1])


### FIXED CODE ###

import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * (n + k + 10)
dp[0] = 0

for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            if dp[i + j] == float('inf'):
                dp[i + j] = dp[i] + abs(h[i + j] - h[i])
            else:
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
        else:
            break


print(dp[n-1])
while 1:
    n, m = map(int, raw_input().split())
    if n == m == 0:
        break
    S = map(int, raw_input().split())
    left = -1; right = max(S)+2
    def check(mid):
        if 1+mid <= S[0]:
            return 10**9
        cnt = 0; l = 1
        target = S[n-1] - mid
        for i in xrange(n-1):
            while l <= S[i] and cnt <= m and l<=target:
                l += max(1, mid-(S[i]-l))
                cnt += 1
            while l+mid <= S[i+1] and cnt <= m and l<=target:
                l += max(1, mid-(l-S[i]))
                cnt += 1
        return cnt
    while left+1 < right:
        mid = (left + right) / 2
        if m <= check(mid):
            left = mid
        else:
            right = mid
    if 10**8 < check(left):
        print -1
    else:
        print right

### FIXED CODE ###

while 1:
    n, m = map(int, raw_input().split())
    if n == m == 0:
        break
    S = map(int, raw_input().split())
    left = 0; right = sum(S)+2
    def check(mid):
        if 1+mid <= S[0]:
            return 10**9
        cnt = 0; l = 1
        target = S[n-1] - mid
        for i in xrange(n-1):
            while l <= S[i] and cnt<=m and l<=target:
                l += mid-(S[i]-l)
                cnt += 1
            if (l+mid <= S[i+1] or abs(l-S[i]) < abs(l-S[i+1])) and cnt<=m and l<=target:
                l += max(1, mid-(l-S[i]))
                cnt += 1
                if l+mid <= S[i+1]:
                    cnt += S[i+1]-mid+1-l
                    l = S[i+1]-mid+1
        return cnt
    while left+1 < right:
        mid = (left + right) / 2
        if m-1 <= check(mid):
            left = mid
        else:
            right = mid
    if 10**8 < check(left):
        print -1
    else:
        print left
a,b=map(int,input().split())
c=0
if a!=3 and b!=3:
	c=3
elif a!=2 and b!=2:
	c=2
else:
	c=1
finally:
  	print(c)

### FIXED CODE ###

a=int(input())
b=int(input())
if a!=3 and b!=3:
  print(3)
elif a!=2 and b!=2:
  print(2)
else:
  print(1)
# -*- coding: utf-8 -*-
n,k=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
p=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
max = 0
final = []
#最大のリストを選定
for i in range(0,n-k):
    ck = sum(p[i:i+k])
    if ck > max:
        final = p[i:i+k]
        max = ck

#計算
print((ck+k)/2.0)


### FIXED CODE ###

# -*- coding: utf-8 -*-
n,k=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
p=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
#最大のリストを選定
before_pi = p[0]
before_sum = sum(p[0:k])+ 0.0
suml = [sum(p[0:k])]
for i in range(1,n-k+1):
    before_sum = before_sum - before_pi+p[i+k-1]
    suml.append(before_sum)
    before_pi = p[i]

#計算
print((max(suml)+k)/2.0)
x = input().split()
a = int(x[0])
op = x[1]
b = int(x[2])
for i in I:
  if op == "+":
    A = a + b
    prnit(A)
  elif op == "-":
    B = a - b
    print(B)
  elif op == "*":
    C = a * b
    print(C)
  elif op == "/":
    D = a // b
    print(D)
  elif op == "?":
    break


### FIXED CODE ###

for i in range(10000):
  x = input().split()
  a = int(x[0])
  op = x[1]
  b = int(x[2])
  if op == "+":
    A = a + b
    print(A)
  elif op == "-":
    B = a - b
    print(B)
  elif op == "*":
    C = a * b
    print(C)
  elif op == "/":
    D = a // b
    print(D)
  elif op == "?":
    break
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

    N, x, d = map(int, input().split())
    
    assert d != 0
    if d == 0:
        if x:
            print(N+1)
        else:
            print(0)
        exit()

    if d < 0:
        x = x + d * (N-1)
        d *= -1
    dic = defaultdict(list)

    for i in range(N+1):
        mod = (x * i) % d
        st = (i * (i+1)) // 2
        ed = (i * (N + N-i+1)) // 2
        st = st * d + (x-d) * i
        ed = ed * d + (x-d) * i
        dic[mod].append((st, ed))
    ans = 0
    for mod in dic:
        L = dic[mod]
        L.sort(key=lambda t: t[0])
        ed_prev = L[0][0] - 1
        for st, ed in L:
            if st > ed_prev:
                ans += (ed - st) // d + 1
                ed_prev = ed
            elif ed > ed_prev:
                ans += (ed - ed_prev) // d
                ed_prev = ed
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

    N, x, d = map(int, input().split())

    if d == 0:
        if x:
            print(N+1)
        else:
            print(1)
        exit()

    if d < 0:
        x = x + d * (N-1)
        d *= -1
    dic = defaultdict(list)

    for i in range(N+1):
        mod = (x * i) % d
        st = (i * (i+1)) // 2
        ed = (i * (N + N-i+1)) // 2
        st = st * d + (x-d) * i
        ed = ed * d + (x-d) * i
        dic[mod].append((st, ed))
    ans = 0
    for mod in dic:
        L = dic[mod]
        L.sort(key=lambda t: t[0])
        ed_prev = L[0][0] - 1
        for st, ed in L:
            if st > ed_prev:
                ans += (ed - st) // d + 1
                ed_prev = ed
            elif ed > ed_prev:
                ans += (ed - ed_prev) // d
                ed_prev = ed
    print(ans)


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

if a == b == c:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a,b,c = map(int,input().split())
 
if a == b == c:
  print("Yes")
else:
  print("No")
a = int(input())
if "9" in a:
  print("Yes")
else :
  print("NO")

### FIXED CODE ###

a = input()
if "9" in a:
  print("Yes")
else :
  print("No")
if b == 'A':
  print('T')
elif b == 'T':
  print('A')
elif b == 'C':
  print('G')
elif b == 'G':
  print('C')


### FIXED CODE ###

b = input()
if b == 'A':
  print('T')
elif b == 'T':
  print('A')
elif b == 'C':
  print('G')
elif b == 'G':
  print('C')
else:
  pass
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限x
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


X, Y = map(int, input().strip().split())

min_num = min(X,Y)
z = min_num//3

tX = z * 3
tY = z * 3
cA = z
cB = z

rx = X - tX
ry = Y - tY
if rx < 0 or ty < 0:
    raise Exception
if rx == 0 and ry == 0:
    print(cmb(cA+cB, cA, mod))
    exit(0)
if rx * 2 == ry:
    cA += rx
elif ry * 2 == rx:
    cB += ry
else:
    print(0)
    exit(0)
print(cmb(cA+cB, cA, mod))


### FIXED CODE ###

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限x
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


X, Y = map(int, input().strip().split())
if (X + Y) % 3 != 0:
    print(0)
    exit(0)

a = (2*X-Y)//3
b = (2*Y-X)//3

if a < 0 or b < 0:
    print(0)
    exit(0)

print(cmb(a+b,a, mod))
import sys

def main():
    args = sys.argv
    residual = ( int(args[1]) * int(args[2]) )%2
    if residual == 1:
        print("Even")
    else :
        print("Odd")

if __name__ == "__main__":
    main()

### FIXED CODE ###

#import sys

def main():
    #args = sys.argv
    a, b = map(int, input().split())
    residual = ( a * b )%2
    if residual == 1:
        print("Odd")
    else :
        print("Even")

if __name__ == "__main__":
    main()
def main():
 n,*a=map(int,open(0).read().split());d,s=[0]*n,0
 for i,x in enumerate(a):
  if i+x<n:d[i+x]+=1
  s+=d[i-x]
 print(s)
main()

### FIXED CODE ###

from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for i in range(n):
  d[i+a[i]] += 1
ans = 0
for i in range(n):
  ans += d[i-a[i]]
print(ans)
s =  int(input())
k =  int(input())
#print(pow(10, 12))
def main(string_s):
    if str(s).lstrip('1')[0] == '2':
        print('2')
    elif str(s).lstrip('1')[0] == '3':
        print('3')
    elif str(s).lstrip('1')[0] == '4':
        print('4')
    elif str(s).lstrip('1')[0] == '5':
        print('5')
    elif str(s).lstrip('1')[0] == '6':
        print('6')
    elif str(s).lstrip('1')[0] == '7':
        print('7')
    elif str(s).lstrip('1')[0] == '8':
        print('8')
    elif str(s).lstrip('1')[0] == '9':
        print('9')
    else:
        print('1')

main(s)


### FIXED CODE ###

s =  int(input())
k =  int(input())
#print(pow(10, 12))
def main(string_s):
    for i, j in enumerate(str(string_s)):
#        print(i, j)
#        print(i, k)
        if j != '1':
            break
        if i+1 == k:
            print('1')
            return
    if str(s).lstrip('1') == '':
         print('1')
         return
    if str(s).lstrip('1')[0] == '2':
        print('2')
    elif str(s).lstrip('1')[0] == '3':
        print('3')
    elif str(s).lstrip('1')[0] == '4':
        print('4')
    elif str(s).lstrip('1')[0] == '5':
        print('5')
    elif str(s).lstrip('1')[0] == '6':
        print('6')
    elif str(s).lstrip('1')[0] == '7':
        print('7')
    elif str(s).lstrip('1')[0] == '8':
        print('8')
    elif str(s).lstrip('1')[0] == '9':
        print('9')
    else:
        print('1')

main(s)
import math
n,k = map(int,input().split())
print(math.ceil(1/math.log(k,n)))

### FIXED CODE ###

n,k = map(int,input().split())
count = 1
while(n >= k):
    count += 1
    n /= k
print(count)
N = input()
A = input()
B = input()
if ( N*A <= B ):
	print(N*A)
else:
	print(B)


### FIXED CODE ###

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

print(min(n*a,b))
a,b,c,d = map(int,input().split())

e = int(b // c)
f = int(a // c)
if f == int(a / c):
    g = e - f + 1
else:
    g = e - f

h = int(b // d)
i = int(a // d)
if i == int(a / d):
    j = h - i + 1
else:
    j = h - i

import fractions

cd = c*d / fractions.gcd(c,d)

k = int(b // cd)
l = int(a // cd)
if l == int(a / cd):
    m = k - l + 1
else:
    m = k - l

ans = (b-a) + 1 - (g + j - m)
print(int(ans))


### FIXED CODE ###

s = str(input())

l = []
for x in s:
    l += [x]

truf = True
for x in range(3):
    if l[x] == l[x+1]:
        truf = False

if truf:
    print('Good')
else:
    print('Bad')
# AtCoDeerくんとTopCoDeerくんが何と言ってるかを a,bで入力
a,b = input().split()
# もしa=Hでb=HならTopCoDeerくんは正直者
if a = "H":
    if b = "H":
        print("H")
# もしa=Dでb=HならTopCoDeerくんは正直者
elif a = "D":
    if b = "D":
        print("H")
# それ以外はbは嘘つき
else:
    print("D")

### FIXED CODE ###

# AtCoDeerくんとTopCoDeerくんが何と言ってるかを a,bで入力
a,b = input().split()
# もしa=Hでb=HならTopCoDeerくんは正直者
if a == "H" and b == "H":
    print("H")
# もしa=Dでb=HならTopCoDeerくんは正直者
elif a == "D" and b == "D":
    print("H")
# それ以外はbは嘘つき
else:
    print("D")