#include using namespace std; using ll = long long; using vi = vector; using vvi = vector; using vvvi = vector; using vll = vector; using vvll = vector; using vvvll = vector; using vs = vector; using pll = pair; using vp = vector; #define rep(i, n) for(ll i = 0; i < (n); i++) #define repr(i, a, b) for(ll i = (a); i < (b); i++) #define ALL(a) (a).begin(), (a).end() #define SZ(x) ((ll)(x).size()) const ll MOD = 1000000007; const ll INF = 100000000000000000LL; inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; } inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; } inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; } inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; } templatebool chmax(T &a, const T &b){ if(abool chmin(T &a, const T &b){ if(b> x >> y >> z; char s1, s2; ll t1, t2; cin >> s1 >> t1 >> s2 >> t2; if(s1 == s2){ if(t1 > t2) swap(t1, t2); ll r1 = x, r2 = y, r3 = z; if(s1 == 'B') swap(r1, r2); if(s1 == 'C') swap(r1, r3); cout << min({t2-t1, t1+r3+r1-t2, t1+r3+r1-t2}) << endl; }else{ ll r1 = x, r2 = y, r3 = z; if(s1 == 'A'){ if(s2 == 'C') swap(r2, r3); } if(s1 == 'B'){ swap(r1, r2); if(s2 == 'C') swap(r2, r3); } if(s1 == 'C'){ swap(r1, r3); if(s2 == 'A') swap(r2, r3); } dump(t1+t2-1, r1-t1+r2-t2+1, t1+r3+r2-t2, r1-t1+r3+t2); cout << min({t1+t2-1, r1-t1+r2-t2+1, t1+r3+r2-t2, r1-t1+r3+t2}) << endl; } return 0; }