#include #include #include #include using namespace std; int n, a[100009], b[100009], c[100009]; int main() { cin >> n; for (int i = 0; i < n - 1; i++) cin >> a[i]; long long sum = 0, ret = 0; for (int i = 0; i < n - 1; i++) { cin >> b[i] >> c[i]; sum += b[i] - c[i]; ret += a[i] * sum; } cout << -ret << endl; return 0; }