#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  long long int H[N], A[N], D[N], S[N], h, a, d, s, t, ans = 0LL;
  cin >> h >> a >> d >> s;
  for (int i = 0; i < N; ++i) {
    cin >> H[i] >> A[i] >> D[i] >> S[i];
    A[i] -= d;
    A[i] = max(A[i], 0LL);
    if (S[i] < s) ans -= A[i];
  }
  vector<pair<double, int> > V;
  for (int i = 0; i < N; ++i) {
    if (a <= D[i] && A[i] > 0) {
      cout << -1 << endl;
      return 0;
    }
    if (a != D[i]) {
      t = (H[i] + a - D[i] - 1) / (a - D[i]);
      V.push_back(make_pair(-(double)A[i] / t, i));
    } else {
      V.push_back(make_pair(0, i));
    }
  }
  sort(V.begin(), V.end());
  t = 0LL;
  for (int i = 0; i < N; ++i) {
    int j = V[i].second;
    if (a != D[j]) {
      t += (H[j] + a - D[j] - 1) / (a - D[j]);
      ans += t * A[j];
    }
    if (ans >= h) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (ans >= h)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
