#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n;
  cin >> n;
  using T = tuple<int64_t, int64_t, int64_t, int64_t>;
  vector<T> vc;
  int h0, a0, d0, s0;
  cin >> h0 >> a0 >> d0 >> s0;
  for (int i = (0); i < (int)(n); ++i) {
    int h, a, d, s;
    cin >> h >> a >> d >> s;
    vc.emplace_back(max(0, a0 - d), s, max(a - d0, 0), h);
  }
  sort(begin(vc), end(vc), greater<T>());
  int64_t turns = 0;
  bool imp = false;
  int64_t damage = 0;
  for (T t : vc) {
    int64_t a, s, d, h;
    tie(a, s, d, h) = t;
    if (a == 0) {
      imp = true;
      break;
    } else {
      turns += (h + a - 1) / a;
      if (s < s0) {
        damage += (turns - 1) * d;
      } else {
        damage += turns * d;
      }
    }
  }
  if (imp || damage >= h0) {
    cout << -1 << endl;
  } else {
    cout << damage << endl;
  }
  return 0;
}
