#include "bits/stdc++.h" #define in std::cin #define out std::cout #define rep(i,N) for(LL i=0;i> x >> y >> z >> S0 >> t0 >> S1 >> t1; if (S0 > S1) { std::swap(S0, S1); std::swap(t0, t1); } LL ans = 1145148101919364; if (S0 == 'A' && S1 == 'A') { LL res1 = std::abs(t0 - t1); LL res2 = t0 + (y - 1) + (x - t1) + 1; LL res3 = t1 + (y - 1) + (x - t0) + 1; LL res4 = t0 + (z - 1) + (x - t1) + 1; LL res5 = t1 + (z - 1) + (x - t0) + 1; ans = std::min({ res1,res2,res3,res4,res5 }); } if (S0 == 'A' && S1 == 'B') { LL res1 = t0 + (t1 - 1); LL res2 = (x - t0) + (y - t1) + 1; LL res3 = t0 + (z - 1) + (y - t1) + 1; LL res4 = (x - t0) + 1 + z + (t1 - 1); ans = std::min({ res1,res2,res3,res4 }); } if (S0 == 'A' && S1 == 'C') { LL res1 = t0 + (t1 - 1); LL res2 = (x - t0) + 1 + (z - t1); LL res3 = t0 + y + (z - t1); LL res4 = (x - t0) + 1 + y + (t1 - 1); ans = std::min({ res1,res2,res3,res4 }); } if (S0 == 'B' && S1 == 'B') { LL res1 = std::abs(t0 - t1); LL res2 = t0 + (x - 1) + (y - t1) + 1; LL res3 = t1 + (x - 1) + (y - t0) + 1; LL res4 = t0 + (z - 1) + (y - t1) + 1; LL res5 = t1 + (z - 1) + (y - t0) + 1; ans = std::min({ res1,res2,res3,res4,res5 }); } if (S0 == 'B' && S1 == 'C') { LL res1 = t0 + (t1 - 1); LL res2 = (y - t0) + (z - t1) + 1; LL res3 = t0 + (x - 1) + (z - t1) + 1; LL res4 = (y - t0) + 1 + x + (t1 - 1); ans = std::min({ res1,res2,res3,res4 }); } if (S0 == 'C' && S1 == 'C') { LL res1 = std::abs(t0 - t1); LL res2 = t0 + (y - 1) + (z - t1) + 1; LL res3 = t1 + (y - 1) + (z - t0) + 1; LL res4 = t0 + (x - 1) + (z - t1) + 1; LL res5 = t1 + (x - 1) + (z - t0) + 1; ans = std::min({ res1,res2,res3,res4,res5 }); } out << ans << std::endl; }