#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#pragma GCC optimize("O3" , "Ofast" , "unroll-loops" , "fast-math")

#define endl '\n'
#define X first
#define Y second
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector <ll> vi;
typedef vector <long long> vll;
typedef vector <unsigned long long> vull;
typedef vector <string> vs;
typedef pair <ll, ll> pii;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

const ll maxn = 5e3 + 7;
ll n;
ll a[maxn];
ll b[maxn];
ll p[maxn];
ll dp[maxn][maxn];

void read_solve()
{
    cin >> n;
    for(ll i = 1;i <= n;i++)
    {
        cin >> a[i] >> b[i];
    }
    for(ll i = 1;i <= n;i++)
    {
        cin >> p[i];
    }
    dp[1][0] = a[1];
    for(ll i = 2;i <= n;i++)
    {
        for(ll j = 0;j <= n;j++)
        {
            for(ll z = 0;z <= n;z++)
            {
                if(j - z >= i)continue;
                dp[i][j] = max(dp[i - 1][z] + a[i] + b[i] * (j - z), (ll)dp[i][j]);
            }
        }
    }
    ll ans = 0;
    for(ll i = 1;i <= n;i++)
    {
        for(ll j = 0;j <= n;j++)
        {
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans << endl;
}

int main()
{
    speed();
    read_solve();
    return 0;
}
