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