#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define len(x) (int)x.size()
#define start auto st = clock()
#define finish auto fin = clock(); cerr << 1000 * (fin - st) / (ld)CLOCKS_PER_SEC << endl
const ll mod2 = 998244353;

using namespace std;

void print(vector<int> &a) {
    for (auto x : a) cout << x << ' ';
    cout << '\n';
}

void print(vector<ll> &a) {
    for (auto x : a) cout << x << ' ';
    cout << '\n';
}

// #define mtask
// #define int ll

void solve() {
    int n;
    cin >> n;
    vector<pair<ll, ll>> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first >> a[i].second;
    }
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    vector<ll> dp(n + 1);
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= i; ++j) {
            dp[j] += a[i].first + a[i].second * j;
        }
        for (int j = 1; j <= i; ++j) {
            dp[j] = max(dp[j], dp[j - 1]);
        }
        for (int j = i + 1; j <= n; ++j) {
            dp[j] = dp[j - 1];
        }
        ans = max(ans, dp[n]);
        // print(dp);
    }
    cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
#ifdef mtask
    int t;
    cin >> t;
    while (t--)
#endif
        solve();
}