import
java.util.*;
class
GFG {
static
int
productOfDigit(
int
n)
{
int
product =
1
;
while
(n >
0
) {
product *= n %
10
;
n /=
10
;
}
return
product;
}
static
void
sortArr(
int
[] arr,
int
n)
{
ArrayList<ArrayList<Integer> > vp
=
new
ArrayList<ArrayList<Integer> >();
for
(
int
i =
0
; i < n; i++) {
vp.add(
new
ArrayList<Integer>());
}
for
(
int
i =
0
; i < n; i++) {
ArrayList<Integer> l1 = vp.get(i);
l1.add(productOfDigit(arr[i]));
l1.add(arr[i]);
vp.set(i, l1);
}
Collections.sort(
vp,
new
Comparator<ArrayList<Integer> >() {
public
int
compare(ArrayList<Integer> o1,
ArrayList<Integer> o2)
{
if
(o1.get(
0
) != o2.get(
0
))
return
o1.get(
0
).compareTo(
o2.get(
0
));
return
o1.get(
1
).compareTo(o2.get(
1
));
}
});
for
(
int
i =
0
; i < n; i++)
System.out.print(vp.get(i).get(
1
) +
" "
);
}
public
static
void
main(String[] args)
{
int
[] arr = {
12
,
10
,
102
,
31
,
15
};
int
n = arr.length;
sortArr(arr, n);
}
}