#include <bits/stdc++.h>
using namespace std;
long long h[40001], a[40001], d[40001], s[40001];
long long N, H, A, D, S;
struct NODE {
  long long hp, dmg;
  NODE(long long hp, long long dmg) : hp(hp), dmg(dmg){};
};
bool cmp(const NODE &a, const NODE &b) { return a.hp * b.dmg < b.hp * a.dmg; }
int main() {
  cin >> N;
  cin >> H >> A >> D >> S;
  long long F = H;
  for (int i = 0; i < N; i++) {
    cin >> h[i] >> a[i] >> d[i] >> s[i];
  }
  vector<NODE> v;
  long long dsum = 0;
  for (int i = 0; i < N; i++) {
    long long dmg = max(A - d[i], 0ll);
    if (!dmg) {
      cout << -1 << endl;
      return 0;
    }
    h[i] = (h[i] + dmg - 1) / dmg;
    long long edmg = max(a[i] - D, 0ll);
    H -= s[i] > S ? edmg : 0ll;
    dsum += edmg;
    v.push_back(NODE(h[i], edmg));
  }
  sort(v.begin(), v.end(), cmp);
  for (int i = 0; i < v.size(); i++) {
    H -= (v[i].hp - 1) * dsum;
    dsum -= v[i].dmg;
    H -= dsum;
  }
  if (H <= 0)
    cout << -1 << endl;
  else
    cout << F - H << endl;
}
