<>;@a=<>;map{$\=-$\;$\+=$_*$p,/ /,$p=$_="$' $`"for@a,"@a",$"}0,0;print