N = gets.to_i A = (N - 1).times.map { gets.to_i } Q = N.times.map { gets.split.map(&:to_i) } ans = 0 cur = 0 Q.each.with_index do |(b, c), i| ans += cur * A[i - 1] if i > 0 cur += (c - b) end puts ans