$n=<>;map{$\=$\*$_%(1e9+7)for~$b&($b=$_)?0:1..0+$n-($n=`dc -e2o$_\p`=~y/1//)}sort{0;$b<=>$a}$\++,glob<>;print