#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long h, a, d, s;
  cin >> h >> a >> d >> s;
  vector<long long> eh(n), ea(n), ed(n), es(n);
  vector<pair<long double, long long>> ss(n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> eh[i] >> ea[i] >> ed[i] >> es[i];
    ea[i] = ((ea[i] - d) > (0) ? (ea[i] - d) : (0));
    ed[i] = ((a - ed[i]) > (0) ? (a - ed[i]) : (0));
    if (es[i] > s) ans += ea[i];
    if (ed[i] == 0) {
      if (ea[i] > 0) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      ss[i] = {((eh[i] + ed[i] - 1) / ed[i]) / (long double)ea[i], i};
    }
    if (ea[i] == 0) ss[i] = {1000000000000000000, i};
  }
  sort((ss).begin(), (ss).end());
  long long turn = 0;
  int id;
  for (int i = 0; i < n; i++) {
    id = ss[i].second;
    turn += (eh[id] + ed[id] - 1) / ed[id];
    ans += (turn - 1) * ea[id];
    if (ans >= h) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
