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