#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

const long long MAX = (5e3) + 5;

long long a[MAX], b[MAX], p[MAX], dp[MAX][MAX], n;

void Solve()
{
    cin >> n;
    for (long long i = 1; i <= n; i++)
        cin >> a[i] >> b[i];
    for (long long i = 1; i <= n; i++)
        cin >> p[i];

    dp[1][0] = a[1];
    long long ans = max(a[1], 1LL * 0);
    for (long long i = 2; i <= n; i++)
    {
        for (long long j = 0; j < i; j++)
        {
            dp[i][j] = dp[i - 1][min(i - 2, j)] + a[i] + j * b[i];
            if (j > 1)
                dp[i][j] = max(dp[i][j], dp[i][j - 1]);
        }
        ans = max(ans, dp[i][i - 1]);
    }
    cout << ans << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    Solve();
    return 0;
}