Harryxun/stf_run huggingface dataset:
from heapq import heapify, heappop
from math import ceil
N, K = map(int, input().split())
H = list(map(int, input().split()))
# N=3
# K=1
# H=[4,1,5]

Hminus = list(map(lambda x: x*(-1), H))
# print(type(Hminus))
heapify(Hminus)
# print(Hminus)
for _ in range(K):
    heappop(Hminus)
print(sum(Hminus)*(-1))

### FIXED CODE ###

from heapq import heapify, heappop
from math import ceil
N, K = map(int, input().split())
H = list(map(int, input().split()))
# N=8
# K=9
# H=[7, 9, 3, 2, 3, 8, 4, 6]

Hminus = list(map(lambda x: x*(-1), H))
# print(type(Hminus))
heapify(Hminus)
# print(Hminus)
if K > len(H):
    print(0)
else:
    for _ in range(K):
        heappop(Hminus)
    print(sum(Hminus)*(-1))
N,A,B = map(int, input().split())
print(min(N*A),B)

### FIXED CODE ###

N,A,B = map(int, input().split())
print(min(N*A,B))
import math
 
def comb(n, r):
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
a_list = list(map(int, input().split()))
a_list.append(n + 100)

for i in range(len(a_list) - 1):
  tmp_list = a_list[:]
  del tmp_list[i]
  tmp_list.sort()
  count = 0
  tmp_count = 0
  for j in range(1, len(tmp_list)):
    if tmp_list[j] == tmp_list[j - 1]:
      tmp_count += 1
    else:
      if tmp_count >= 1:
      	count += comb(tmp_count + 1, 2)
      tmp_count = 0
  print(count)
 

### FIXED CODE ###

import math

def comb(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

if nums[0] <= 1 and nums[1] <= 1:
  print(0)
elif nums[1] <= 1:
  print(comb(nums[0], 2))
elif nums[0] <= 1:
  print(comb(nums[1], 2))
else:
  print(comb(nums[0], 2) + comb(nums[1], 2))
n = int(input())
a = list(map(int, input().split()))
table = {}
for i in range(n):
  if a[i] not in table:
    table[a[i]] = 1
  else:
    table[a[i]] = table[a[i]] + 1
table = sorted(table.items(), key=lambda x: x[1], reverse=True)
x = 0
y = 0
for i in table:
  if table[i] >= 4:
    if x == 0:
      x = i
      y = i
    else:
      y = i
    break
  elif table[i] >= 2:
    if x == 0:
      x = i
    else:
      y = i
      break
print(x*y)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
used = [0] * n
a.sort(reverse=True)
x = 0
y = 0
for i in range(1,n):
    if a[i - 1] == a[i] and used[i-1] == 0 and used[i] == 0:
        if x == 0:
            x = a[i]
            used[i] = 1
            used[i-1] = 1
        elif y == 0:
            y = a[i]
            used[i] = 1
            used[i-1] = 1
            break
print(x*y)
c=list(input())
s=""
for x in c:
    if x!=B:
        s+=x
    else:
        s=s[:-1]
print(s)

### FIXED CODE ###

c=list(input())
s=""
for x in c:
    if x!="B":
        s+=x
    else:
        s=s[:-1]
print(s)
C = []*3, C1 = [[]*2]*3, C2 = [[]*3]*2
for i in range(3):
  C[i] = list(map(int, input().splite()))
for i in range(3):
  for j in range(2):
    C1[i][j] = C[i][j] - C[i][j+1]
for i in range(2):
  for j in range(3):
    C2[i][j] = C[i][j] - C[i+1][j]
if(C1[0][0] == C1[1][0] and C1[1][0] == C1[2][0]):
  if(C1[0][1] == C1[1][1] and C1[1][1] == C1[2][1]):
    if(C2[0][0] == C2[0][1] and C1[0][1] == C1[0][2]):
      if(C2[1][0] == C1[1][1] and C1[1][1] == C1[1][2]):
        print("Yes")
        exit()
else:
  print("No")

### FIXED CODE ###

C = [0]*3
C1 = [[0]*2]*3
C2 = [[0]*3]*2
flg = False
for i in range(3):
  C[i] = list(map(int, input().split()))
for i in range(2):
  for j in range(2):
    if(C[i][j] -C[i][j+1] != C[i+1][j] -C[i+1][j+1]):
      flg = True
for i in range(2):
  for j in range(2):
    if(C[i][j] -C[i+1][j] != C[i][j+1] -C[i+1][j+1]):
      flg = True
print("No" if flg else "Yes")
N, Q = map(int, input().split())
tree = dict()
for _ in range(N-1):
  a, b = map(int, input().split())
  if a in tree:
    tree[a].append(b)
  else:
    tree[a] = [b]

point = [0] * (N+1)

def act(node, add):
  point[node] = point[node] + add
  if node in tree:
    for ch in tree[node]:
      act(ch, add)

for _ in range(Q):
  p, x = map(int, input().split())
  act(p, x)

ans = ' '.join([str(n) for n in point[1:]])
print(ans)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def abc138_d():
    N, _ = map(int, readline().strip().split())
    input_data = [tuple(map(int, ln.strip().split())) for ln in readlines()]

    # 隣接リスト作成
    graph = [[] for _ in range(N+1)]
    for a, b in input_data[:N-1]:
        graph[a].append(b)
        graph[b].append(a)

    # クエリをもとにスコア加算　※頂点pだけに加算し、子へは加算しない
    val = [0] * (N+1)
    for p, x in input_data[N-1:]:
        val[p] += x

    # DFSで根元から順に足していく
    stack = [1]
    visited =set([1])
    while stack:
        x = stack.pop()
        for y in graph[x]:
            if y in visited: continue
            stack.append(y)
            visited.add(y)
            val[y] += val[x]

    print(*val[1:], sep=' ')

abc138_d()
import bisect
import sys
sys.setrecursionlimit(3*10**5)

INF = 10**10

N = int(input())
a = list(map(int,input().split()))
T = [set() for x in range(N)]
for i in range(N-1):
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    T[u].add(v)
    T[v].add(u)

search = [0]*N

A = [INF]

ans = [-1]*N

def dfs(V):
    num = a[V]
    added = 0
    if A[-1] > num:
        A.append(num)
        added = 1
    else:
        k = bisect.bisect_left(A,num)
        v = A[k]
        A[k] = num
    ans[V] = len(A)
    for VV in T[V]:
        if search[VV]:
            continue
        search[VV] = 1
        dfs(VV)
    if added:
        A.pop()
    else:
        A[k] = v

search[0] = 1
dfs(0)

print(*ans,sep="\n")

### FIXED CODE ###

import bisect
import sys
sys.setrecursionlimit(3*10**5)

INF = 10**10

N = int(input())
a = list(map(int,input().split()))
T = [set() for x in range(N)]
for i in range(N-1):
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    T[u].add(v)
    T[v].add(u)

search = [0]*N

A = [INF]*N

ans = [-1]*N

def dfs(V):
    num = a[V]
    k = bisect.bisect_left(A,num)
    v = A[k]
    A[k] = num
    ans[V] = bisect.bisect_left(A,INF)
    # このにぶたん無駄じゃね？まあ間に合うからいいか……
    for VV in T[V]:
        if search[VV]:
            continue
        search[VV] = 1
        dfs(VV)
    A[k] = v

search[0] = 1
dfs(0)

print(*ans,sep="\n")
a = []
for i in range(3):
    a.append(list(map(int, input().split())))

n = int(input())
for i in range(n):
    b = int(input())
    for j in a:
        if b in j:
            a[a.index(j)][j.index(b)] = 0

ans = 0
for i in range(3):
    if a[0][i] == a[1][i] == a[2][i] == 0:
        ans = 1
    elif a[i][0] == a[i][1] == a[i][2] == 0:
        ans = 1
if a[0][0] == a[1][1] == a[2][2] == 0:
    ans = 1
if a[0][3] == a[1][1] == a[2][0] == 0:
    ans = 1
if ans == 1:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

a = []
for i in range(3):
    a.append(list(map(int, input().split())))

n = int(input())
for i in range(n):
    b = int(input())
    for j in a:
        if b in j:
            a[a.index(j)][j.index(b)] = 0

ans = 0
for i in range(3):
    if a[0][i] == a[1][i] == a[2][i] == 0:
        ans = 1
    elif a[i][0] == a[i][1] == a[i][2] == 0:
        ans = 1
if a[0][0] == a[1][1] == a[2][2] == 0:
    ans = 1
if a[0][2] == a[1][1] == a[2][0] == 0:
    ans = 1

if ans == 1:
    print("Yes")
else:
    print("No")
n = input()

zero = "0"
nine = "9"
zeronine = ""

for index in range(len(n)-1):
  if index%2==1:
    zeronine += zero
  else:
    zeronine += nine

if len(n)%2==0:
  print(int(zeronine))
else:
  print(int(n)-int(zeronine))

### FIXED CODE ###

n = input()

zero = "0"
nine = "9"
zeronine = ""

for index in range(len(n)-1):
  if index%2==1:
    zeronine += zero
  else:
    zeronine += nine

if len(n)%2==0:
  print(int(zeronine))
else:
  if len(n)==1:
    print(int(n))
  else:
    print(int(n)-int(zeronine))
x = int(input())
y = int(input())

if x==0 or y==0:
 print(x+y)
else:
  print(x+(y/2))

### FIXED CODE ###

X,Y = map(int,input().split())
 
print( X + (Y // 2))
a,b=input(int,input().split())
if a<10 and b<10:
  print(str(a*b))
else:
  print(-1)

### FIXED CODE ###

a,b=map(int,input().split())
if a<=9 and b<=9:
  print(a*b)
else:
  print(-1)
N, M = map(int, input().split())
L_max, R_min = 0, 100000
for i in range(M):
  L, R = map(int,input().split())
  if L_max < L:
    L_max = L
  if R_min > R:
    R_min = R
if R_min - L_max < 0:
  print(0)
else:
  print(R_min - L_max + 1)

### FIXED CODE ###

A, B = map(int, input().split())
if A > 12:
  print(B)
elif 5 < A <= 12:
  print(int(B/2))
else:
  print(0)
import math
import fileinput

for line in fileinput.input():
    return 2 * math.pi * line

### FIXED CODE ###

import math

R = int(input())
print(2 * math.pi * R)
# your code goes here
S = str(input())
K = int(input())
#print(S, K)
count = 0
while(S[count] == "1"):
	count += 1
if(K <= count):
	print("1")
else:
	print(S[count])

### FIXED CODE ###

# your code goes here
S = str(input())
K = int(input())
#print(S, K)
count = 0
while(count < len(S) and S[count] == "1"):
	count += 1
#print(count)
if(K <= count):
	print("1")
else:
	print(S[count])
strstart = input()
for i in strstart:
    if i == 'C':
        wzc = i
        break
for i in strstart:
    if i == 'F':
        wzf = i
        break
if wzc < wzf:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

s=input();pd=0
for i in range(0,len(s)):
    if s[i]=='C':
        pd=1
    if s[i]=='F'and pd==1:
        print('Yes')
        pd=2
        break
if pd!=2:
    print('No')
n = int(input())
if n%2==0:
    print(n, n, n//2)
else:
    f = False
    for i in range(1, 3500):
        _h = n/i
        for j in range(1,3500):
            _n = n/j
            w = n/(4-_h-_n)
            if w>0 and w%1==0:
                print(i, j, int(w))
                f = True
            if f: break
        if f: break

### FIXED CODE ###

N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        if 4*h*n-N*n-N*h>0 and (N*h*n)%(4*h*n-N*n-N*h)==0:
            print(h, n, (N*h*n)//(4*h*n-N*n-N*h))
            exit()
A,B,K = map(int,input().split())

X = list(range(A,B+1,1))
ans = X[0:K]+X[len(X)-K:len(X)]
ans = list(set(ans))
for i in range(len(ans)):
    print(ans[i])

### FIXED CODE ###

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

for i in range(A,B+1,1):
    if i-A < K or B-i < K:
        print(i)
X,Y = map(int,input().split())
# 何回移動するか
r = (X+Y)//3
# 移動の可能性 rC(x-r)
from functools import reduce
mod = 10**9+7
if (X+Y)%3==0:
    r = (X+Y)//3
    num = reduce(lambda x,y:x*y%mod,[k+1 for k in range(r)])
    p = reduce(lambda x,y:x*y%mod,[k+1 for k in range(X-r)])
    q = reduce(lambda x,y:x*y%mod,[k+1 for k in range(2*r-X)])
    ans = num*pow(p,mod-2,mod)*pow(q,mod-2,mod)%mod
    print(ans%mod)   
else:
    print(0)

### FIXED CODE ###

X,Y = map(int,input().split())
# 何回移動するか
r = (X+Y)//3
# 移動の可能性 rC(x-r)
from functools import reduce
mod = 10**9+7

if (X+Y)%3==0 and X<= 2*Y and Y<= 2*X :
    r = (X+Y)//3
    l = min
    if r != X and r != Y:
        num = reduce(lambda x,y:x*y%mod,[k+1 for k in range(r)])
        p = reduce(lambda x,y:x*y%mod,[k+1 for k in range(X-r)])
        q = reduce(lambda x,y:x*y%mod,[k+1 for k in range(2*r-X)])
        ans = num*pow(p,mod-2,mod)*pow(q,mod-2,mod)%mod
        print(ans%mod)   
    else:
        print(1)
else:
    print(0)
t=int(input())
print(t//3600+':'t//60%60':'t%60)


### FIXED CODE ###

S = int(input())
h = S // 3600
m = S % 3600 // 60
s = S % 60
print(str(h)+":"+str(m)+":"+str(s))
import math

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

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

print(lcm(a, b))

### FIXED CODE ###

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

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

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

print(lcm(a, b))
# -*- coding: <encoding name> -*-

s = input()
s_former = s[:(n - 1) / 2 + 1]
s_latter = s[(n + 3) / 2 + 1:]
print('Yes' if s == s[::-1] and s_former == s_former[::-1] and s_latter == s_latter[::-1])


### FIXED CODE ###

S = input()
N = len(S)
S1 = S[0:(N-1)//2]
S2 = S[(N+3)//2-1:N+1]
print("Yes" if S == S[::-1] and S1 == S1[::-1] and S2 == S2[::-1] else "No")
S=raw_input()

M=10**9+7

all=1
abc=0
ab=0
a=0

for x in S:
	if x=="A":
		a+=all
	if x=="B":
		ab+=a
	if x=="C":
		abc+=ab

	if x=="?":
		abc=abc*3+ab
		ab=ab*3+a
		a= a*3+all
		all*=3

	abc%=M
	ab%=M
	a%=M
	ans%=M


print abc%M


### FIXED CODE ###

S=raw_input()

M=10**9+7

all=1
abc=0
ab=0
a=0

for x in S:
	if x=="A":
		a+=all
	if x=="B":
		ab+=a
	if x=="C":
		abc+=ab

	if x=="?":
		abc=abc*3+ab
		ab=ab*3+a
		a= a*3+all
		all*=3

	abc%=M
	ab%=M
	a%=M
	all%=M


print abc%M
S = input()
T = input()
cnt = 0
for i in range(len(s)):
    if S[i]==T[i]:
        cnt += 1
print(cnt) 

### FIXED CODE ###

S = input()
T = input()
cnt = 0
for i in range(len(S)):
    if S[i]==T[i]:
        cnt += 1
print(cnt)
def calc(a):
  m = min(a)
  b = [i % m for i in a if i % m != 0]
  if b:
    return calc([*b, m])
  else:
    return min(a)
      
if __name__ == "__main__":
  _ = int(input())
  print(calc(list(map(int, input().split()))))

### FIXED CODE ###

def calc(a):
    m = min(a)
    b = [i % m for i in a if i % m != 0]
    if b:
        return calc(b+[m])
    else:
        return min(a)
      
_ = int(input())
print(calc(list(map(int, input().split()))))
N,K=(int(i) for i in input().split())
hlist=[]
for _ in range(N):
    hlist.append(int(input()))
hlist.sort()
for j in range(N-K+2):
    dif=[hlist[j+k]-hlist[j]]
print(min(dif))

### FIXED CODE ###

N,K=(int(i) for i in input().split())
hlist=[int(input()) for i in range(N)]
hlist.sort()
dif=[]
for j in range(N-K+1):
    dif.append(hlist[j+K-1]-hlist[j])
print(min(dif))
n, m, k = list(map(int, input().split()))
ns = list(map(int, input().split()))
ms = list(map(int, input().split()))

import pandas as pd
nss = pd.Series([0] + ns).cumsum()
mss = pd.Series([0] + ms).cumsum()

mx = 0
for i in range(n + 1):
    if nss[i] > k:
        break

    j = -1
    for v in mss:
        if nss[i] + v > k:
            break
        j += 1
    mx = max(mx, i + j)

print(mx)

### FIXED CODE ###

n, m, k = list(map(int, input().split()))
ns = list(map(int, input().split()))
ms = list(map(int, input().split()))

nss = [0]
for i, v in enumerate(ns):
    nss.append(nss[i] + ns[i])

mss = [0]
for i, v in enumerate(ms):
    mss.append(mss[i] + ms[i])

mx = 0
j = m
for i in range(n + 1):
    if nss[i] > k:
        break

    while mss[j] > k - nss[i]:
        j -= 1
    
    mx = max(mx, i + j)

print(mx)
H,W,M=map(int,input().split())
dicti={}
dictj={}
bomb=[]
for i in range(M):
  h,w=map(int,input().split())
  bomb.append((h,w))
  if h in dicti:
    dicti[h]+=1
  if h not in dicti:
    dicti[h]=1
  if w in dictj:
    dictj[w]+=1
  if w not in dictj:
    dictj[w]=1
LI=sorted(dicti.items(),key=lambda x:x[1],reverse=True)
LJ=sorted(dictj.items(),key=lambda x:x[1],reverse=True)
Imax=LI[0][1]
Jmax=LJ[0][1]
I=0
J=0
IL=[]
for i in range(len(LI)):
  if LI[i][1]==Imax:
    I+=1
for j in range(len(LJ)):
  if LJ[i][1]==Jmax:
    J+=1
pos=0
for i in range(M):
  if dicti[bomb[i][0]]==Imax and dictj[bomb[i][0]]==Jmax:
    pos+=1
if pos==I*J:
  print(Imax+Jmax)
else:
  print(Imax+Jmax-1)
    

### FIXED CODE ###

H,W,M=map(int,input().split())
dicti={}
dictj={}
bomb=set()
for i in range(M):
  h,w=map(int,input().split())
  bomb.add((h,w))
  if h in dicti:
    dicti[h]+=1
  if h not in dicti:
    dicti[h]=1
  if w in dictj:
    dictj[w]+=1
  if w not in dictj:
    dictj[w]=1
LI=sorted(dicti.items(),key=lambda x:x[1],reverse=True)
LJ=sorted(dictj.items(),key=lambda x:x[1],reverse=True)
Imax=LI[0][1]
Jmax=LJ[0][1]
I=0
J=0
IL=[]
JL=[]
for i in range(len(LI)):
  if LI[i][1]==Imax:
    IL.append(LI[i][0])
for i in range(len(LJ)):
  if LJ[i][1]==Jmax:
    JL.append(LJ[i][0])
  
ans=Imax+Jmax-1

for h in IL:
  for w in JL:
    if (h,w) not in bomb:
      ans=Imax+Jmax
      break
print(ans)
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,=pin()
    A=tupin()
    
    from math import gcd

    temp=A[0]
    for i in range(1,N):
          temp=gcd(temp,A[i])
    print(temp)
    
#%%submit!
resolve()

### FIXED CODE ###

# coding: utf-8
# Your code here!
import fractions
from functools import reduce
def pin(type=int):
    return map(type,input().split())


N, =pin()
m = list(pin())




def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

print(gcd_list(m))
print(X[1])
print(X[2])
print(X[3])
print(X[4])
print(X[5])
print(X[6])
print(X[7])
print(X[8])
print(X[9])
print(X[10])

### FIXED CODE ###

r,D,x = map(int,input().split())
X = [x]*11

for i in range(0,10):
  X[i+1] = r*X[i] - D
  
  
print(X[1])
print(X[2])
print(X[3])
print(X[4])
print(X[5])
print(X[6])
print(X[7])
print(X[8])
print(X[9])
print(X[10])
a, b, c = map(int, input().split())

for i in range(a, b+1):
	if i=c:
		print("Yes")
		exit()
print("No")

### FIXED CODE ###

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

if(a<b):
	for i in range(a, b):
		if i==c:
			print("Yes")
			exit()
if(a>b):
	for i in range(b, a):
		if i==c:
			print("Yes")
			exit()

print("No")
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return int(input())
from collections import defaultdict, Counter
import bisect

sys.setrecursionlimit(100000)

n = SI()
xy = [(0,0) for _ in range(n)]
div = []
for i in range(n):
    x, y = LI()
    xy[i] = (x, y)
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        else:
            div.append("{}_{}".format(xy[i][0] - xy[j][0], xy[i][1]- xy[j][1]))
c = Counter(div)
max_ = c.most_common()[0][1]
print(n - max_)

### FIXED CODE ###

import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return int(input())
from collections import defaultdict, Counter
import bisect

sys.setrecursionlimit(10000000)

n = SI()
xy = [(0,0) for _ in range(n)]
div = defaultdict(int)
for i in range(n):
    x, y = LI()
    xy[i] = (x, y)
if n==1:
    print(1)
else:
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            else:
                div["{}_{}".format(xy[i][0] - xy[j][0], xy[i][1]- xy[j][1])] += 1

    max_ = max(div.values())
    print(n - max_)
import sys
while 1:
    a, b = map(int, sys.stdin.readline().split())
    c = a + b
    c = str(c)
    print(len(c))

### FIXED CODE ###

import fileinput
for line in fileinput.input():
    a, b = map(int, line.split())
    print(len(str(a + b)))
a, b, c = map(int, input().split())

print(a[0].upper()+b[0].upper()+c[0].upper())

### FIXED CODE ###

a, b, c = input().split()
 
print(a[0].upper()+b[0].upper()+c[0].upper())
while 1:
	n = input()
	if n == 0: break
	item = {}
	for i in range(n):
		name,cost = raw_input().split()
		item[name] = int(cost)
	m = input()
	recipes = [raw_input().split() for i in range(m)]
	for recipe in recipes:
		if recipe[0] not in item:
			item[recipe[0]] = 2<<31
	recipes = sorted(recipes, key = lambda x: item[x[0]])
	for recipe in recipes:
		name = recipe[0]
		needs = recipe[2:]
		cost = 0
		for need in needs:
			cost += item[need]
		item[name] = min(cost, item[name])
	print item[raw_input()]

### FIXED CODE ###

while 1:
	n = input()
	if n == 0: break
	item = {}
	for i in range(n):
		name,cost = raw_input().split()
		item[name] = int(cost)
	for i in range(input()):
		recipe = raw_input().split()
		cost = sum(item[name] if name in item else 0 for name in recipe[2:])
		item[recipe[0]] = min(cost, item[recipe[0]])
	print item[raw_input()]
a,b,k=map(int,input().split())
ans=[]
for i in range(1,101): if (a%i==0 and b%i==0): ans.append(i)
print(ans[-k])

### FIXED CODE ###

a,b,k=map(int,input().split())
ans=[]
for i in range(1,101):
    if (a%i==0 and b%i==0): ans.append(i)
print(ans[-k])
import numpy as np

N, K, Q = map(int, input().split())
A = np.array([int(input()) for i in range(Q)])
  
points = K - Q
for i in range(1, N+1):
  correct_num = len(np.where(A==i)[0])
  fin_point = points[i-1] + correct_num
  
  if fin_point > 0:
    print("Yes")
  else:
    print("No")  

### FIXED CODE ###

import numpy as np

N, K, Q = map(int, input().split())
A = np.array([int(input()) for i in range(Q)])
  
points = np.full(N, K-Q)

for i in range(0, Q):
  points[A[i]-1] += 1
 
for i in points:
  if i > 0:
    print("Yes")
  else:
    print("No")
N = int(input())

word = []
for i in range(N):
    word.append(input())

for i in range(N - 1):
    if word.count(word[i]) != 1:
        print('No')
        exit()

for i in range(1, N):
    if word[i][0] != word[i - 1][-1]:
        print('No')
        exit()

print('Yes')


### FIXED CODE ###


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

AB = A * B

for C in range(1, 4):
    if (AB * C) % 2 == 1:
        print('Yes')
        exit()

print('No')
import sys
input = sys.stdin.readline
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
ans = 0
flag = True
l = []
r = set(list(range(n)))
N = n*(n-1) // 2
for _ in range(N)
    if l and not r:
        print(ans)
        break
    ne = set()
    for j in r:
        if not a[j]:
            continue
        c = a[j][0]
        if c == "-":
            continue
        if j + 1 == a[c-1][0]:
            a[j][0] = "-"
            a[c-1][0] = "-"
            ne.add(j)
            ne.add(c-1)
    l = list(ne)
    for j in l:
        if a[j]:
            if a[j][0] == "-":
                a[j] = a[j][1:]
                flag = False
                if not a[j]:
                    ne.remove(j)
    if flag:
        print(-1)
        break
    else:
        r = ne
        ans += 1


### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
ans = 0
r = set(list(range(n)))
N = n*(n-1) // 2 + 1
for _ in range(N):
    if not r:
        print(_)
        break
    ne = set()
    flag = True
    for j in r:
        if not a[j]:
            continue
        c = a[j][0]
        if c == "-":
            continue
        if j + 1 == a[c-1][0]:
            a[j][0] = "-"
            a[c-1][0] = "-"
            ne.add(j)
            ne.add(c-1)
    for j in list(ne):
        if a[j]:
            if a[j][0] == "-":
                a[j].pop(0)
                flag = False
                if not a[j]:
                    ne.remove(j)
    if flag:
        print(-1)
        break
    else:
        r = ne
s = list(input())
print(s.reverse.index("Z")-s.index("A")+1)

### FIXED CODE ###

s = list(input())
print(len(s)-s[::-1].index("Z")-s.index("A"))