sub f{my$_=pop;-48-7*/\pL/+ord}<>;printf sort{$a<=>$b}map{$x=0;($x*=1+f sort@@)+=f$_ for@@=/./g;$x}<>