sub f{my$_=pop;/\pL/?-55+ord:$_} <>; for(<>){ $x=0; for(@@=/./g){ ($x*=1+f sort@@)+=f$_ } !$y|$x<$y and$y=$x } print$y