#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
ld eps=1e-9;

struct op {
	long long int damage;
	long long int turn;
};
bool operator < (const op&l, const op&r) {
	return ld(l.damage)/ld(l.turn) > ld(r.damage)/ld(r.turn);
}
int main() {
	int N; cin >> N;
	int T, A, D, S; cin >> T >> A >> D >> S;
	vector<op>ops;
	long long int gettotal = 0;
	for (int i = 0; i < N; ++i) {
		long long int t, a, d, s; cin >> t >> a >> d >> s;
		
		const long long int getdam = max(0ll,a - D);
		if (s < S) {
			gettotal -= getdam;
		}
		const long long int mydam = A - d;
		if (mydam <= 0) {
			if (getdam <= 0) {
				continue;
			}
			else {

				cout << -1 << endl;
				return 0;
			}
		}
		else {
			const long long  int turn = (t-1) / mydam+1;
			ops.push_back(op{ getdam,turn });
		}
	}
	sort(ops.begin(), ops.end());
	long long int atsum = 0;
	for (auto o : ops) {
		atsum += o.damage;
	}
	for (auto o : ops) {
		ld about = ld(atsum)*ld(o.turn);
		if (about > 1e16) {
			gettotal =1e16;
			break;
		}
		gettotal += atsum*o.turn;
		if (gettotal >= T)break;
		atsum -= o.damage;
	}
	if (gettotal >= T)gettotal = -1;
	cout << gettotal << endl;
	return 0;
}