#include<bits/stdc++.h>
using namespace std;
const int M = 1000000007;
struct enemy {
    long long damage, turn;
    enemy(long long damage, long long turn) : damage(damage), turn(turn) {}
    bool operator<(const enemy& o) const { return turn * o.damage < damage * o.turn; }
};

int main() {
    int n;
    cin >> n;
    long long h, a, d, s;
    cin >> h >> a >> d >> s;
    long long ans = 0, sum = 0;
    vector<enemy> v;
    for (int i = 0; i < n; ++i) {
        long long hi, ai, di, si;
        cin >> hi >> ai >> di >> si;
        if (ai <= d) continue;
        if (di >= a) {
            cout << "-1\n";
            return 0;
        }
        if (si > s) ans += ai - d;
        sum += ai - d;
        v.push_back(enemy(ai - d, (hi + a - di - 1) / (a - di)));
    }
    sort(v.begin(), v.end());
    for (auto& i : v) {
        ans += sum * i.turn - i.damage;
        sum -= i.damage;
        if (ans >= h) {
            cout << "-1\n";
            return 0;
        }
    }
    cout << ans << "\n";
    return 0;
}

