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



xa = min(a,k)

k -= xa

xb = min(b, k)

k -= xb

xc = k

print((xa-xc))

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

if a+b >= k:

    print((min(a,k)))

else:

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

a, b, c, k = list(map(int, input().split()))
xa = min(a, k)
k -= xa
xb = min(b, k)
k -= xb
xc = k
print((xa - xc))

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

-xa = min(a, k) -k -= xa -xb = min(b, k) -k -= xb -xc = k -print((xa - xc)) +if a + b >= k: +    print((min(a, k))) +else: +    print((a - (k - a - b)))