($P1,$P2,$N,@R)=<>; $\+=$_[$_]++&&$P1+$P2 for@R; print