#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Enemy {
  ll cnt;
  ll attack;
  int after;
  Enemy() {;}
  Enemy(ll cnt, ll attack, int after)
    : cnt(cnt), attack(attack), after(after) {;}
  bool operator<(const Enemy &rhs) const {
    return rhs.cnt * attack < cnt * rhs.attack;
  }
};

int n;
ll h, a, d, s;
int main() {
  while (scanf("%d", &n) > 0) {
    scanf("%lld %lld %lld %lld", &h, &a, &d, &s);
    ll attackSum = 0;
    vector<Enemy> enemys;
    bool ng = false;
    REP(i, n) {
      ll eh, ea, ed, es;
      scanf("%lld %lld %lld %lld", &eh, &ea, &ed, &es);
      ll attack = ea - d;
      ll damage = a - ed;
      if (attack <= 0) { continue; }
      if (damage <= 0) { ng = true; continue; }
      ll 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; }
    ll ans = 0;
    sort(enemys.rbegin(), enemys.rend());
    FORIT(it, enemys) {
      attackSum -= it->attack;
      ans += attackSum * it->cnt;
      ll cnt = it->cnt;
      if (it->after) { cnt--; }
      ans += it->attack * cnt;
      if (ans >= h) { break; }
    }
    if (h <= ans) {
      puts("-1");
    } else {
      printf("%lld\n", ans);
    }
  }
}