program cojs486;
var
i,j,k,m,n:int64;
co,cx,mo,mx:int64;
begin
assign(input,'bs.in');
assign(output,'bs.out');
reset(input);
rewrite(output);
while not eof do
begin
readln(co,cx,mo,mx);
if co<cx then begin k:=co; co:=cx; cx:=k;
k:=mo; mo:=mx; mx:=k; end;
if (mo=0)and(mx=0) then n:=0
else if (mo=0)and(mx>0) then begin n:=mx; if cx<n then n:=cx; end
else if (mo>0)and(mx=0) then begin n:=mo; if co<n then n:=co; end
else
begin
n:=2*cx;
if co-cx>=mo then
begin
n:=n+mo; co:=co-cx-mo; dec(mo);
while (co>=cx)and(mo>0) do
begin
co:=co-cx; dec(mo);
n:=n+cx;
end;
if (co>0)and(mo>0) then
n:=n+co;
end
else n:=n+co-cx;
end;
writeln(n);
end;
close(output);
close(input);
end.