#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    ll hp, atk, def, spd;
    cin >> hp >> atk >> def >> spd;
    vector<ll> h, a, d, s;
    for (int i = 0; i < n; i++)
    {
        ll htmp, atmp, dtmp, stmp;
        cin >> htmp >> atmp >> dtmp >> stmp;
        if (dtmp >= atk && atmp > def)
        {
            cout << -1 << endl;
            return 0;
        }
        if (atmp <= def)
            continue;
        atmp -= def;
        h.push_back(htmp);
        a.push_back(atmp);
        d.push_back(dtmp);
        s.push_back(stmp);
    }
    n = h.size();
    vector<ll> turn(n);
    for (int i = 0; i < n; i++)
    {
        ll tmp = atk - d[i];
        turn[i] = (h[i] - 1) / tmp + 1;
    }
    vector<int> idx(n);
    for (int i = 0; i < n; i++)
        idx[i] = i;
    sort(idx.begin(), idx.end(), [&](int i, int j) { return turn[i] * a[j] < turn[j] * a[i]; });
    ll ret = 0, cnt = 0;
    for (auto i : idx)
    {
        hp -= cnt * a[i];
        ret += cnt * a[i];
        cnt += turn[i];
        if (s[i] <= spd)
            turn[i]--;
        hp -= turn[i] * a[i];
        ret += turn[i] * a[i];
        if (hp <= 0)
        {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ret << endl;
}
