#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; struct Data{ int a,b,c,cnt; Data(){ a=b=c=-1; cnt=0; } Data(int _a,int _b,int _c,int _cnt){ a=_a; b=_b; c=_c; cnt=_cnt; } Data(Data x,Data y,int d){ while(x.a>0 && d>=1000){ d -= 1000; x.a--; } while(x.b>0 && d>=100){ d -= 100; x.b--; } while(x.c>0 && d>0){ d--; x.c--; } if(d!=0){ a=b=c=-1; } else{ a = x.a+y.a; b = x.b+y.b; c = x.c+y.c; cnt = x.cnt+1; } } bool operator<(const Data &x)const{ if(a!=x.a) return a>a>>b>>c; } int get_sum(){ return a*1000+b*100+c; } }; Data dp[10000]; int main(){ Data A,B,C; int Db,Dc; A.input(); cin>>Db; B.input(); cin>>Dc; C.input(); dp[A.get_sum()] = A; int ans = 0; for(int i=A.get_sum();i>=0;i--){ if(dp[i].a==-1) continue; ans = max(ans,dp[i].cnt); if(i>=Db) dp[i-Db+B.get_sum()] = max(dp[i-Db+B.get_sum()],Data(dp[i],B,Db)); if(i>=Dc) dp[i-Dc+C.get_sum()] = max(dp[i-Dc+C.get_sum()],Data(dp[i],C,Dc)); } printf("%d\n",ans); return 0; }