#include <stdio.h>
int main(){
int n,i,a,b,c,sum=0;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
scanf("%d",&b[i]);
sum+=b[i];
}
for(i=0;i<n-1;i++){
scanf("%d",&c[i]);
}
for(i=0;i<n;i++){
if(a[i]+1==a[i+1]){
sum+=c[i];
}
}
printf("%d",sum);
}