#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 40000;
const long long INF = 1LL << 60;

/* typedef */

typedef long long ll;

/* global variables */

int n, m;
ll h0, a0, d0, s0;
ll hs[MAX_N], as[MAX_N], ds[MAX_N], ss[MAX_N];
ll tns[MAX_N], dms[MAX_N];
int ids[MAX_N];

/* subroutines */

bool idcmp(const int& a, const int& b) {
  return tns[a] * dms[b] < tns[b] * dms[a];
}

/* main */

int main() {
  cin >> n;
  cin >> h0 >> a0 >> d0 >> s0;

  m = 0;

  for (int i = 0; i < n; i++) {
    cin >> hs[i] >> as[i] >> ds[i] >> ss[i];
    int ai = a0 - ds[i], di = as[i] - d0;
    tns[i] = (ai > 0) ? (hs[i] + ai - 1) / ai : INF;
    dms[i] = (di > 0) ? di : 0;
    if (ai <= 0 && di > 0) {
      cout << -1 << endl;
      return 0;
    }

    if (di > 0) ids[m++] = i;
  }

  sort(ids, ids + m, idcmp);

  ll dsum = 0, tnsum = 0;
  
  for (int i = 0; i < m; i++) {
    int id = ids[i];
    //printf("id=%d, tns[id]=%lld, dms[id]=%lld\n", id, tns[id], dms[id]);

    tnsum += tns[id];
    dsum += (s0 > ss[id] ? tnsum - 1 : tnsum) * dms[id];

    if (dsum >= h0) {
      dsum = -1;
      break;
    }
  }

  cout << dsum << endl;
  
  return 0;
}