#include <bits/stdc++.h>
using namespace std;
inline int getInt() {
  int s;
  scanf("%d", &s);
  return s;
}
int main() {
  int n = getInt();
  vector<int> h(n);
  vector<int> a(n);
  vector<int> d(n);
  vector<int> s(n);
  vector<int> memo(n);
  vector<pair<double, int> > c(n);
  int hh = getInt();
  int aa = getInt();
  int dd = getInt();
  int ss = getInt();
  long long ans = 0;
  long long tm = 0;
  long long alltime;
  for (int i = 0; i < (int)(n); i++) {
    h[i] = getInt();
    a[i] = getInt();
    d[i] = getInt();
    s[i] = getInt();
    int dam = aa - d[i];
    if (dam <= 0) goto bad;
    memo[i] = (h[i] + dam - 1) / dam;
    if (s[i] < ss)
      c[i].first = (double)max(0, a[i] - dd) / (memo[i] - 1);
    else
      c[i].first = (double)max(0, a[i] - dd) / memo[i];
    c[i].second = i;
  }
  alltime = accumulate(memo.begin(), memo.end(), 0ll);
  sort(c.rbegin(), c.rend());
  for (int i = 0; i < (int)(n); i++) {
    int ii = c[i].second;
    int tt = memo[ii] - 1;
    if (s[i] > ss) tt++;
    ans += (tm + tt) * max(0, a[ii] - dd);
    if (ans >= hh) goto bad;
    tm += memo[ii];
  }
  printf("%d\n", (int)ans);
  return 0;
bad:
  puts("-1");
  return 0;
}
