{
TASK:phrope
LANG:PASCAL
}

var
  a,b: Int64;
  x,y,c: Int64;
  fl,fl2: Boolean;
  br,br2: Int64;


procedure scan(p,q,k: Int64);
var
  i: Int64;

begin
  if (p=0) or (q=0) and (not fl) then
  begin
    fl:= true;
    br:= k;
  end
  else
  begin
    i:= 1;
    while (i<=p) and (2*i<=q) and (not fl) do
    begin
      scan(p-i,q-2*i,k+1);
      i:= i+1;
    end;
    i:= 1;
    while (i<=q) and (2*i<=p) and (not fl) do
    begin
      scan(p-2*i,q-i,k+1);
      i:= i+1;
    end;
  end;
end;


begin
  readln(a,b); c:= 1; fl:= false; x:= 0; y:= 0; fl:= false;
  if b>a then
  begin
    br:= b;
    b:= a;
    a:= br;
    fl2:= true;
  end;
  br:= 0;
  while (c<=a) and (2*c<=b) do
  begin
    fl:= false;
    scan(a-c,b-2*c,1);
    if fl then
    begin
      x:= c;
      y:= 2*c;
    end;
    c:= c+1;
  end;
  br2:= br;
  br:= 0; c:= 1; fl:= false;
  while (c<=b) and (2*c<=a) do
  begin
    fl:= false;
    scan(a-2*c,b-c,1);
    if fl then
    begin
      x:= 2*c;
      y:= c;
    end;
    c:= c+1;
  end;

  if (br mod 2 <> 0) or (br2 mod 2 <> 0) then
  begin
    if not fl2 then
      writeln(x,' ',y);
    if fl2 then
      writeln(y,' ',x);
  end;
  if (br mod 2 = 0) and (br2 mod 2 = 0) then
    writeln('0 0');
end.