#include<iostream>
#include<random>
#pragma GCC optimize("Ofast")
using namespace std;

using ll = long long;
using ld = long double;

const ll infl = (ll)4e18 + 100;
const ll infi = (ll)1e9 + 100;
const ll maxn = (ll)1e6 + 10;
const ll mod = (ll)1e9 + 7;

ll n;
ll a[maxn], b[maxn];
ll p[maxn], t[maxn];

mt19937 mt(525252);
inline ll gen(ll l, ll r) {
    // cout << l << " " << r << '\n';
    if (r - l + 1 == 0) return 0;
    return l + mt() % (r - l + 1);
}

inline void 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];

    ll ans = 0;
    for (ll it = 0; it <= 10000; ++it) {
        for (ll k = 0; k <= n; ++k) {
            bool f = true;

            for (ll i = 1; i <= k; ++i) {
                t[i] = gen(t[i - 1], k - 1);
                if (t[i] < t[i - 1]) {
                    f = false;
                    break;
                }
            }

            if (f) {
                ll nw = 0;
                for (ll i = 1; i <= k; ++i)
                    nw += a[i] + t[i] * b[i];

                ans = max(ans, nw);
            }
        }
    }

    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll t_ = 1; // cin >> t_;
    while (t_--) {
        solve();
        cout << '\n';
    }

    return 0;
}