x = $<.lines.map{|l|l.split.map(&:to_i)}.flatten _,_,_,a,b,c,d,e,f,g,h,i = x.map.with_index{|e,i|e-x[i%3]} p (a*e*i+b*f*g+c*d*h-a*f*h-b*d*i-c*e*g)/6