$n=<>;@a=glob<>; open(t,">/tmp/t"); sub f{ my($x,$u)=@_; if(!$h{$x}++){ if(!$u){ print t $x,$/; }else{ for$i(0..$n-1){ if($u&1<<$i){ my$y=$a[$i]; f($x.$y,$u^1<<$i); } } } } } f('',(1<<$n)-1); open(p,"sort -nr /tmp/t|factor|"); ($r)=(grep(!/\d /,
),-1); print $r+0;