#include using namespace std; typedef long long ll; signed main(){ //cout << setprecision(12) ; ios::sync_with_stdio(false); cin.tie(0); ll x,y,z; cin>>x>>y>>z; string s1,s2; ll t1,t2; cin>>s1>>t1>>s2>>t2; ll ans = 1e18; if(s1==s2){ if(s1=="B") swap(x,y); if(s1=="C") swap(z,x); ans = abs(t2-t1); ll d1 = t1 + min(y,z) + x-t2; ll d2 = x-t1 +1 + min(y,z) + t2-1; ans = min(ans,min(d1,d2)); cout<