uses
  Math, SysUtils;

  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
  f: TextFile;
  a: array of Integer;
  i, j, g, N, a0: Integer;
begin
  Assign(f, 'input.txt'); Reset(f);
  Read(f, N);
  SetLength(a, N);
  for i := 0 to High(a) do Read(f, a[i]);
  CloseFile(f);

  a0 := a[0]; g := 0;
  for i := 2 to a[0] do begin
    if a0 mod i <> 0 then continue;
    while a0 mod i = 0 do a0 := a0 div i;
    g := 0;
    for j := 1 to High(a) do begin
      if a[j] mod i <> 0 then
        g := GCD(g, a[j]);
    end;
    if g <> 1 then break;
  end;

  Assign(f, 'output.txt'); Rewrite(f);
  case g of
  0:  begin
    Writeln(f, a[0], ' 0');
    for j := 1 to High(a) do Write(f, a[j], ' ');
  end;
  1: Writeln(f, -1);
  else begin
    for j := 0 to High(a) do
      if a[j] mod i = 0 then Write(f, a[j], ' ');
    Writeln(f, 0);
    for j := 0 to High(a) do
      if a[j] mod i <> 0 then Write(f, a[j], ' ');
  end;
  end;
  CloseFile(f);
end.
