{$apptype console}
// ACM 2009
// Problem G
// (C) Chistyakov T. S.
var
  simple: array of integer;

procedure genSimple;
var
  n, i, j: integer;
  isSimple: boolean;
begin
  setlength(simple, 1229);
  n := 0;
  for i := 2 to 10000 do begin
    isSimple := true;
    for j := 0 to n - 1 do
      if i mod simple[j] = 0 then begin
        isSimple := false;
        break;
      end;
    if isSimple then begin
      simple[n] := i;
      Inc(n);
    end;
  end;
end;

function nod(a, b: integer): integer;
begin
  if a = 0 then 
    Result := b
  else if b = 0 then 
    Result := a
  else if a < b then
    Result := nod(a, b mod a)
  else 
    Result := nod(b, a mod b);
end;

var 
  fi, fo: textfile;
  n: integer;
  a: array of integer;
  b: array of boolean;
  i, j, ii, t: integer;
  all: boolean;
  d: integer;
begin
  assignfile(fi, 'input.txt'); reset(fi);
  assignfile(fo, 'output.txt'); rewrite(fo);

  genSimple;
  read(fi, n);
  setlength(a, n);
  for i := 0 to n - 1 do begin
    read(fi, a[i]);
    t := a[i];
    for j := 0 to High(simple) do
      while t mod simple[j] = 0 do
        t := t div simple[j];
    if t > 1 then begin
      SetLength(simple, Length(simple) + 1);
      simple[High(simple)] := t;
    end;
  end;

  SetLength(b, Length(simple));
  for i := 0 to High(b) do
    b[i] := false;
  for i := 0 to High(b) do
    for j := 0 to n - 1 do
      if a[j] mod simple[i] = 0 then begin
        b[i] := true;
        break;
      end;
  j := 0;
  for i := 0 to High(simple) do
    if not b[i] then
      Inc(j)
    else
      simple[i - j] := simple[i];
  SetLength(simple, Length(simple) - j);

  all := false;
  ii := -1;
  for i := 0 to High(simple) do begin
    d := -1;
    for j := 0 to n - 1 do
      if a[j] mod simple[i] <> 0 then begin
        if d = -1 then
          d := a[j]
        else
          d := nod(d, a[j]);
      end;
    if d = -1 then begin
      all := true;
      break;
    end;
    if d > 1 then begin
      ii := i;
      break;
    end;
  end;

  if all then begin
    for i := 0 to n - 2 do
      write(fo, a[i], ' ');
    write(fo, 0, ' ', a[n - 1]);
  end
  else if ii <> -1 then begin
    for i := 0 to n - 1 do
      if a[i] mod simple[ii] = 0 then
        write(fo, a[i], ' ');
    write(fo, 0);
    for i := 0 to n - 1 do
      if a[i] mod simple[ii] <> 0 then
        write(fo, ' ', a[i]);
  end
  else
    write(fo, -1);

  closefile(fi);
  closefile(fo);
end.