typedef long long ll; #include using namespace std; int main() { vector dis(3); for (int i = 0; i < 3; i++) { std::cin >> dis[i]; } pair start,end; char t1,t2; ll tt1,tt2; std::cin >> t1>>tt1; std::cin >> t2>>tt2; start = {t1-'A',tt1}; end = {t2-'A',tt2}; if(start.first==end.first){ std::cout << min({ abs(start.second-end.second), min(start.second,dis[start.first]-start.second)+ min(end.second,dis[end.first]-end.second)+ min(dis[(start.first+1)%3],dis[(start.first+2)%3]), start.second+dis[start.first]-end.second+ min(dis[(start.first+1)%3],dis[(start.first+2)%3]) }) << std::endl; }else{ std::cout << min({ start.second+ end.second-1, dis[start.first]-start.second+1+ dis[end.first]-end.second, start.second+ dis[3-start.first-end.first]+ dis[end.first]-end.second, dis[start.first]-start.second+ dis[3-start.first-end.first]+ end.second }) << std::endl; } }