program bs;
var
counto,countx,maxo,maxx,ans,temp:longint;
begin
assign(input,'bs.in');
assign(output,'bs.out');
reset(input);
rewrite(output);
while not eof do
begin
readln(counto,countx,maxo,maxx);
if (maxo=0)and(maxx=0) then writeln(0);
if (maxo=0)and(maxx<>0) then
if maxx<countx then writeln(maxx) else writeln(countx);
if (maxo<>0)and(maxx=0) then
if maxo<counto then writeln(maxo) else writeln(counto);
if (maxo<>0)and(maxx<>0) then begin
if counto>countx then begin
temp:=countx+1;
ans:=countx*2;
counto:=counto-countx;
if counto>0 then begin
counto:=counto-1;
ans:=ans+1;
end;
if maxo>1 then if counto/(maxo-1)<=temp then ans:=ans+counto else ans:=ans+temp*(maxo-1);
end
else begin
temp:=counto+1;
ans:=counto*2;
countx:=countx-counto;
if countx>0 then begin
countx:=countx-1;
ans:=ans+1;
end;
if maxx>1 then if countx/(maxx-1)<=temp then ans:=ans+countx else ans:=ans+temp*(maxx-1);
end;
writeln(ans);
end;
end;
close(input);
close(output);
end.