#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
int n, h, a, d, s;
struct E {
  int h, a, d, s, t;
};
bool cmp(const E &a, const E &b) {
  long long da = a.a - d, db = b.a - d;
  return db * b.t - da * b.t - (s > a.s) * da + (s > b.s) * db < 0;
}
int main() {
  cin >> n >> h >> a >> d >> s;
  vector<E> es;
  for (int i = 0; i < (int)n; i++) {
    E e;
    cin >> e.h >> e.a >> e.d >> e.s;
    long long 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.push_back(e);
    }
  }
  sort((es).begin(), (es).end(), cmp);
  long long ans = 0, turn = 0;
  for (int i = 0; i < (int)es.size(); i++) {
    turn += es[i].t;
    ans += (es[i].a - d) * (turn - (s > es[i].s));
  }
  cout << ans << endl;
  return 0;
}
