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



if k > a + b:

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

elif k > a:

    print(a)

else:

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

if k <= a+b:

    print((min(k, a)))

else:

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

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

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

-if k > a + b: -    print((a - (k - a - b))) -elif k > a: -    print(a) +if k <= a + b: +    print((min(k, a))) -    print(k) +    print((min(a, (a - (k - (b + a))))))