
  function NZPos(const a: array of Integer): Integer;
  begin
    for Result := High(a) downto 0 do
      if a[Result] > 0 then exit;
    Result := -1;
  end;

  function GCD(a, b: Integer): Integer;
  begin
    while (a > 0) and (b > 0) do
      if a > b then a := a mod b else b := b mod a;
    Result := a + b;
  end;

var
  a, b: array of Integer;
  f: TextFile;
  i, N, pa, pb, g: Integer;
begin
  Assign(f, 'input.txt'); Reset(f);
  Read(f, N);
  SetLength(a, N);
  SetLength(b, N);
  for i := 0 to N - 1 do Read(f, a[i]);
  for i := 0 to N - 1 do Read(f, b[i]);
  CloseFile(f);

  pa := NZPos(a);
  pb := NZPos(b);
  Assert(pb >= 0);

  Assign(f, 'output.txt'); Rewrite(f);
  if pa > pb then
    Writeln(f, '1 0')
  else if pb > pa then
    Writeln(f, '0 1')
  else begin
    g := GCD(a[pa], b[pb]);
    Writeln(f, a[pa] div g, ' ', b[pb] div g);
  end;
  CloseFile(f);
end.
