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



sum=0



if A>K:

    sum += K

    K = 0

else:

    sum += A

    K = K-A



if B>K:

    K = 0

else:

    K = K-B



if C>K:

    sum -= K

    K = 0

else:

    sum -= C

    K = K-C



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



sum = 0



X_a = min(A,K)

sum += X_a

K -= X_a



X_b = min(B,K)

K -= X_b



X_c = min(C,K)

sum -= X_c



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

A, B, C, K = list(map(int, input().split()))
sum = 0
X_a = min(A, K)
sum += X_a
K -= X_a
X_b = min(B, K)
K -= X_b
X_c = min(C, K)
sum -= X_c
print(sum)

-if A > K: -    sum += K -    K = 0 -else: -    sum += A -    K = K - A -if B > K: -    K = 0 -else: -    K = K - B -if C > K: -    sum -= K -    K = 0 -else: -    sum -= C -    K = K - C +X_a = min(A, K) +sum += X_a +K -= X_a +X_b = min(B, K) +K -= X_b +X_c = min(C, K) +sum -= X_c