#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; vector a(n - 1), b(n), c(n); rep(i, n - 1) cin >> a[i]; rep(i, n) cin >> b[i] >> c[i]; ll ans = 0; int now = c[0]; rep(i, n - 1) { ans += a[i] * now; now += c[i + 1] - b[i + 1]; } cout << ans << '\n'; return 0; }