#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);
struct Enemy {
  long long cnt;
  long long attack;
  int after;
  Enemy() { ; }
  Enemy(long long cnt, long long attack, int after)
      : cnt(cnt), attack(attack), after(after) {
    ;
  }
  bool operator<(const Enemy &rhs) const {
    return rhs.cnt * attack < cnt * rhs.attack;
  }
};
int n;
long long h, a, d, s;
int main() {
  while (scanf("%d", &n) > 0) {
    scanf("%lld %lld %lld %lld", &h, &a, &d, &s);
    long long attackSum = 0;
    vector<Enemy> enemys;
    bool ng = false;
    for (int i = 0; i < (int)(n); i++) {
      long long eh, ea, ed, es;
      scanf("%lld %lld %lld %lld", &eh, &ea, &ed, &es);
      long long attack = ea - d;
      long long damage = a - ed;
      if (attack <= 0) {
        continue;
      }
      if (damage <= 0) {
        ng = true;
        continue;
      }
      long long cnt = (eh + damage - 1) / damage;
      int after = 0;
      if (es < s) {
        after = 1;
      }
      attackSum += attack;
      enemys.push_back(Enemy(cnt, attack, after));
    }
    if (ng) {
      puts("-1");
      continue;
    }
    long long ans = 0;
    sort(enemys.rbegin(), enemys.rend());
    for (__typeof((enemys).begin()) it = (enemys).begin(); it != (enemys).end();
         it++) {
      attackSum -= it->attack;
      ans += attackSum * it->cnt;
      long long cnt = it->cnt;
      if (it->after) {
        cnt--;
      }
      ans += it->attack * cnt;
    }
    if (h <= ans) {
      puts("-1");
    } else {
      printf("%lld\n", ans);
    }
  }
}
