#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Data
{
public:
    long long h, a, d, s;
    bool operator<(const Data& other) const
    {
        return h * other.a < other.h * a;
    }
};

int main()
{
    int n;
    cin >> n;

    Data usagi;
    cin >> usagi.h >> usagi.a >> usagi.d >> usagi.s;

    vector<Data> enemy;
    for(int i=0; i<n; ++i){
        Data tmp;
        cin >> tmp.h >> tmp.a >> tmp.d >> tmp.s;
        if(tmp.a > usagi.d)
            enemy.push_back(tmp);
    }
    n = enemy.size();

    for(int i=0; i<n; ++i){
        enemy[i].a = max(enemy[i].a - usagi.d, 0LL);
        long long damage = usagi.a - enemy[i].d;
        if(damage <= 0){
            cout << -1 << endl;
            return 0;
        }else{
            enemy[i].h = (enemy[i].h + damage - 1) / damage;
            if(enemy[i].s > usagi.s)
                enemy[i].s = 0;
            else
                enemy[i].s = 1;
        }
    }
    sort(enemy.begin(), enemy.end());

    long long t = 0;
    long long ret = 0;
    for(int i=0; i<n; ++i){
        t += enemy[i].h;
        ret += (t - enemy[i].s) * enemy[i].a;
        if(ret >= usagi.h){
            cout << -1 << endl;
            return 0;
        }
    }

    cout << ret << endl;

    return 0;
}