$n=<>; $_=<>;chop; $q=int sqrt y/Q//; print !/H/ && $q && ($c=substr$_,0,$n/$q) x $q eq $_ ? $c : -1;