#include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int as[100]; int a; for (int i = 0; i < n - 1; ++i) { cin >> a; as[i] = a; } as[n-1] = 0; int b, c; int bs[100]; int cs[100]; for (int j = 0; j < n; ++j) { cin >> b >> c; bs[j] = b; cs[j] = c; } int m[101]; m[0] = 0; for (int k = 1; k <= n; ++k) { m[k] = m[k - 1] - bs[k - 1] + cs[k - 1]; } int result = 0; for (int l = 1; l <= n; ++l) { result += m[l] * as[l - 1]; } cout << result << "\n"; }