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



ans = min(K,A)

K -= A

if K > 0:

    K -= B

if K > 0:

    ans -= K

print(ans)

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

print((min(K,A) - max(0,K-A-B)))



A, B, C, K = list(map(int, input().split()))
ans = min(K, A)
K -= A
if K > 0:
    K -= B
if K > 0:
    ans -= K
print(ans)

A, B, C, K = list(map(int, input().split()))
print((min(K, A) - max(0, K - A - B)))

-ans = min(K, A) -K -= A -if K > 0: -    K -= B -if K > 0: -    ans -= K -print(ans) +print((min(K, A) - max(0, K - A - B)))