#include using namespace std; using int64 = long long; int main() { int N, A[100]; cin >> N; for(int i = 0; i < N - 1; i++) { cin >> A[i]; } int sum = 0; int64 ret = 0; for(int i = 0; i < N; i++) { int x, y; cin >> x >> y; sum -= x; sum += y; ret += 1LL * A[i] * sum; } cout << ret << endl; }