#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int64_t n;
    cin >> n;
    vector<int64_t> a(n);
    vector<int64_t> b(n);
    for(int64_t i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    vector<int64_t> p(n);
    for(int64_t i = 0; i < n; ++i) {
        cin >> p[i];
    }
    vector<vector<int64_t>>dp(n,vector<int64_t>(n, -1e9));
    for(int64_t i = 0; i <= n; ++i) {
        dp[0][i] = a[0] + b[0] * i;
    }   
    for(int64_t j = 1; j <= 1; ++j) {
        dp[0][j] = max(dp[0][j], dp[0][j-1]);
    } 
    for(int64_t i = 1; i < n; ++i) {
        for(int64_t j = 0; j <= i + 1; ++j) {                   
            int64_t cur = a[i] + b[i] * j;     
            for(int64_t k = i-1; k >= j- 1; --k) {                
                if(j != 0) {
                    dp[i][j] = max(dp[i][j], dp[k][j - 1] + cur);
                }
                if(j != -1) {
                    cur += a[k] + b[k] * j;
                }
            }            
            if(j == 0) {
                dp[i][j] = max(dp[i][j], cur);
            }
        }
        for(int64_t j = 1; j <=i  +1; ++j) {
            dp[i][j] = max(dp[i][j], dp[i][j-1]);
        }
    }
    int64_t res = 0;
    for(int64_t64_t i = 0; i < n; ++i) {
        res = max(res, dp[i][i + 1]);
    }    
    cout << res << '\n';
    return 0;
}