#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int x = 0;
  int s = 0;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N - 1);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    cin >> B.at(i);
  }
  for (int j = 0; j < N - 1; j++) {
    cin >> C.at(j);
  }
  for (int k = 0; k < N; k++) {
    x = A.at(k);
    s += B.at(x - 1);
    if (A.at(k) == x + 1) {
      s += C.at(x);
    }
  }
  cout << s;
}
