#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U>
ostream& operator<<(ostream& o, const pair<T, U>& p) {
  o << "(" << p.first << "," << p.second << ")";
  return o;
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}
using pl = pair<ll, ll>;
bool comp(const pl& l, const pl& r) {
  return l.first * r.second >= l.second * r.first;
}
ll solve() {
  int n;
  cin >> n;
  ll H, A, D, S;
  cin >> H >> A >> D >> S;
  ll ret = 0;
  vector<pl> e(n);
  for (int(i) = 0; (i) < (int)(n); ++(i)) {
    ll h, a, d, s;
    cin >> h >> a >> d >> s;
    ll damage = max(0LL, a - D);
    ll dd = max(0LL, A - d);
    if (dd == 0) return -1;
    ll turn = (h + dd - 1) / dd;
    if (S > s) ret -= damage;
    e[i] = {damage, turn};
  }
  sort((e).begin(), (e).end(), comp);
  ll T = 0;
  for (int(i) = 0; (i) < (int)(n); ++(i)) {
    T += e[i].second;
    ret += e[i].first * T;
    if (ret > H) return -1;
  }
  return ret;
}
int main() {
  cout << solve() << endl;
  return 0;
}
