#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a[100], b[100], c[100], e = 0, f = 1000;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cin >> b[i];
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < n; i++) {
    e = e + b[a[i]];
    if (a[i] - 1 == f) e = e + c[i - 1];
    f = a[i];
  }
  cout << e << endl;
  return (0);
}
