#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <numeric>

#define LOCAL
#ifdef LOCAL
#else
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#endif

void Solve() {
    int n;
    std::cin >> n;
    std::vector<std::pair<long long, long long>> vec(n);

    for (int i = 0; i < n; ++i) {
        std::cin >> vec[i].first >> vec[i].second;
    }

    std::vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> p[i];
    }

    std::vector<std::vector<long long>> dp(n, std::vector<long long>(n, -1e18));
    std::vector<std::vector<long long>> pref_max(n, std::vector<long long>(n + 1, -1e18));

    long long max = vec[0].first;
    dp[0][0] = vec[0].first;
    for (int i = 0; i <= n; ++i) {
        pref_max[0][i] = dp[0][0];
    }

    for (int i = 1; i < n; ++i) {
        for (long long j = 0; j <= i; ++j) {
            dp[i][j] = vec[i].first + vec[i].second * j + pref_max[i - 1][j + 1];
            pref_max[i][j + 1] = std::max(pref_max[i][j], dp[i][j]);

            max = std::max(max, dp[i][j]);
        }
        for (int j = i + 1; j <= i + 1; ++j) {
            pref_max[i][j + 1] = pref_max[i][j];
        }
    }

    std::cout << max << '\n';
}

int main() {
    #ifdef LOCAL
        std::cout << '\n';
    #else
        std::ios_base::sync_with_stdio(false);
        std::cin.tie(nullptr);
    #endif

    int t = 1;
    //std::cin >> t;

    for (int i = 0; i < t; ++i) {
        Solve();
    }
}