local A, B, C, K = io.read("*n", "*n", "*n", "*n")

local K_rem = K
local function add(card, card_num)
	if card < K_rem then
		K_rem = K_rem - card
		return card * card_num
	else
		local val = K_rem * card_num
		K_rem = 0
		return val
	end
end

local result = add(A, 1)
result = result + add(B, 0)
result = result + add(C, -1)

print(result)