#include <bits/stdc++.h>
using namespace std;
inline int sign(double x) { return (abs(x) < 1e-9 ? 0 : x > 0 ? 1 : -1); }
inline bool inRange(int val, int min, int max) {
  return val >= min && val < max;
}
inline bool inRange(double val, double min, double max) {
  return val - min > -1e-9 && val - max < 1e-9;
}
template <class T>
struct vevector : public vector<vector<T>> {
  vevector(int n = 0, int m = 0, const T &initial = T())
      : vector<vector<T>>(n, vector<T>(m, initial)) {}
};
template <class T>
struct vevevector : public vector<vevector<T>> {
  vevevector(int n = 0, int m = 0, int l = 0, const T &initial = T())
      : vector<vevector<T>>(n, vevector<T>(m, l, initial)) {}
};
template <class T>
struct vevevevector : public vector<vevevector<T>> {
  vevevevector(int n = 0, int m = 0, int l = 0, int k = 0,
               const T &initial = T())
      : vector<vevevector<T>>(n, vevevector<T>(m, l, k, initial)) {}
};
inline void readfrom(...) {}
inline void writeto(...) {}
struct _Reader {
  template <class T>
  _Reader operator,(T &rhs) {
    cin >> rhs;
    return *this;
  }
};
struct _Writer {
  bool f;
  _Writer() : f(false) {}
  template <class T>
  _Writer operator,(const T &rhs) {
    cout << (f ? " " : "") << rhs;
    f = true;
    return *this;
  }
};
template <class T>
T read() {
  T t;
  cin >> t;
  return t;
}
template <class T>
vector<T> read(int n) {
  vector<T> v;
  for (int i = 0; i < (n); i++) {
    v.push_back(read<T>());
  }
  return v;
}
template <class T>
vevector<T> read(int n, int m) {
  vevector<T> v;
  for (int i = 0; i < (n); i++) v.push_back(read<T>(m));
  return v;
}
template <class T>
vevector<T> readjag() {
  return read<T>(read<int>());
}
template <class T>
vevector<T> readjag(int n) {
  vevector<T> v;
  for (int i = 0; i < (n); i++) v.push_back(readjag<T>());
  return v;
}
template <class T1, class T2>
inline istream &operator>>(istream &in, pair<T1, T2> &p) {
  in >> p.first >> p.second;
  return in;
}
template <class T1, class T2>
inline ostream &operator<<(ostream &out, pair<T1, T2> &p) {
  out << p.first << p.second;
  return out;
}
template <class T>
inline ostream &operator<<(ostream &out, const vector<T> &v) {
  ostringstream ss;
  for (auto x : v) ss << x << ' ';
  auto s = ss.str();
  out << s.substr(0, s.length() - 1) << endl;
  return out;
}
void solve();
int main() {
  solve();
  return 0;
}
void solve() {
  int testcases = 1;
  for (int testcase = 0; testcase < (testcases); testcase++) {
    int n;
    _Reader(), n;
    long long hp, pa, pd, ps;
    _Reader(), hp, pa, pd, ps;
    double dmgPerTurn = 0;
    struct E {
      long long h, a, d, s;
    };
    vector<E> op;
    for (int i = 0; i < (n); i++) {
      int h, a, d, s;
      _Reader(), h, a, d, s;
      op.push_back({h, a, d, s});
    }
    struct C {
      long long a, d, t;
      double priority;
    };
    vector<C> enemies;
    bool muri = false;
    long long dmg = 0;
    for (int i = 0; i < (n); i++) {
      E e = op[i];
      int aa = max(e.a - pd, 0ll);
      int dd = max(pa - e.d, 0ll);
      if (dd == 0 && aa != 0) {
        muri = true;
        break;
      }
      if (dd == 0) {
        continue;
      }
      int tt = (e.h + dd - 1) / dd;
      double priority = (double)tt / aa;
      enemies.push_back({aa, dd, tt, priority});
      if (e.s > ps) {
        dmg += aa;
      }
      dmgPerTurn += aa;
    }
    if (muri) {
      _Writer(), -1;
      cout << endl;
      continue;
    }
    sort(enemies.begin(), enemies.end(), [&](const C &a, const C &b) -> bool {
      return a.priority < b.priority;
    });
    for (auto e : enemies) {
      long long t = e.t;
      dmg += t * dmgPerTurn - e.a;
      dmgPerTurn -= e.a;
    }
    _Writer(), dmg < hp ? dmg : -1;
    cout << endl;
  }
}
