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