#include "bits/stdc++.h"

using namespace std;

template<typename T>
istream &operator>>(istream &is, vector<T> &a) {
      for (T &elem: a) is >> elem;
      return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
      for (T elem: a) os << elem << ' ';
      return (os << '\n');
}

#define int long long

signed main() {
#ifdef LOCAL
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
#else
      cin.tie(nullptr);
      ios_base::sync_with_stdio(false);
#endif
      int n;
      cin >> n;
      vector<int> a(n + 1), b(n + 1);
      for (int i = 1; i <= n; ++i) cin >> a[i] >> b[i];

      vector<int> c(n);
      cin >> c;

//      vector<int> maxval(n);
//      std::iota(maxval.begin(), maxval.end(), 0ll);
//      for (int i = 0; i < n; ++i) {
//            for (int j = 0; j < c[i]; ++j) {
//                  maxval[j] = min(maxval[j], i);
//            }
//      }

      vector dp(n + 1, vector<int>(n, -1e18));
      vector p(n + 1, vector<int>(n, -1e18));
      dp[0][0] = 0;
//      dp[0][0] = a[0];
//      p[0][0] = a[0];
      for (int i = 1; i <= n; ++i) {
            p[i - 1][0] = dp[i - 1][0];
            for (int val = 1; val < n; ++val) {
                  p[i - 1][val] = max(p[i - 1][val - 1], dp[i - 1][val]);
            }
            for (int val = 0; val < i; ++val) {
                  dp[i][val] = p[i - 1][val] + a[i] + b[i] * val;
            }
      }

//      cout << dp;
      int res = -1e18;
      for (int i = 0; i < n; ++i) {
            for (int val = 0; val < n; ++val) {
                  res = max(res, dp[i][val]);
            }
      }
      cout << res << '\n';

}