#include using namespace std; int A[5], D[2], B[2][5]; int memo[11][110][10000]; int f(int A0, int A1, int A2) { if (memo[A0][A1][A2] != -1) return memo[A0][A1][A2]; int ret = 0; for (int i = 0; i < 2; i++) { int pay = D[i]; int a0, a1, a2; if (pay / 1000 <= A0) { a0 = A0 - pay / 1000; pay %= 1000; } else { a0 = 0; pay -= A0 * 1000; } if (pay / 100 <= A1) { a1 = A1 - pay / 100; pay %= 100; } else { a1 = 0; pay -= A1 * 100; } if (pay <= A2) { a2 = A2 - pay; } else { continue; } ret = max(ret, f(a0 + B[i][0], a1 + B[i][1], a2 + B[i][2]) + 1); } return memo[A0][A1][A2] = ret; } int main() { cin >> A[0] >> A[1] >> A[2]; for (int i = 0; i < 2; i++) { cin >> D[i] >> B[i][0] >> B[i][1] >> B[i][2]; } for (int i = 0; i <= 10; i++) { for (int j = 0; j <= 100; j++) { for (int k = 0; k <= 10000; k++) { memo[i][j][k] = -1; } } } cout << f(A[0], A[1], A[2]) << endl; }