#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;
template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  ll hp, atk, def, spd;
  cin >> hp >> atk >> def >> spd;
  vector<ll> h, a, d, s;
  for (int i = 0; i < n; i++) {
    ll htmp, atmp, dtmp, stmp;
    cin >> htmp >> atmp >> dtmp >> stmp;
    if (dtmp >= atk) {
      cout << -1 << endl;
      return 0;
    }
    if (atmp <= def) continue;
    atmp -= def;
    h.push_back(htmp);
    a.push_back(atmp);
    d.push_back(dtmp);
    s.push_back(stmp);
  }
  n = h.size();
  vector<ll> turn(n), dmg(n);
  for (int i = 0; i < n; i++) {
    dmg[i] = a[i] - def;
    ll tmp = atk - d[i];
    turn[i] = (h[i] - 1) / tmp + 1;
  }
  vector<int> idx(n);
  for (int i = 0; i < n; i++) idx[i] = i;
  sort(idx.begin(), idx.end(),
       [&](int i, int j) { return turn[i] * dmg[j] < turn[j] * dmg[i]; });
  ll ret = 0, cnt = 0;
  for (auto i : idx) {
    hp -= cnt * a[i];
    ret += cnt * a[i];
    if (hp <= 0) {
      cout << -1 << endl;
      return 0;
    }
    cnt += turn[i];
    if (s[i] > spd) {
      hp -= turn[i] * a[i];
      ret += turn[i] * a[i];
    } else {
      turn[i]--;
      hp -= turn[i] * a[i];
      ret += turn[i] * a[i];
    }
    if (hp <= 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ret << endl;
}
