N = gets.to_i A = (N-1).times.map{ gets.to_i } BC = $<.map{|s| s.split.map &:to_i } _, curr = BC.shift ans = 0 BC.each_with_index{|(b,c), i| ans += curr * A[i] curr += c - b } p ans