//#define NDEBUG
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using ll = long long;

using std::vector;
using std::make_pair;
using std::pair;

constexpr int MOD = 998244353;

constexpr ll INF = 1e18;
void solve() {
    int n;
    std::cin >> n;
    std::vector<ll> a(n), b(n);
    for (int i = 0;  i <n; ++i) {
        std::cin >> a[i] >> b[i];
    }
    std::vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> p[i];
    }
    std::vector<std::vector<ll>> dp(n, std::vector<ll>(n, -INF));
    dp[0][0] = a[0];
    for (int tmm = 0; tmm < n; ++tmm) {
        dp[0][tmm] = a[0];
    }
    for (int i = 1; i < n; ++i) {
        ll mx = -INF;
        for (int tmm = 0; tmm <= i; ++tmm) {
            mx = std::max(mx, a[i] + b[i] * tmm);
            dp[i][tmm] = mx + dp[i - 1][tmm];
        }
        for (int tmm = i + 1; tmm < n; ++tmm) {
            dp[i][tmm] = dp[i][i];
        }
    }
    ll res = -INF;
    for (int i = 0; i < n; ++i) {
        res = std::max(res, dp[i][i]);
    }
    std::cout << res << '\n';
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
}

