#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for(int i=0; i=b; --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector VI; typedef vector VL; typedef vector VVL; typedef vector VVI; typedef pair P; typedef pair PL; int main() { int n; cin >> n; n--; VI a(n); REP(i,n) cin >> a[i]; int ans = 0, x = 0; REP(i,n+1){ int b, c; cin >> b >> c; x += c - b; if (i < n) ans += x * a[i]; } cout << ans << endl; return 0; }