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