#include #include void solve() { int n; std::cin >> n; std::vector xs(n - 1); for (auto& x : xs) std::cin >> x; int ans = 0, k = 0; for (auto x : xs) { int b, c; std::cin >> b >> c; k += c - b; ans += k * x; } std::cout << ans << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }