#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define Vector2 pair <int, int>
#define print(a) for (const auto& x : a) cout << x << ' ';

void solve()
{
	int n;
	cin >> n;
	vector <int> a(n), b(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i];
	}
	vector <int> p(n);
	for (auto& x : p) {
		cin >> x;
	}
	int ans = LLONG_MIN;
	for (int k = 0; k <= n; ++k) {
		int res = 0;
		for (int i = 0; i < k; ++i) {
			if (b[i] <= 0) {
				res += a[i];
			} else {
				res += a[i] + i * b[i];
			}
		}
		ans = max(res, ans);
	}
	cout << ans << '\n';
}

signed main()
{
	cin.tie(nullptr)->ios_base::sync_with_stdio(false);
	solve();
	return 0;
}