#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

ll n, h, a, d, s;
struct E{
	ll h, a, d, s, t;
};
bool cmp(const E &a, const E &b){
	ll da = a.a - d, db = b.a - d;
	return a.t * db < b.t * da;
}

int main(){
	cin >> n >> h >> a >> d >> s;
	vector<E> es;
	rep(i, n){
		E e;
		cin >> e.h >> e.a >> e.d >> e.s;
		ll k = a - e.d;
		if(e.a <= d) continue;
		if(k <= 0){
			cout << -1 << endl;
			return 0;
		}
		else{
			e.t = (e.h + k - 1) / k; 
			es.pb(e);
		}
	}
	sort(all(es), cmp);
	ll ans = 0, turn = 0;
	rep(i, es.size()){
		turn += es[i].t;
		ans += (es[i].a - d) * (turn - (s > es[i].s));
		if(ans >= h){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
	return 0;
}