#include using namespace std; using ll = long long; #define FOR(i,a,b) for(ll i=(a);i<(b);++i) #define ALL(v) (v).begin(), (v).end() #define p(s) cout<<(s)<> N; vector A(N-1); FOR(i, 0, N-1){ cin >> A.at(i); } ll people = 0; ll sum = 0; FOR(i, 0, N-1){ ll out, ride; cin >> out >> ride; people += ride; people -= out; // cost sum += people * A[i]; } p(sum); return 0; }