#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
int tekisort(pair<int, int> a, pair<int, int> b) {
  return a.first * b.second < a.second * b.first;
}
int main() {
  long long n, shuh, shua, shud, shus;
  long long tmph, tmpa, tmpd, tmps, zentan;
  zentan = 0;
  vector<pair<int, int> > enemies;
  cin >> n >> shuh >> shua >> shud >> shus;
  zentan = shuh;
  for (long long i = 0; i < n; i++) {
    cin >> tmph >> tmpa >> tmpd >> tmps;
    long long tmpdd = shua - tmpd;
    if (tmpdd <= 0) {
      cout << -1 << endl;
      return 0;
    }
    long long tmpt = tmph / tmpdd;
    if (tmph % tmpdd) tmpt += 1;
    if (tmps > shus) shuh -= max(tmpa - shud, (long long)0);
    enemies.push_back(make_pair(tmpt, max(tmpa - shud, (long long)0)));
  }
  sort(enemies.begin(), enemies.end(), tekisort);
  long long imamade = 0;
  for (long long i = 0; i < n; i++) {
    imamade += enemies[i].first;
    shuh -= (imamade - 1) * enemies[i].second;
  }
  if (shuh > 0)
    cout << zentan - shuh << endl;
  else
    cout << -1 << endl;
  return 0;
}
