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





ans=0



if K <= A:

  ans=K



elif K <= A + B :

  ans=A

else:

  ans= A - (K - A - B)

  

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



if K <= A:print(K)

elif K <= A + B :print(A)

else:print((A*2 + B - K))
A, B, C, K = list(map(int, input().split()))
ans = 0
if K <= A:
    ans = K
elif K <= A + B:
    ans = A
else:
    ans = A - (K - A - B)
print(ans)

A, B, C, K = list(map(int, input().split()))
if K <= A:
    print(K)
elif K <= A + B:
    print(A)
else:
    print((A * 2 + B - K))

-ans = 0 -    ans = K +    print(K) -    ans = A +    print(A) -    ans = A - (K - A - B) -print(ans) +    print((A * 2 + B - K))