#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
using ordered_set  = tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

void solve() {
   int n;
   cin >> n;
   vector<int> a(n), b(n);
   for (int i = 0;i < n;i++) cin >> a[i] >> b[i];

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

   bool bmn = 1;
   bool bmx = 1;

   for (auto el : b) if (el > 0) bmn = 0;
   for (auto el : b) if (el < 0) bmx = 0;

//    if (bmn) {

//     vector<int> prefa(n + 1, 0), prefb(n + 1,0);
//     for (int i = 1;i <= n;i++) prefa[i] = prefa[i - 1] + a[i-1];
//     for (int i = 1;i <= n;i++) prefb[i] = prefb[i - 1] + b[i-1];


//     int pri = 0;
//     int prj = 0;
//     int ans = 0;
    

//     for (int i = 0;i < n;i++) {
//         if (p[i] != -1) {
//             ans += prefa[p[i]] - prefa[prj] + pri * (prefb[p[i]] - prefb[prj]);
//             pri = i;
//             prj = p[i];
//         }
//     }

//     int mx = 0;
//     for (int i= prj + 1;i < n;i++) {
//         mx = max(mx, prefa[i]-prefa[prj] + pri * (prefb[i]-prefb[prj]));
//     }
//     cout << ans + mx << '\n';
//     return ;
//    }


   vector<int> dp(n, -1e12);
   dp[0] = a[0];

   for (int i = 1;i < n;i++) dp[i] = dp[i - 1] + a[i];

    for (int i = 1;i < n;i++) {
        for (int j = 0;j < n;j++) {
            if (i <= j) dp[j] = max(dp[j], dp[j - 1] + a[j] + b[j] * i);
        }
    }

    int ans = -1e18;

    for (int i = 0;i < n;i++) {
        ans = max(ans, dp[i]);
    }

    cout << ans << '\n';
}
/*
4
-6 -1
-5 14
0 10 
-30 2
-1 -1 -1 -1
*/
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int t = 1;
    //  cin >> t;
    while (t --> 0) solve();
}
/*
4
3 -6
4 -10
-7 -3


5
1 -2
2 -3
3 -5
10 -1
20 -7
-1 1 2 -1 -1
*/