#include <iostream>
using namespace std;
int main(){
int tmp=0,no=0;
int a1,a2,a3;
int b1,b2,b3,b4,b5;
int c1,c2,c3,c4,c5;
cin>>a1>>a2>>a3;
cin>>b1>>b2>>b3>>b4>>b5;
cin>>c1>>c2>>c3>>c4>>c5;
if(a1==b1||a2==b1){
tmp+=c1;
}
if(a1==b2||a2==b2){
tmp+=c2;
}
if(a1==b3||a2==b3){
tmp+=c3;
}
if(a1==b4||a2==b4){
tmp+=c4;
}
if(a1==b5||a2==b5){
tmp+=c5;
}
if(a3==b1){
tmp-=c1;
no++;
}
if(a3==b2){
tmp-=c2;
no++;
}
if(a3==b3){
tmp-=c3;
no++;
}
if(a3==b4){
tmp-=c4;
no++;
}
if(a3==b5){
tmp-=c5;
no++;
}
if(tmp<0){
cout<<"0"<<endl;
}
else if(no==0){
cout<<tmp*2<<endl;
}
else{
cout<<tmp<<endl;
}
}