#include <bits/stdc++.h>
using namespace std;
struct Data {
  long long h, a, d, s, t;
  bool operator<(const Data &data) const { return d * data.t > data.d * t; }
};
int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  Data fri;
  cin >> fri.h >> fri.a >> fri.d >> fri.s;
  vector<Data> buf(n);
  bool out = false;
  for (int i = 0; i < n; i++) {
    cin >> buf[i].h >> buf[i].a >> buf[i].d >> buf[i].s;
    long long fattack = max(0LL, fri.a - buf[i].d);
    long long eattack = max(0LL, buf[i].a - fri.d);
    if (fattack == 0LL) {
      out = true;
      continue;
    }
    buf[i].t = (long long)(buf[i].h / fattack) +
               (long long)((buf[i].h % fattack) != 0);
    buf[i].d = eattack;
  }
  if (out) {
    puts("-1");
    return 0;
  }
  sort(buf.begin(), buf.end());
  long long ans = 0LL, total_turn = 0;
  long long HP = fri.h;
  for (int i = 0; i < buf.size(); i++) {
    int coef = 0;
    if (buf[i].s < fri.s) coef = 1;
    total_turn += buf[i].t;
    ans += buf[i].d * (total_turn - (long long)coef);
    HP -= buf[i].d * (total_turn - (long long)coef);
    if (HP <= 0LL) {
      puts("-1");
      return 0;
    }
  }
  cout << ((ans < fri.h) ? ans : -1) << endl;
  return 0;
}
