#include <iostream>
#include<vector>
#include<set>
#include<map>
#include <cmath>
#include <algorithm>

using namespace std;
long long typedef ll;
ll INF = 1e15;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n,a , b;
	cin >> n;
	vector<ll> data, add, p;
	bool checker = true, testb = true;
	for (ll i = 0; i < n; ++i) {
		cin >> a >> b;
		data.push_back(a);
		add.push_back(b);
		if (b > 0) {
			testb = false;
		}
	}
	for (ll i = 0; i < n; ++i) {
		cin >> a;
		if (a != -1) {
			checker = false;
		}
		p.push_back(a);
	}
	vector<vector<ll>> options(n);
	if (testb && checker) {
		ll best = 0, s = 0;
		for (ll i = 0; i < n; ++i) {
			s += data[i];
			best = max(best, s);
		}
		cout << best;
	}
	else if (checker) {
		for (ll i = 0; i < n; ++i) {
			for (ll j = 0; j <= i; ++j) {
				options[i].push_back(data[i] + add[i] * j);
			}
		}
		vector<ll> prev = { 0 }, cur = {};
		ll best = 0, gbest = 0;
		for (ll i = 0; i < n; ++i) {
			best = prev[0];
			for (ll j = 0; j <= i; ++j) {
				cur.push_back(options[i][j] + best);
				gbest = max(gbest, cur.back());
				if (j < i - 1) {
					best = max(best, prev[j + 1]);
				}
			}
			prev = cur;
			cur.clear();
		}
		cout << gbest;
	}
}
