#include <bits/stdc++.h>
using namespace std;
struct at {
  long long a, t;
};
bool comp(const at &x, const at &y) {
  return (x.a * (x.t - 1) + y.a * (x.t + y.t - 1)) <
         (y.a * (y.t - 1) + x.a * (x.t + y.t - 1));
}
vector<at> e;
int main() {
  int n;
  cin >> n;
  long long hp, atk, def, sp;
  long long ans = 0;
  cin >> hp >> atk >> def >> sp;
  for (int i = 0; i < n; i++) {
    long long ehp, eatk, edef, esp;
    cin >> ehp >> eatk >> edef >> esp;
    long long dm = max((long long)0, atk - edef);
    if (esp > sp) ans += max(0LL, eatk - def);
    if (dm == 0) {
      cout << -1 << endl;
      exit(0);
    }
    e.push_back((at){max((long long)0, eatk - def), (ehp + dm - 1) / dm});
  }
  sort(e.begin(), e.end(), comp);
  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    long long x = e[i].a, y = e[i].t;
    ans += x * (y - 1 + cnt);
    cnt += y;
  }
  if (hp - ans <= 0)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
