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

ans = 0

while k > 0:

    if a >= k:

        ans += k

        break

    else:

        ans += a

        k -= a

    if b >= k:

        break

    else:

        k -= b

    ans -= k

    break



print(ans)
a,b,c,k =list(map(int, input().split()))



ans = 0

x = min(k , a)

ans += x

k2 = k - x

x2 = min(k2, b)

k3 = k2 - x2

x3 = min(k3, c)

ans -= k3



print(ans)
a, b, c, k = list(map(int, input().split()))
ans = 0
while k > 0:
    if a >= k:
        ans += k
        break
    else:
        ans += a
        k -= a
    if b >= k:
        break
    else:
        k -= b
    ans -= k
    break
print(ans)

a, b, c, k = list(map(int, input().split()))
ans = 0
x = min(k, a)
ans += x
k2 = k - x
x2 = min(k2, b)
k3 = k2 - x2
x3 = min(k3, c)
ans -= k3
print(ans)

-while k > 0: -    if a >= k: -        ans += k -        break -    else: -        ans += a -        k -= a -    if b >= k: -        break -    else: -        k -= b -    ans -= k -    break +x = min(k, a) +ans += x +k2 = k - x +x2 = min(k2, b) +k3 = k2 - x2 +x3 = min(k3, c) +ans -= k3