#include <iostream>
#include <random>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

int main() {
	int n; cin >> n;
	vector<long long> a(n), b(n);
	vector<int> p(n), ans(n, -1);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	long long sum = 0;
	stack<pair<int, long long>> st;
	for (int i = 0; i < n; i++) {
		if (b[i] > 0) {
			st.push(make_pair(i, sum));
			ans[i] = i;
			sum += b[i];
		}
		else {
			sum += b[i];
			while (st.size() && sum - st.top().second < 0) {
				ans[st.top().first] = -1;
				st.pop();
			}
		}
	}
	int last = 0;
	long long res = 0; sum = 0;
	for (int i = 0; i < n; i++) {
		last = max(last, ans[i]);
		sum += a[i] + (b[i] * last);
		res = max(res, sum);
	}
	cout << res;
}
