Harryxun/stf_run huggingface dataset:
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= 1

# print(a)
cnt = [0]*(10**5)
cnt2 = [0]*(10**5)#何回目に出てきたか
t = []
nxt = 0
loop = 0

for i in range(10**5):
    cnt[nxt] += 1
    if cnt[nxt] >= 2:
        # print("i: " + str(i))
        # print("nxt: " + str(nxt))
        loop = i - cnt2[nxt]
        modC = max(0, cnt2[nxt])
        break
    cnt2[nxt] = i
    t.append(nxt)
    nxt = a[nxt]

modK = (k-modC)%loop
# print("-------")
# print(t)
# print("modC: " + str(modC))
# print("modK: " + str(modK))
# print("loop: " + str(loop))
# print(modK)
# print(loop)
# print("-------")

print(t[modC + modK] + 1)

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= 1

cnt = [0]*(2*10**5)#何回出たか
cnt2 = [0]*(2*10**5)#何回目に出てきたか
t = []
nxt = 0
loop = 0

for i in range(2*10**5):
    cnt[nxt] += 1
    if cnt[nxt] >= 2:
        # print("i: " + str(i))
        # print("nxt: " + str(nxt))
        loop = i - cnt2[nxt]
        modC = cnt2[nxt]
        break
    cnt2[nxt] = i
    t.append(nxt)
    nxt = a[nxt]

modK = (k-modC)%loop
# print("-------")
# print(t)
# print("modC: " + str(modC))
# print("modK: " + str(modK))
# print("loop: " + str(loop))
# print(modK)
# print(loop)
# print("-------")

if k < modC:
    print(t[k] + 1)
else:
    print(t[modC + modK] + 1)

"""
発想はあってる
テストケース公開されたら試してみる！
"""
N, M = map(int, input().split())
parent = [i for i in range(N + M)]
def find(x):
    if x == parent[x]:
        return x
    parent[x] = find(parent[x])
    return parent[x]

def unite(x, y):
    x, y = find(x), find(y)
    if x == y:
        return
    parent[y] = x
for i in range(N):
    for l in list(map(int, input().split()))[1:]:
        # 言語はparentの後半
        unite(i, N + l - 1)
if all(find(0) == find(i) for i in range(N)):
    print('YES')
else:
    print('NO')

### FIXED CODE ###

N, M = map(int, input().split())
parent = [i for i in range(N + M)]
rank = [1] * (N + M)
def find(x):
    if x == parent[x]:
        return x
    parent[x] = find(parent[x])
    return parent[x]

def unite(x, y):
    x, y = find(x), find(y)
    if x == y:
        return
    if rank[x] == rank[y]:
        rank[x] += 1
    elif rank[x] < rank[y]:
        x, y = y, x
    parent[y] = x
for i in range(N):
    for l in list(map(int, input().split()))[1:]:
        # 言語はparentの後半
        unite(i, N + l - 1)
if all(find(0) == find(i) for i in range(N)):
    print('YES')
else:
    print('NO')
N, K = map(int,input().split())
p = list(map(int,input().split()))
c = list(map(int,input().split()))
K = K-1
ans = -10**9-1
for i in range(N):
   i += 1
   start = i
   circle = 1
   number = c[i-1]
   while i != start:
      i = p[i-1]
      circle += c[i-1]
      number += 1
   for j in range (min(number, K+1)):
      sum = 0
      for k in range(i, i+j+1):
         index = (i + j - 1)%number
         sum += c[index]
      if circle > 0:
         sum = circle*((K-j)//number) + sum
      ans = max(sum, ans)
print(ans)

### FIXED CODE ###

N, K = map(int,input().split())
p = list(map(int,input().split()))
c = list(map(int,input().split()))
K = K-1
ans = -10**9-1
for h in range(N):
   i = h+1
   start = i
   circle = [c[i-1]]
   i = p[i-1]
   while i != start:
      score = circle[-1] + c[i-1]
      circle.append(score)
      i = p[i-1]
   l=len(circle)
   for j in range(min(l, K+1)):
      if circle[l-1] > 0:
         score = circle[j] + ((K - j)//l)*circle[l-1]
      else:
         score = circle[j]
      ans = max(score, ans)      
print(ans)
a=int(input())
b=list(map(int,input().split()))
c=int(input())
d=list(map(int,input().split()))
e=set(d)

for item in e:
  if d.count(item)>c.count(item):
    print("NO")
    exit()
    
print("YES")

### FIXED CODE ###

import collections

a=int(input())
b=collections.Counter(list(map(int,input().split())))
c=int(input())
d=collections.Counter(list(map(int,input().split())))
e=set(d)

for item in e:
  if d[item]>b[item]:
    print("NO")
    exit()
    
print("YES")
def main():
    N = int(input())
    edges = [[-1]*N for _ in range(N)]
    e_num = [0] * N 
    for l in range(N-1):
        i, j = [int(x)-1 for x in input().split()]
        edges[i][j] = edges[j][i] = l
        e_num[i] += 1
        e_num[j] += 1
    look = -1
    for ind, l in enumerate(e_num):
        if l == 1:
            look = ind
            break
    color = [-1]*(N-1)
    mc, c = a(N, 0, look, color, edges)
    print(mc+1)
    for i in c:
        print(i+1)


def a(N, maxc, look, color, edges):
    nexts = []
    used = []
    for i in range(N):
        if edges[look][i] != -1:
            if color[edges[look][i]] != -1:
                used.append(color[edges[look][i]])
            else:
                nexts.append(i)
    c = 0
    for n in nexts:
        while c in used:
            c += 1
        color[edges[look][n]] = c
        maxc = max(c, maxc)
        c += 1
    for n in nexts:
        maxc = max(maxc, a(N, maxc, n, color, edges)[0])
    return maxc, color
    

main()

### FIXED CODE ###

import sys
from collections import deque

# txt = "100000"
# for i in range(99999):
#     txt += "\n" + str(i) +" " +  str(i+1)
# def i():
#     for l in txt.split("\n"):
#         yield l
# input = i().__next__
def main():
    N = int(input())
    mawari = [[] for _ in range(N)]
    e_num = [0] * N 
    for l in range(N-1):
        i, j = [int(x)-1 for x in input().split()]
        e_num[i] += 1
        e_num[j] += 1
        mawari[i].append((j, l))
        mawari[j].append((i, l))
    look = -1
    for ind, l in enumerate(e_num):
        if l == 1:
            look = ind
            break
    color = [-1]*(N-1)
    c_prev = deque([-1])
    to_visit = deque([look])
    maxc = 0
    while len(to_visit)>=1:
        look = to_visit.pop()
        c = 0
        prevc = c_prev.pop()
        for i,j in mawari[look]:
            if color[j] != -1:
                continue
            if c == prevc:
                c += 1
            color[j] = c
            c_prev.append(c)
            to_visit.append(i)
            maxc = max(maxc, c)
            c += 1
        
    # mc, c = a(N, 0, look, color, mawari, -1)
    print(maxc+1)
    for i in color:
        print(i+1)


# def a(N, maxc, look, color, mawari, prev):
#     nexts = mawari[look]
#     c = 0
#     for i,j in nexts:
#         if c == prev:
#             c += 1
#         color[j] = c
#         maxc = max(maxc, a(N, maxc, i, color, mawari, c)[0])
#         c += 1
#     return maxc, color
    

main()
n = raw_input[0]
m = raw_input[1:len(raw_input)-2]
y = raw_input[-2:]
y += [0]
remainder = 0
total = 0
for i in range(n+1):
    y[i] += remainder
    total += min(y[i], m[i])
    remainder = max(y[i] - m[i], 0)
    print(remainder)
print(total)

### FIXED CODE ###

from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys


def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


def main():
    n = I()
    monster = LI()
    ret = 0
    ans = sum(monster)
    savor_lim = LI()
    for i in range(n - 1, -1, -1):
        k = min(savor_lim[i], monster[i + 1])
        monster[i + 1] -= k
        savor_lim[i] -= k
        monster[i] -= min(savor_lim[i], monster[i])
    return ans - sum(monster)



print(main())
N = set(int(input()))
if len(N)<=2:
  print("Yes")
else:
  print("No)

### FIXED CODE ###

n = input()
mae_n = n[:-1]
ushiro_n = n[1:]
if (len(set(mae_n))==1)or(len(set(ushiro_n))==1):
  print("Yes")
else:
  print("No")
# 入力
# r, g, b = map(str, input().split())
r = input()
g = input()
b = input()


# 処理&出力
number = int(r + g + b)
if number % 4 == 0:
    print('Yes')
else:
    print('No')



### FIXED CODE ###

# 入力
r, g, b = map(str, input().split())

# 処理&出力
number = r + g + b
if int(number) % 4 == 0:
    print('YES')
else:
    print('NO')
N=int(input())
s=''
point=0
q1,q2,q3=0,0,0 #q1はBA q2はBの最初のみ q3はAの末尾のみ
for j in range(N):
    n=str(input())
    point+=n.count("AB")
    if n[0]=="B" and n[len(n)-1]=="A":
      q1+=1  
    elif n[0]=="B":
      q2+=1
    elif n[len(n)-1]=="A":
      q3+=1
    else:
      pass
if q1>=1:
  if q2==0 and q3==0:
    print(q1-1+point)
  elif q2==0 or q3==0
    print(q1-1+1+point)
  else:
    print(q1-1+point+2+min(q2-1,q3-1))
else:
  print(min(q2,q3)+point)

### FIXED CODE ###

N=int(input())
s=''
point=0
q1,q2,q3=0,0,0 #q1はBA q2はBの最初のみ q3はAの末尾のみ
for j in range(N):
    n=str(input())
    point+=n.count("AB")
    if n[0]=="B" and n[len(n)-1]=="A":
      q1+=1  
    elif n[0]=="B":
      q2+=1
    elif n[len(n)-1]=="A":
      q3+=1
    else:
      pass
if q1>=1:
  if q2==0 and q3==0:
    print(q1-1+point)
  elif q2==0 or q3==0:
    print(q1-1+1+point)
  else:
    print(q1-1+point+2+min(q2-1,q3-1))
else:
  print(min(q2,q3)+point)
----:---F1  *scratch*      All L1     (Fundamental)-----------------------------
Loading subst-jis...done
S = input()
T = input()

S_list = []
T_list = []
print(S_list)
print(T_list)
alpha = "abcdefghijklmnopqrstuvwxyz"

for i in alpha:
    SS = S.count(i)
    TT = T.count(i)
    if SS and TT > 0:
        S_list.append(SS)
        T_list.append(TT)

if sorted(S_list) != sorted(T_list):
    print('No')
else:
    print('Yes')

### FIXED CODE ###

S = input()
T = input()

S_list = []
T_list = []
alpha = "abcdefghijklmnopqrstuvwxyz"

for i in alpha:
    SS = S.count(i)
    TT = T.count(i)
    if SS > 0:
        S_list.append(SS)
    if TT > 0:
        T_list.append(TT)

if sorted(S_list) != sorted(T_list):
    print('No')
else:
    print('Yes')
import numpy as np

N=int(input())
A=[int (x) for x in input().split()]
p=[0]*N
for i in range(N-1):
    p[A[i]-1]+=1
for i in range(N):
    print(int(p[i]))

### FIXED CODE ###

N=int(input())
A=[int (x) for x in input().split()]
p=[0]*N
for i in range(N-1):
    p[A[i]-1]+=1
for i in range(N):
    print(int(p[i]))
a=int(input())
s=str(input())

if a>=3200:
    input(s)
else:
    input("red")

### FIXED CODE ###

a=int(input())
s=str(input())

if a>=3200:
    print(s)
else:
    print("red")
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**8)
n,k=map(int,input().split())
z=list(map(int,input().split()))
dp=[0 for i in range(len(z))]
vi=[0 for i in range(len(z))]
def dps(i,dp,vi):
    if(i<=0):
        return 0;
    if(vi[i]==1):
        return dp[i];
    
    vi[i]=1
    maxa=98778979878
    for j in range(1,min(i+1,k+1)):
        maxa=min((dps(i-j,dp,vi)+abs(z[i]-z[i-j])),maxa)
    dp[i]=maxa
    return dp[i];
print(dps(len(z)-1,dp,vi))



### FIXED CODE ###

n=int(input())
z=list(map(int,input().split()))
ans=[0,abs(z[1]-z[0])]

for i in range(2,len(z)):
    ans.append(min(abs(z[i]-z[i-1])+ans[-1],abs(z[i]-z[i-2])+ans[-2]))
print(ans[-1])
x,y = list(map(int,input().split()))

mod = 10**9 + 7

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

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

# def comb(n,r,mod):
# 	'''
# 	return nCr
# 	O(min{n-r, r})
# 	'''
# 	a=1
# 	b=1
# 	r = min(r,n-r)
# 	for i in range(r):
# 		a = a*(n-i)%mod
# 		b = b*(i+1)%mod
# 	return a*pow(b,mod-2,mod)%mod

if (x+y)%3!=0:
    print(0)
    exit()
else:
    n = int((2/3)*x - (1/3)*y)
    m = int((2/3)*y - (1/3)*x)
    if n>=0 and m>=0:
        print(comb(n+m,m,mod))
        exit()
    else:
        print(0)
        exit()

### FIXED CODE ###

x,y = list(map(int,input().split()))

mod = 10**9 + 7

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

# def comb(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

def comb_mod(n, r, mod):
    if n < r:
        return 0
    elif n < 0 or r < 0:
        return 0
    else:
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, n + 1):
            fac.append(fac[-1] * i % mod)
            inv.append(-inv[mod % i] * (mod // i) % mod)
            finv.append((finv[-1] * inv[-1]) % mod)
        return int(fac[n] * finv[r] * finv[n - r] % mod)


# def comb(n,r,mod):
# 	'''
# 	return nCr
# 	O(min{n-r, r})
# 	'''
# 	a=1
# 	b=1
# 	r = min(r,n-r)
# 	for i in range(r):
# 		a = a*(n-i)%mod
# 		b = b*(i+1)%mod
# 	return a*pow(b,mod-2,mod)%mod

if (x+y)%3!=0:
    print(0)
    exit()
else:
    m = int((2*x - y)/3)
    n = int((2*y - x)/3)
    if n>=0 and m>=0:
        print(comb_mod(n+m,n,mod))
        exit()
    else:
        print(0)
        exit()
A, B, N = map(int,input().split())

x = N
for x in reversed(range(1,N+1)):
  if x % B != 0:
    print(int(A*x/B)-A*int(x/B))
    exit()


print(0)

### FIXED CODE ###

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

for i in range(A,B+1):
  if i % K == 0:
    print("OK")
    exit()
    
print("NG")
a, b, c = map(str,input().split())
print(upper(a[0] + b[0] + c[0]))

### FIXED CODE ###

a, b, c = map(str,input().split())
print((a[0] + b[0] + c[0]).upper())
a,b,c,d,e,f = map(int, input().split())

ab_list = set()

for i in range(0,f//100+1,a):
    for j in range(0, f//100-i+1, b):
        ab_list.add(100*(i+j))

ab_max = max(ab_list)

sug_max = int(ab_max*(e/100))

cd_list = set()

for i in range(0,sug_max+1, c):
    for j in range(0, sug_max-i+1, d):
        cd_list.add(i+j)


water = list(ab_list)
water.sort()

sugar = list(cd_list)
sugar.sort()

s = 0
ans = [0,0]
max_noudo = 0
for w in water[1:]:
    while (sugar[s+1] <= int(w*e/100)):
        if (s+1) >= len(sugar)-1:
            break
        s += 1
        
    noudo = sugar[s]/(w+sugar[s])
    if noudo > max_noudo:
        max_noudo = noudo
        ans = [w+sugar[s], sugar[s]]
        
print(*ans)

### FIXED CODE ###

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

ab_list = set()

for i in range(0,f//100+1,a):
    for j in range(0, f//100-i+1, b):
        ab_list.add(100*(i+j))

ab_max = max(ab_list)

sug_max = int(ab_max*(e/100))

cd_list = set()

for i in range(0,sug_max+1, c):
    for j in range(0, sug_max-i+1, d):
        cd_list.add(i+j)

water = list(ab_list)
water.sort()

sugar = list(cd_list)
sugar.sort()

max_noudo = -1
ans = [0,-1]
for w in water:
    for s in sugar:
        if w==0 and s==0:
            continue
        if 100*s <= e*w and w+s <= f:
            noudo = s/(w+s)
            if noudo > max_noudo:
                max_noudo = noudo
                ans = [w+s, s]
                
print(*ans)
a = int(input())
b = []
sum = 0
for i in range(a):
  b[i] = int(input())
  sum += b[i]
print(sum)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
sam = 0
for i in range(N):
  sam += A[i]**-1
print(sam**-1)
n=int(input())
print(n**3))

### FIXED CODE ###

n=int(input())
print(n**3)
x=int(input())


if x>0:
    if x%11>5:
        ans=(x//11)*2+2

    elif 1<=x%11<=5:
        ans=(x//11)*2+1

print(ans)

### FIXED CODE ###

x = int(input())
 
ans = (x//11)*2
remainder = x%11
if remainder == 0:
    print(ans)
elif 1 <= remainder <= 6:
    print(ans+1)
else:
    print(ans+2)
from collections import defaultdict
length, types = map(int, input().split(" "))
match = [n for n in input().split(" ")]
cost = defaultdict(int)
cost.update({"1":2, "2":5, "3":5, "4":4, "5":5, "6":6, "7":3, "8":7, "9":6})

dp = ["" for n in range(length + 1)]

def compare_str(a, b):
    if len(a) == len(b):
        return a if a > b else b
    elif len(a) > len(b):
        return a
    return b
        

for m in match:
    dp[cost[m]] = m

for i in range(length):
    # print(dp, i)
    if dp[i]:
        for m in match:
            if i + cost[m] <= length:
                if dp[i + cost[m]]:
                    dp[i + cost[m]] = compare_str(dp[i + cost[m]], dp[i] + m)
                else:
                    dp[i + cost[m]] = dp[i] + m
print(dp[length])

### FIXED CODE ###

from collections import defaultdict
length, types = map(int, input().split(" "))
match = [n for n in input().split(" ")]
cost = {}
cost.update({"1":2, "2":5, "3":5, "4":4, "5":5, "6":6, "7":3, "8":7, "9":6})

dp = ["-" for n in range(10010)]

def compare_str(a, b):
    if a == "":
        return b
    elif len(a) == len(b):
        return a if a > b else b
    elif len(a) > len(b):
        return a
    return b
    
# for m in match:
#     dp[cost[m]] = m
dp[0] = ""
for i in range(length + 1):
    # print(dp, i)
    if dp[i] != "-":
        for m in match:
            # if i + cost[m] <= length:
            dp[i + cost[m]] = compare_str(dp[i + cost[m]], dp[i] + m)
print(dp[length])
x=int(input())
a=int(input())
b=int(input())
ans=x-a
print(ans>=b):
  ans-=b
print('ans')

### FIXED CODE ###

x=int(input())
a=int(input())
b=int(input())
ans=x-a
while ans>=b:
  ans-=b
print(ans)
# encoding: utf-8


import sys


class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        length_1 = int(self.__input[0])
        array_1 = list(map(int, self.__input[1].split()))
        length_2 = int(self.__input[2])
        array_2 = list(map(int, self.__input[3].split()))

        assert length_1 == len(array_1) and length_2 == len(array_2)

        count = 0
        for each in array_2:
            if self.linear_search(key=each, array=array_1, array_length=length_1):
                count += 1

        return str(count)

    @staticmethod
    def linear_search(key, array, array_length):
        # print(len(set(array_1).intersection(set(array_2))))
        for i in array_length:
            if array[i] == key:
                return True
        return False


if __name__ == '__main__':
    case = Solution()
    print(case.solution)

### FIXED CODE ###

# encoding: utf-8


import sys


class Solution:
    def __init__(self):
        """
        init input array
        """
        self.__input = sys.stdin.readlines()

    @property
    def solution(self):
        length_1 = int(self.__input[0])
        array_1 = list(map(int, self.__input[1].split()))
        length_2 = int(self.__input[2])
        array_2 = list(map(int, self.__input[3].split()))

        assert length_1 == len(array_1) and length_2 == len(array_2)

        count = 0
        for each in array_2:
            if self.linear_search(key=each, array=array_1, array_length=length_1):
                count += 1

        return str(count)

    @staticmethod
    def linear_search(key, array, array_length):
        # print(len(set(array_1).intersection(set(array_2))))
        for i in range(array_length):
            if array[i] == key:
                return True
        return False


if __name__ == '__main__':
    case = Solution()
    print(case.solution)
from math import sqrt
a, b, c = map(int, input().split())

if a+b > c:
    print("No"):
elif (c-a-b)/2 > sqrt(a*b):
    print("Yes")
else:
    print("No")


### FIXED CODE ###

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

if a+b > c:
    print("No")
elif (c-a-b)**2 > 4*a*b:
    print("Yes")
else:
    print("No")
from sys import stdin

input = stdin.readline


def p_a():
    n = int(input())
    print(((n + 1) // 2) / n)


def p_b():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))

    print(sum(map(lambda x: x >= k, h)))


def p_c():
    n = int(input())
    k = list(map(int, input().split()))

    print(*[i[0] for i in sorted(enumerate(k, start=1), key=lambda x: x[1])])


import math


def euclid(a, b):
    mod = a % b
    return b if mod == 0 else euclid(b, mod)


def seachPrimeNum(N):
    max = int(math.sqrt(N))
    seachList = [i for i in range(2, N + 1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum


def p_d():
    a, b = map(int, input().split())
    gcd = euclid(max(a, b), min(a, b))

    ans = 1
    nums = seachPrimeNum(gcd)
    for i in nums:
        if gcd % i == 0:
            ans += 1

    print(ans)


if __name__ == '__main__':
    p_d()


### FIXED CODE ###

def calc_gcd(a, b):
    return calc_gcd(b, a % b) if b else a


def p_d():
    a, b = map(int, input().split())
    gcd = calc_gcd(a, b)
    ans = 1
    cnt = 2
    while cnt * cnt < gcd:
        up = True
        while gcd % cnt == 0:
            if up:
                ans += 1
                up = False
            gcd //= cnt
        cnt += 1
    ans += 1 if gcd != 1 else 0
    print(ans)


if __name__ == '__main__':
    p_d()
a = int(input())
b = float(input())

print(a*b)

### FIXED CODE ###

a, b = map(str, input().split())
a = int(a)
b1, b2 = b.split('.')
b = int(b1) * 100 + int(b2)
ans = a * b
print(ans//100)
N,A,B,C=map(int,input().split())

l=[int(input()) for i in range(N)]

INF=3000

def mp(co,a,b,c):
    if co==N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF

    ret0=mp(co+1,a,b,c)
    ret1=mp(co+1,a+1,b,c)+10
    ret2=mp(co+1,a,b+1,c)+10
    ret3=mp(co+1,a,b,c+1)+10

    return min(ret0,ret1,ret2,ret3)

print(mp(0,0,0,0))
N,A,B,C=map(int,input().split())

l=[int(input()) for i in range(N)]

INF=3000

def mp(co,a,b,c):
    if co==N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF

    ret0=mp(co+1,a,b,c)
    ret1=mp(co+1,a+1,b,c)+10
    ret2=mp(co+1,a,b+1,c)+10
    ret3=mp(co+1,a,b,c+1)+10

    return min(ret0,ret1,ret2,ret3)

print(mp(0,0,0,0))


### FIXED CODE ###

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

l=[int(input()) for i in range(N)]

INF=3000

def mp(co,a,b,c):
    if co==N:
        return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF

    ret0=mp(co+1,a,b,c)
    ret1=mp(co+1,a+l[co],b,c)+10
    ret2=mp(co+1,a,b+l[co],c)+10
    ret3=mp(co+1,a,b,c+l[co])+10

    return min(ret0,ret1,ret2,ret3)

print(mp(0,0,0,0))
N, M = map(int, input().split())
A_s = list(map(int,input().split()))


x = 0
for l in range(N):
  for r in range(N-l):
    hoge = float(sum(A_s[l:l+r+1]) / M)
    if hoge.is_integer():
      x += 1
      
print(x)

### FIXED CODE ###

N, K = map(int, input().split())
r = N % K
if r == 0:
  print(0)
else:
  print(1)
import sys
a = []
b = []
a = input()
b = input()

for num in range(0,len(a)):
   sys.stdout.write(a[num])
   sys.stdout.write(b[num])

### FIXED CODE ###

import sys
a = []
b = []
a = input()
b = input()

for num in range(0,len(a)):
   sys.stdout.write(a[num])
   if len(b) > num:
       sys.stdout.write(b[num])
S = input()
T = input()
ind = 0
w = ""
for i in range(len(S)):
  if S[i] == "?" or S[i] == T[ind]:
    ind += 1
    if ind == len(T):
      w += T
      for j in range(i+1,len(S)):
        w += S[j]
      break
  else:
    for k in range(ind, 0 , -1):
      w += S[i-k]
    ind = 0
    w += S[i]
if ind < len(T):
  print("UNRESTORABLE")
else:
  print(w)
  for i in range(len(w)):
    if w[i] == "?":
      ans = w.replace("?", "a")
  print(ans)   

### FIXED CODE ###

def main():
    s = input()
    t = input()
    T = len(t)
    candidate = []
    for i in range(len(s)-T+1):
        buf = s[i:i+T]
        flag = True
        for b, tc in zip(buf, t):
            if b == "?" or b == tc:
                continue
            else:
                flag = False
                break
        if flag == True:
            candidate.append(i)
    if len(candidate) == 0:
        print("UNRESTORABLE")
    else:
        print((s[:candidate[-1]] + t + s[candidate[-1]+T:]).replace("?", "a"))
if __name__ == '__main__':
    main()
a, b, c, k =map(int, input().split())
if k <= a:
    print (a)
elif k > a:
    if k <= (a + b):
        print(a) 
    elif k > (a + b):
        print(a - (k - (a + b))

### FIXED CODE ###

a, b, c, k =map(int, input().split())
if k <= a:
    print (k)
elif k > a:
    if k <= (a + b):
        print(a) 
    elif k > (a + b):
        print(a - (k - (a + b)))