import
java.util.*;
class
GFG
{
static
void
Print(Vector<Integer> ans)
{
for
(Integer i : ans)
System.out.print(i +
" "
);
}
static
void
Permutation(
int
a[],
int
n)
{
int
flag =
0
, pos =
0
;
Vector<Integer> ans =
new
Vector<Integer>();
Arrays.sort(a);
for
(
int
i =
2
; i < n; i++)
{
if
(a[i] != a[i -
1
] + __gcd(a[i -
1
],
a[i -
2
]))
{
flag =
1
;
pos = i;
break
;
}
}
if
(flag ==
0
)
{
if
(a[
1
] == a[
0
] + __gcd(a[
0
],
a[n -
1
]))
{
ans.add(a[n -
1
]);
for
(
int
i =
0
; i < n -
1
; i++)
ans.add(a[i]);
Print(ans);
return
;
}
else
{
for
(
int
i =
0
; i < n; i++)
ans.add(a[i]);
Print(ans);
return
;
}
}
else
{
if
(a[
1
] == a[
0
] + __gcd(a[pos], a[
0
]))
{
flag =
0
;
for
(
int
i = n -
1
; i > pos +
2
; i--)
{
if
(a[i] != a[i -
1
] + __gcd(a[i -
1
],
a[i -
2
]))
{
flag =
1
;
break
;
}
}
if
(flag ==
0
& pos < n -
1
)
{
if
(a[pos +
1
]
!= a[pos -
1
] + __gcd(a[pos -
1
],
a[pos -
2
]))
flag =
1
;
}
if
(flag ==
0
& pos < n -
2
)
{
if
(a[pos +
2
]
!= a[pos +
1
] + __gcd(a[pos -
1
],
a[pos +
1
]))
flag =
1
;
}
if
(flag ==
0
)
{
ans.add(a[pos]);
for
(
int
i =
0
; i < n; i++)
if
(i != pos)
ans.add(a[i]);
Print(ans);
return
;
}
}
}
ans.add(-
1
);
Print(ans);
}
static
int
__gcd(
int
a,
int
b)
{
if
(b ==
0
)
return
a;
return
__gcd(b, a % b);
}
public
static
void
main(String[] args)
{
int
a[] = {
4
,
6
,
2
,
8
,
8
};
int
n = a.length;
Permutation(a, n);
}
}