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

if a + b >= k:

    ans = min(a,k)

else:

    ans = a - (k-a-b)

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

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

a, b, c, k = list(map(int, input().split()))
print((min(a, k) - max(k - a - b, 0)))

-if a + b >= k: -    ans = min(a, k) -else: -    ans = a - (k - a - b) -print(ans) +print((min(a, k) - max(k - a - b, 0)))