// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;
    int H, A, D, S; cin >> H >> A >> D >> S;

    vector< tuple<int, int, int, int> > enemies;
    for(int i=0; i<N; i++) {
        int h, a, d, s; cin >> h >> a >> d >> s;

        // 主人公が攻撃しても意味ない
        if(A - d <= 0) {
            // 敵がつよい
            if(a - D > 0) {
                cout << -1 << endl;
                return 0;
            }
            // 戦闘不能判定に関係ないからいらなさそう
            else {
                continue;
            }
        }
        
        enemies.emplace_back(h, a, d, s);
    }

    sort(enemies.begin(), enemies.end(), [&](auto x, auto y) {
            int xh, xa, xd, xs; tie(xh, xa, xd, xs) = x;
            int yh, ya, yd, ys; tie(yh, ya, yd, ys) = y;

            // 何ターンで死ぬか
            int xdam = A - xd; int xturn = (xh + xdam - 1) / xdam;
            int ydam = A - yd; int yturn = (yh + ydam - 1) / ydam;

            // 何回攻撃するか (x -> y)
            int xatkl = (xs > S ? xturn : xturn - 1);
            int yatkl = (ys > S ? xturn + yturn : xturn + yturn - 1);

            // 何回攻撃するか (y -> x)
            int yatkr = (ys > S ? yturn : yturn - 1);
            int xatkr = (xs > S ? xturn + yturn : xturn + yturn - 1);

            int suml = xdam * xatkl + ydam * yatkl;
            int sumr = xdam * xatkr + ydam * yatkr;
            return suml < sumr;
        });

    int turn_sum = 0, mi = 0;
    for(auto e : enemies) {
        int h, a, d, s; tie(h, a, d, s) = e;
        int dam = A - d, turn = (h + dam - 1) / dam;
        // fprintf(stderr, "h = %lld, a = %lld, d = %lld, s = %lld, dam = %lld, turn = %lld\n", h, a, d, s, dam, turn);

        turn_sum += turn;
        int atk = (s > S ? turn_sum : turn_sum - 1);
        // fprintf(stderr, "atk = %lld, dam = %lld\n", atk, dam);

        mi += atk * dam;
    }

    if(mi >= H) cout << -1 << endl;
    else cout << mi << endl;
    return 0;
}

