#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x,int> > V[10001]; map,int>,int> M; pair,int> h(int a,int b,int c) { return make_pair(make_pair(a,b),c); } void solve() { int i,j,k,l,r,x,y; string s; cin>>A[0]>>A[1]>>A[2]; cin>>DB; cin>>B[0]>>B[1]>>B[2]; cin>>DC; cin>>C[0]>>C[1]>>C[2]; M[h(A[0],A[1],A[2])]=0; V[A[0]*1000+A[1]*100+A[2]].push_back(h(A[0],A[1],A[2])); for(i=10000;i>=0;i--) { sort(V[i].begin(),V[i].end()); FOR(y,V[i].size()) { if(y>0 && V[i][y]==V[i][y-1]) continue; ma=max(ma,M[V[i][y]]); { pair,int> k=V[i][y],k2; int x=DB; j=min(x/1000,k.first.first); k.first.first -= j; x -= j*1000; j=min(x/100,k.first.second); k.first.second -= j; x -= j*100; j=min(x,k.second); k.second -= j; x -= j; if(x==0) { k2=h(k.first.first+B[0],k.first.second+B[1],k.second+B[2]); r=k2.first.first*1000+k2.first.second*100+k2.second; M[k2]=max(M[k2],M[V[i][y]]+1); V[r].push_back(k2); } } { pair,int> k=V[i][y],k2; int x=DC; j=min(x/1000,k.first.first); k.first.first -= j; x -= j*1000; j=min(x/100,k.first.second); k.first.second -= j; x -= j*100; j=min(x,k.second); k.second -= j; x -= j; if(x==0) { k2=h(k.first.first+C[0],k.first.second+C[1],k.second+C[2]); r=k2.first.first*1000+k2.first.second*100+k2.second; M[k2]=max(M[k2],M[V[i][y]]+1); V[r].push_back(k2); } } } } cout<