#include <bits/stdc++.h>
using namespace std;

struct data {
  long long h, a, d, s;
  bool operator<(const data &r) const {
    long long nowl = h * r.a, nowr = r.h * a;
    if(nowl != nowr) return nowl < nowr;
    return s > r.s;
  }
};

long long n;
data me;
vector<data> v;

long long solve();

int main() {
  cin >> n >> me.h >> me.a >> me.d >> me.s;
  v.resize(n);
  for(int i = 0; i < n; ++i) {
    cin >> v[i].h >> v[i].a >> v[i].d >> v[i].s;
    v[i].a = max(0LL, v[i].a - me.d);
    v[i].d = max(0LL, me.a - v[i].d);
    if(v[i].a == v[i].d && v[i].a == 0) {
      v.pop_back();
      --n;
      --i;
      continue;
    }
    if(v[i].d == 0) {
      cout << -1 << endl;
      return 0;
    }
    v[i].h = (v[i].h + v[i].d - 1) / v[i].d;
  }
  sort(v.begin(), v.end());
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0, turn = 0;
  for(int i = 0; i < n; ++i) {
    turn += v[i].h - (me.s > v[i].s);
    res += v[i].a * turn;
    if(me.s > v[i].s) ++turn;
    if(res >= me.h) return -1;
  }
  return res;
}
