#include <bits/stdc++.h>
using namespace std;
struct cww {
  cww() {
    if (1) {
      ios::sync_with_stdio(false);
      cin.tie(0);
    }
  }
} star;
template <typename T>
inline bool chmin(T &l, T r) {
  bool a = l > r;
  if (a) l = r;
  return a;
}
template <typename T>
inline bool chmax(T &l, T r) {
  bool a = l < r;
  if (a) l = r;
  return a;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &it : v) is >> it;
  return is;
}
long long dm[41234];
long long nt[41234];
long long ceil(long long a, long long b) { return (a + b - 1) / b; }
int main() {
  int n;
  long long hh, aa, dd, ss;
  cin >> n >> hh >> aa >> dd >> ss;
  long long ret = 0;
  for (int i = (0); i < (n); i++) {
    int h, a, d, s;
    cin >> h >> a >> d >> s;
    if (aa - d <= 0 && a - dd > 0) {
      cout << -1 << endl;
      return 0;
    }
    if (a - dd <= 0) {
      i--;
      n--;
      continue;
    }
    dm[i] = a - dd;
    nt[i] = ceil(h, aa - d) - 1;
    if (ss < s) ret += dm[i];
  }
  vector<int> v(n);
  iota((v).begin(), (v).end(), 0);
  sort((v).begin(), (v).end(), [&](const int i, const int j) {
    long long di = dm[i] * nt[j];
    long long dj = dm[j] * nt[i];
    return di < dj;
  });
  long long turn = 0;
  for (auto &i : v) {
    if (0) cout << i << " " << dm[i] << " " << nt[i] << endl;
    turn += nt[i] + 1;
    ret += dm[i] * (turn - 1);
    if (ret >= hh) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ret << endl;
  return 0;
}
