#!perl -nla sub F{$a[pop@F]||=$z=$z*97+1&~0>>9}$a{$h}//=$.;$#F?$h=$h+pop(@F)*(F()-F)&~0>>9:$.-1&&print$a{$h|=0}-2