#include "bits/stdc++.h" using namespace std; int A[3], B[3], C[3]; int now[3]; int DB, DC; bool useB(){ int nokori = DB; int use0 = min(now[0], nokori / 1000); nokori -= use0 * 1000; int use1 = min(now[1], nokori / 100); nokori -= use1 * 100; int use2 = min(now[2], nokori / 1); nokori -= use2 * 1; if (nokori != 0) return false; now[0] += B[0] - use0; now[1] += B[1] - use1; now[2] += B[2] - use2; return true; } bool useC(){ int nokori = DC; int use0 = min(now[0], nokori / 1000); nokori -= use0 * 1000; int use1 = min(now[1], nokori / 100); nokori -= use1 * 100; int use2 = min(now[2], nokori / 1); nokori -= use2 * 1; if (nokori != 0) return false; now[0] += C[0] - use0; now[1] += C[1] - use1; now[2] += C[2] - use2; return true; } int main() { 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]; set> s, all; int ans = -1; auto first = make_tuple(A[0], A[1], A[2]); s.insert(first); all.insert(first); while (s.size()){ ans++; set> ns; for (auto i : s){ now[0] = get<0>(i); now[1] = get<1>(i); now[2] = get<2>(i); if (useB()){ auto n = make_tuple(now[0], now[1], now[2]); if (all.count(n) == 0){ ns.insert(n); all.insert(n); } now[0] = get<0>(i); now[1] = get<1>(i); now[2] = get<2>(i); } if (useC()){ auto n = make_tuple(now[0], now[1], now[2]); if (all.count(n) == 0){ ns.insert(n); all.insert(n); } } } s = ns; } cout << ans << endl; cin >> ans; }