#include <bits/stdc++.h>
int main() {
  int ANS = 0;
  int N;
  int BSUM = 0, CSUM = 0;
  int A[21];
  int B[21];
  int C[21];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &B[i]);
    BSUM = BSUM + B[i];
  }
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  for (int i = 0; i < N - 1; i++) {
    if (A[i] == A[i + 1] - 1) {
      CSUM = CSUM + C[i];
    }
  }
  ANS = BSUM - CSUM;
  printf("%d", ANS);
  return 0;
}
