#include using namespace std; namespace { typedef double real; typedef long long ll; template ostream& operator<<(ostream& os, const vector& vs) { if (vs.empty()) return os << "[]"; auto i = vs.begin(); os << "[" << *i; for (++i; i != vs.end(); ++i) os << " " << *i; return os << "]"; } template istream& operator>>(istream& is, vector& vs) { for (auto it = vs.begin(); it != vs.end(); it++) is >> *it; return is; } vector A, B, C; int Db, Dc; void input() { A.resize(3); B.resize(3); C.resize(3); cin >> A >> Db >> B >> Dc >> C; } vector try_(int d, int x, int y, int z) { vector ret; int t = d; int p = min(x, t / 1000); t -= p * 1000; int q = min(y, t / 100); t -= q * 100; int r = min(z, t / 1); if (p * 1000 + q * 100 + r * 1 < d) return ret; ret.push_back(p); ret.push_back(q); ret.push_back(r); return ret; } map< tuple, int > cache; int f(int x, int y, int z) { //cerr << "f " << x << " " << y << " " << z << endl; auto key = make_tuple(x, y, z); if (cache.count(key)) return cache[key]; vector b = try_(Db, x, y, z); vector c = try_(Dc, x, y, z); int ans = 0; if (not b.empty()) { ans = max(ans, 1 + f(x - b[0] + B[0], y - b[1] + B[1], z - b[2] + B[2])); } if (not c.empty()) { ans = max(ans, 1 + f(x - c[0] + C[0], y - c[1] + C[1], z - c[2] + C[2])); } return cache[key] = ans; } void solve() { cout << f(A[0], A[1], A[2]) << endl; } } int main() { input(); solve(); return 0; }