#include <bits/stdc++.h>
#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 l.damage / ld(l.turn) > 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) {
      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) {
    gettotal += atsum * o.turn;
    atsum -= o.damage;
  }
  if (gettotal >= T) gettotal = -1;
  cout << gettotal << endl;
  return 0;
}
