#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector A(N - 1); for (auto &&e : A) { cin >> e; } int res = 0, cur = 0; for (int i = 0; i < N; i++) { int b, c; cin >> b >> c; cur += c; cur -= b; res += cur * A[i]; } cout << res << '\n'; return 0; }