eval"N,*A="+gets(p).split*?, B=A.pop N*2 n=0 p A.map{|a|b,c,*B=B;a*n-=b-c}.sum