#ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif #include using namespace std; // #include // using namespace atcoder; using ll = long long; // 2^63-1まで 負の値は可 // using ull = unsigned long long; // 0 <= ull <=2^64-1の範囲 負の値は不可 using vl = vector; // using vvl = vector; // using P = pair; template using MNPQ = priority_queue, greater>; template using MXPQ = priority_queue, less>; #define overload(a, b, c, d, e, ...) e #define FOR1(i, n) for (int i = 0; i < n; i++) #define FOR2(i, s, n) for (int i = s; i < n; i++) #define FOR3(i, s, n, a) for (int i = s; i < n; i += a) #define rep(...) overload(__VA_ARGS__, FOR3, FOR2, FOR1)(__VA_ARGS__) #define FOR1_R(i, n) for (int i = n - 1; i >= 0; i--) #define FOR2_R(i, s, n) for (int i = s - 1; i >= n; i--) #define FOR3_R(i, s, n, a) for (int i = s - 1; i >= n; i += a) #define rrep(...) overload(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define nall(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define YN(flg) cout << (flg ? "Yes" : "No") << "\n" #define out_grid(x, y, h, w) !(0 <= x && x < h && 0 <= y && y < w) #define debug(x) cerr << #x << " = " << x << endl; const long long INF = 4e18; template istream& operator>>(istream& is, vector& a) { for (auto& x : a) is >> x; return is; } template ostream& operator<<(ostream& os, vector& a) { for (int i = 0; i < (int)a.size(); i++) os << a[i] << " "; return os; } template ostream& operator<<(ostream& os, pair& p) { os << "{" << p.first << "," << p.second << "}"; return os; } template ostream& operator<<(ostream& os, map& a) { for (auto& [k, v] : a) os << "{key:" << k << ", item:" << v << "} "; return os; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); ll r, p, q; cin >> r >> p >> q; ll a, b, c, d; cin >> a >> b >> c >> d; auto f = [&]() -> ll { ll mn = min({a, b, c}); chmin(mn, r / p); a -= mn, b -= mn, c -= mn; r -= mn * p; return mn; }; ll ans = f(); vector v = {a, b, c}; auto ff = [&](ll x) -> bool { ll pr = d, m = 0; rep(i, 3)(v[i] >= x ? pr : m) += abs(v[i] - x); if (pr < m) return 0; return r >= m * q + x * p; }; ll ok = 0, ng = 1e10; while (ng - ok > 1) { ll mid = (ok + ng) / 2; // cout << ok << " " << ng << endl; (ff(mid) ? ok : ng) = mid; } cout << ans + ok << endl; // sort(nall(v)); // ll n = min(v[1] - v[0], d); // ll e = min(n, r / (p + q)); // v[0] += e; // r -= e * (p + q); // a = v[0], b = v[1], c = v[2]; // ans += f(); // n = min((v[1] - v[0]) * 2, d); // e = min(n, r / (p + q)); // v[0] += e, v[1] += e; // r -= e * (p + q); // a = v[0], b = v[1], c = v[2]; // ans += f(); // cout << ans << endl; return 0; }