#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a vector dijkstra(Int s,vector > > & G){ const T INF = numeric_limits::max(); using P = pair; Int n=G.size(); vector d(n,INF); vector b(n,-1); priority_queue,greater

> q; d[s]=0; q.emplace(d[s],s); while(!q.empty()){ P p=q.top();q.pop(); Int v=p.second; if(d[v]d[v]+c){ d[u]=d[v]+c; b[u]=v; q.emplace(d[u],u); } } } return d; } //INSERT ABOVE HERE signed main(){ Int x,y,z; cin>>x>>y>>z; char s0,s1; Int t0,t1; cin>>s0>>t0; cin>>s1>>t1; Int n=8; using P = pair; vector< vector

> G(n); vector vs({x,x,y,y,z,z}); for(Int k=0;k<6;k+=2){ G[k+0].emplace_back(k+1,vs[k]-1); G[k+1].emplace_back(k+0,vs[k]-1); } for(Int k=0;k<2;k++){ G[0+k].emplace_back(2+k,1); G[0+k].emplace_back(4+k,1); G[2+k].emplace_back(0+k,1); G[2+k].emplace_back(4+k,1); G[4+k].emplace_back(0+k,1); G[4+k].emplace_back(2+k,1); } for(Int k=0;k<6;k+=2){ if(s0=='A'+(k/2)){ G[k+0].emplace_back(6,t0-1); G[6].emplace_back(k+0,t0-1); G[k+1].emplace_back(6,vs[k]-t0); G[6].emplace_back(k+1,vs[k]-t0); } if(s1=='A'+(k/2)){ G[k+0].emplace_back(7,t1-1); G[7].emplace_back(k+0,t1-1); G[k+1].emplace_back(7,vs[k]-t1); G[7].emplace_back(k+1,vs[k]-t1); } } if(s0==s1){ G[6].emplace_back(7,abs(t0-t1)); G[7].emplace_back(6,abs(t0-t1)); } cout<