#include <bits/stdc++.h>
using namespace std;
class monster {
 public:
  long long int atk, SpellCounter;
  monster() {}
  monster(long long int atk_, int spell_) : atk(atk_), SpellCounter(spell_) {}
};
int main(void) {
  int n;
  cin >> n;
  long long int hero_h, hero_a, hero_d, hero_s;
  cin >> hero_h >> hero_a >> hero_d >> hero_s;
  long long int orig_h = hero_h;
  long long int sum = 0;
  long long int input_h, input_a, input_d, input_s;
  vector<pair<double, int> > rate;
  vector<monster> enemy;
  for (int i = 0; i < n; i++) {
    cin >> input_h >> input_a >> input_d >> input_s;
    long long int attack = max(input_a - hero_d, 0LL);
    if (input_s > hero_s) {
      hero_h -= attack;
    }
    if (hero_a <= input_d) {
      cout << -1 << endl;
      return 0;
    }
    sum += attack;
    long long int SpellCounter = ((input_h - 1) / (hero_a - input_d)) + 1;
    rate.push_back(make_pair(input_a / (double)SpellCounter, i));
    enemy.push_back(monster(attack, SpellCounter));
  }
  sort(rate.begin(), rate.end());
  reverse(rate.begin(), rate.end());
  for (int i = 0; i < n; i++) {
    long long int sc = enemy[rate[i].second].SpellCounter - 1;
    hero_h -= sc * sum;
    sum -= enemy[rate[i].second].atk;
    hero_h -= sum;
    if (hero_h <= 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << orig_h - hero_h << endl;
  return 0;
}
