#include using namespace std; using ll = long long; using vll = vector; template using umap = unordered_map; #define rep(i, n) for (int i = 0; i < n;i++) #define rep1(i, n) for (int i = 1; i <= n;i++) #define rrep(i, n) for (int i = n - 1; i >= 0;i--) #define rrep1(i, n) for (int i = n; i >= 1;i--) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define INF 1LL << 60 #define chmin(a, b) a = min(a, b) #define chmax(a, b) a = max(a, b) int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); ll r, p, q, a, b, c, d; cin >> r >> p >> q >> a >> b >> c >> d; ll ans = 0; auto check = [&](ll x) {// x人のルーマニア人を錬成できるか? if (x * p > r) { return false; } ll res = min({a, b, c}); if (res >= x) { return true; } ll A = a - res; ll B = b - res; ll C = c - res; // 残りでremain人のルーマニア人を錬成できるか? ll remain = x - res; ll need = max(0LL, remain - A) + max(0LL, remain - B) + max(0LL, remain - C); if (need > d) { return false; } if (need * q + x * p > r) { return false; } return true; }; ll ok = 0; ll ng = a + b + c + d; while (ng - ok > 1) { ll mid = (ok + ng) / 2; if (check(mid)) { ok = mid; } else { ng = mid; } } cout << ok << endl; }