#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "sz:" << v.size() << "\n[";
  for (const auto& p : v) {
    os << p << ",";
  }
  os << "]\n";
  return os;
}
struct Enemy {
  ll hp;
  ll ap;
  ll sp;
  ll dp;
  bool operator>(const Enemy& e) const { return ap > e.ap; }
};
ostream& operator<<(ostream& os, const Enemy& v) {
  os << "[hp:" << v.hp << ",ap:" << v.ap << ",sp:" << v.sp << ",dp:" << v.dp
     << "]";
  return os;
}
int main() {
  int n;
  cin >> n;
  ll H, A, D, S;
  cin >> H >> A >> D >> S;
  vector<Enemy> enemy;
  for (int i = 0; i < n; i++) {
    ll h, a, d, s;
    cin >> h >> a >> d >> s;
    if (a - D <= 0) {
      continue;
    }
    if (A - d <= 0) {
      cout << -1 << endl;
      return 0;
    }
    enemy.push_back(Enemy{
        h,
        max(a - D, 0LL),
        s - S,
        max(A - d, 0LL),
    });
  }
  const int size = enemy.size();
  sort(enemy.begin(), enemy.end(), greater<Enemy>());
  vector<ll> turns(size);
  ll adv = 0;
  ll sum = 0;
  for (int i = 0; i < size; i++) {
    const auto& e = enemy[i];
    if (e.sp < 0) {
      adv += e.ap;
    }
    if (i == 0) {
      turns[i] = (e.hp + (e.dp) - 1) / e.dp;
    } else {
      turns[i] = turns[i - 1] + (e.hp + (e.dp) - 1) / e.dp;
    }
    sum += turns[i] * e.ap;
  }
  sum -= adv;
  if (sum > H) {
    cout << -1 << endl;
  } else {
    cout << sum << endl;
  }
  return 0;
}
