#include using namespace std; #define int long long vector> vec[10]; signed main(){ int x, y, z; cin >> x >> y >> z; int memo[3] = {x, y, z}; pair s, t; cin >> s.first >> s.second; cin >> t.first >> t.second; int si = s.first-'A'; int ti = t.first-'A'; int vi; if(si != 1 && ti != 1) vi = 1; if(si != 2 && ti != 2) vi = 2; if(si != 0 && ti != 0) vi = 0; int a1 = s.second-1 + t.second-1 + 1; int a2 = memo[si] - s.second + memo[ti] - t.second + 1; int a3 = s.second-1 + 1 + memo[vi] + memo[ti]-t.second; int a4 = memo[si]-s.second + 1 + memo[vi] + t.second-1; if(s.first != t.first){ cout << min(a1, min(a2, min(a3, a4))) << endl; }else{ int x, y; x = min(s.second, t.second); y = max(s.second, t.second); int a5 = y-x; int a6, a7, a8; a6 = a7 = a8 = LLONG_MAX; if(si != 0) a6 = memo[si]-y+x-1+1+memo[0]; if(si != 1) a7 = memo[si]-y+x-1+1+memo[1]; if(si != 2) a8 = memo[si]-y+x-1+1+memo[2]; cout << min(a5, min(a6, min(a7, a8))) << endl; } return 0; }