Program CountOblong;
Var a,b,c,d:LongInt;
Function Smaller(X,Y:LongInt):LongInt;
begin
if X>Y then
Smaller:=Y
else
Smaller:=X;
end;
Function Bigger(X,Y:LongInt):LongInt;
begin
if X>Y then
Bigger:=X
else
Bigger:=Y;
end;
Function GetOblong(W1,H1,W2,h2:LongInt):LongInt;
Var Ans,Temp:LongInt;
begin
Ans:=0;
if (W1>=W2) and (H1>=H2) then
begin
Ans:=1+GetOblong(Smaller(W1-W2,H1-H2),Bigger(W1-W2,H1-H2),W2,H2)+
GetOblong(Smaller(w1-w2,h1),Bigger(W1-w2,h1),w2,h2);
temp:=1+GetOblong(Smaller(w1-w2,h1-h2),Bigger(w1-w2,h1-h2),w2,h2)+
GetOblong(Smaller(w1,h1-h2),Bigger(w1,h1-h2),w2,h2);
if temp>Ans then
Ans:=temp;
end;
if (W1>=H2) and (h1>=w2) then
begin
temp:=1+GetOblong(Smaller(W1-h2,H1-w2),Bigger(W1-h2,H1-w2),W2,H2)+
GetOblong(Smaller(w1-h2,h1),Bigger(W1-h2,h1),w2,h2);
if temp>Ans then
Ans:=temp;
temp:=1+GetOblong(Smaller(w1-h2,h1-w2),Bigger(w1-h2,h1-w2),w2,h2)+
GetOblong(Smaller(w1,h1-w2),Bigger(w1,h1-w2),w2,h2);
if temp>Ans then
Ans:=temp;
end;
GetOblong:=Ans;
end;
begin
Writeln('Input the Width and Height of the two oblongs:');
readln(a,b,c,d);
Writeln(GetOblong(Smaller(a,b),Bigger(a,b),Smaller(c,d),Bigger(c,d)));
end.