#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
istream& operator>>(istream& is, pair<S, T>& p) {
  return is >> p.first >> p.second;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const long long MOD = 1e9 + 7;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N;
  cin >> N;
  long long mh, ma, md, ms;
  cin >> mh >> ma >> md >> ms;
  vector<pair<long long, long long> > en(N);
  long long dsum = 0;
  for (int i = (0); i < (N); ++i) {
    long long h, a, d, s;
    cin >> h >> a >> d >> s;
    if (ma <= d) {
      cout << -1 << endl;
      return 0;
    }
    en[i] = make_pair((h - 1) / (ma - d) + 1, max(0LL, a - md));
    if (s < ms) dsum -= en[i].second;
  }
  sort((en).begin(), (en).end(),
       [](pair<long long, long long>& p1, pair<long long, long long>& p2) {
         return p1.first * p2.second < p1.second * p2.first;
       });
  long long tsum = 0;
  for (int i = 0; i < N; ++i) {
    tsum += en[i].first;
    dsum += tsum * en[i].second;
    if (dsum >= mh) break;
  }
  cout << (dsum >= mh ? -1 : dsum) << endl;
  return 0;
}
