#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 40000;
const long long INF = 1LL << 60;
int n, m;
long long h0, a0, d0, s0;
long long hs[MAX_N], as[MAX_N], ds[MAX_N], ss[MAX_N];
long long tns[MAX_N], dms[MAX_N];
int ids[MAX_N];
bool idcmp(const int& a, const int& b) {
  return tns[a] * dms[b] < tns[b] * dms[a];
}
int main() {
  cin >> n;
  cin >> h0 >> a0 >> d0 >> s0;
  m = 0;
  for (int i = 0; i < n; i++) {
    cin >> hs[i] >> as[i] >> ds[i] >> ss[i];
    int ai = a0 - ds[i], di = as[i] - d0;
    tns[i] = (ai > 0) ? (hs[i] + ai - 1) / ai : INF;
    dms[i] = (di > 0) ? di : 0;
    if (ai <= 0 && di > 0) {
      cout << -1 << endl;
      return 0;
    }
    if (di > 0) ids[m++] = i;
  }
  sort(ids, ids + m, idcmp);
  long long dsum = 0, tnsum = 0;
  for (int i = 0; i < m; i++) {
    int id = ids[i];
    tnsum += tns[id];
    dsum += (s0 > ss[id] ? tnsum - 1 : tnsum) * dms[id];
  }
  cout << dsum << endl;
  return 0;
}
