#include <bits/stdc++.h>
using namespace std;

#define int long long
using ld = long double;

#define all(x) (x).begin(), (x).end()
#define len(x) (int)((x).size())
#define endl '\n'

template<typename T, typename U> bool remin(T& a, const U& b) { return (T)(b) < (a) ? a = (T)(b), 1 : 0; }
template<typename T, typename U> bool remax(T& a, const U& b) { return (a) < (T)(b) ? a = (T)(b), 1 : 0; }
template<typename T> istream& operator>>(istream& in, vector<T>& a) { for (T& x : a) { in >> x; } return in; }
template<typename T> ostream& operator<<(ostream& out, vector<T>& a) { for (T& x : a) { out << x << ' ';  } return out; }

void solve() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (auto& [x, y] : a) cin >> x >> y;
  vector<int> p(n);
  cin >> p;
  vector<vector<int>> dp(n, vector<int>(n * 2, LLONG_MIN));
  dp[0][0] = a[0].first;
  for (int i = 1; i < n; ++i) {
    for (int j = 1; j <= i; ++j) {
      if (dp[i - 1][j - 1] == LLONG_MIN) continue;
      remax(dp[i][j], dp[i - 1][j - 1] + a[i].first + a[i].second * j);
    }
  }
  int ans = LLONG_MIN;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= i; ++j) {
      remax(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
}

int32_t main() {
#ifdef LOCAL
  freopen("C://work//open1//in.txt", "r", stdin);
  freopen("C://work//open1//out.txt", "w", stdout);
#endif
  int test = 1;
  // cinzz >> test;
  while (test--) {
    solve();
  }
return 0;
}