#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int h0, a0, d0, s0;
  int h1, a1, d1;
  int a[40001], t[40001], s[40001];
  pair<double, int> p[40001];
  cin >> n >> h0 >> a0 >> d0 >> s0;
  for (int i = (0); i < (int)n; ++i) {
    cin >> h1 >> a1 >> d1 >> s[i];
    if (a0 <= d1) {
      cout << -1 << endl;
      return 0;
    }
    a[i] = max(a1 - d0, 0);
    t[i] = ((h1 - 1) / (a0 - d1)) + 1;
    p[i] = make_pair((a[i]) ? ((double)t[i] / a[i]) : 1e10, i);
  }
  long long damage = 0;
  long long now = 0;
  sort(p, p + n);
  for (int i = (0); i < (int)n; ++i) {
    int idx = p[i].second;
    now += t[idx];
    damage += (long long)a[idx] * ((s0 < s[idx]) ? now : (now - 1));
  }
  if (damage < h0) {
    cout << damage << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
