#S = str(input())

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



if A <= K:

    a = A

else:

    a = K



if B <= K-a:

    b = B

else:

    b = K-a



c = K - a - b



ans = a - c

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





xa = min(k,a)

xb = min(k-xa,b)

xc = k- xa - xb



print((xa - xc))

# S = str(input())
A, B, C, K = list(map(int, input().split()))
if A <= K:
    a = A
else:
    a = K
if B <= K - a:
    b = B
else:
    b = K - a
c = K - a - b
ans = a - c
print(ans)

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

-# S = str(input()) -A, B, C, K = list(map(int, input().split())) -if A <= K: -    a = A -else: -    a = K -if B <= K - a: -    b = B -else: -    b = K - a -c = K - a - b -ans = a - c -print(ans) +a, b, c, k = list(map(int, input().split())) +xa = min(k, a) +xb = min(k - xa, b) +xc = k - xa - xb +print((xa - xc))