

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

sum = 0

if A <= K:

    K -= A

    sum += 1 * A

elif K > 0:

    sum += 1 * K

    K = 0

if B <= K:

    K -= B

elif K > 0:

    K = 0

if C <= K:

    K -= C

    sum -= 1 * C

elif K > 0:

    sum -= 1 * K

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



if k <= a:

    print(k)

elif k <= a + b:

    print(a)

else:

    print((a - (k - (a + b))))

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

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

-A, B, C, K = list(map(int, input().split())) -sum = 0 -if A <= K: -    K -= A -    sum += 1 * A -elif K > 0: -    sum += 1 * K -    K = 0 -if B <= K: -    K -= B -elif K > 0: -    K = 0 -if C <= K: -    K -= C -    sum -= 1 * C -elif K > 0: -    sum -= 1 * K -print(sum) +a, b, c, k = list(map(int, input().split())) +if k <= a: +    print(k) +elif k <= a + b: +    print(a) +else: +    print((a - (k - (a + b))))