#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}

LL dm[41234];
LL nt[41234];
LL ceil(LL a,LL b){
    return (a+b-1)/b;
}
typedef vector<int> V;
int main(){
    int n;
    LL hh,aa,dd,ss;
    cin>>n>>hh>>aa>>dd>>ss;
    LL ret=0;
    REP(i,n){
        int h,a,d,s;
        cin>>h>>a>>d>>s;
        if(aa-d<=0&&a-dd>0){
            cout<<-1<<endl;
            return 0;
        }
        if(a-dd<=0){
            i--;
            n--;
            continue;
        }
        dm[i]=a-dd;
        nt[i]=ceil(h,aa-d);
        if(ss<s)ret+=dm[i];
    }
    V v(n);
    iota(ALL(v),0);
    sort(ALL(v),
         [&](const int i,const int j){
             LL dij=dm[i]*(nt[i]-1)+dm[j]*(nt[i]+nt[j]-1);
             LL dji=dm[j]*(nt[j]-1)+dm[i]*(nt[i]+nt[j]-1);
             return dij<dji;
         }
         );
    LL turn=0;
    for(auto &i:v){
        DEBUG cout<<i<<" "<<dm[i]<<" "<<nt[i]<<endl;
        turn+=nt[i];
        ret+=dm[i]*(turn-1);
        if(ret>=hh){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<ret<<endl;
    
    return 0;
}