#include <bits/stdc++.h>
using namespace std;
int n;
long long ma, md, ms, mh;
struct data {
  long long h, a, d, s;
  data() {}
  data(long long hh, long long aa, long long dd, long long ss) {
    h = hh;
    a = aa;
    d = dd;
    s = ss;
  }
  bool operator<(const data& da) const {
    long long turn = (h + (ma - d - 1LL)) / (ma - d);
    long long dturn = (da.h + (ma - da.d - 1LL)) / (ma - da.d);
    long long sum =
        turn * max(0LL, a - md) + (turn + dturn) * max(0LL, da.a - md);
    long long dsum =
        (turn + dturn) * max(0LL, a - md) + dturn * max(0LL, da.a - md);
    return sum < dsum;
  }
};
vector<data> vec;
int main(void) {
  scanf("%d", &n);
  long long sum = 0;
  scanf("%lld%lld%lld%lld", &mh, &ma, &md, &ms);
  for (int i = 0; i < n; i++) {
    long long h, a, d, s;
    scanf("%lld%lld%lld%lld", &h, &a, &d, &s);
    if (ma - d < 0LL) {
      if (a - md > 0) {
        printf("-1\n");
        return 0;
      }
    } else {
      sum += max(0LL, a - md);
      vec.push_back(data(h, a, d, s));
    }
  }
  sort(vec.begin(), vec.end());
  long long res = 0;
  for (int i = 0; i < vec.size(); i++) {
    long long turn = (vec[i].h + (ma - vec[i].d - 1LL)) / (ma - vec[i].d);
    res += turn * sum;
    if (vec[i].s < ms) res -= max(0LL, vec[i].a - md);
    if (res >= mh) {
      printf("-1\n");
      return 0;
    }
    sum -= max(0LL, vec[i].a - md);
  }
  printf("%lld\n", res);
  return 0;
}
