#include using namespace std; int dp[10][100][10000]; tuple ok(int a,int th,int hu,int on){ int dig=min(th,a/1000); th-=dig; a-=dig*1000; dig=min(hu,a/100); hu-=dig; a-=dig*100; dig=min(on,a); on-=dig; a-=dig; if(a>0) return make_tuple(-1,-1,-1); return make_tuple(th,hu,on); } int main(){ int a[3]; cin>>a[0]>>a[1]>>a[2]; int db; cin>>db; int b[3]; cin>>b[0]>>b[1]>>b[2]; int dc; cin>>dc; int c[3]; cin>>c[0]>>c[1]>>c[2]; int ans=0; queue > q; q.push(make_tuple(a[0],a[1],a[2])); tuple n; while(!q.empty()){ n=q.front(); q.pop(); int th=get<0>(n); int hu=get<1>(n); int on=get<2>(n); n=ok(db,th,hu,on); if(get<0>(n)!=-1){ int nt=get<0>(n)+b[0]; int nh=get<1>(n)+b[1]; int no=get<2>(n)+b[2]; dp[nt][nh][no]=max(dp[nt][nh][no],dp[th][hu][on]+1); q.push(make_tuple(nt,nh,no)); ans=max(ans,dp[nt][nh][no]); } n=ok(dc,th,hu,on); if(get<0>(n)!=-1){ int nt=get<0>(n)+c[0]; int nh=get<1>(n)+c[1]; int no=get<2>(n)+c[2]; dp[nt][nh][no]=max(dp[nt][nh][no],dp[th][hu][on]+1); q.push(make_tuple(nt,nh,no)); ans=max(ans,dp[nt][nh][no]); } } cout<