$N=<>; @A=map{($s+=<>)%=1e9+7}0..$N; ($x+=$_*pop@A)%=1e9+7for<>; print$x