#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int INF = (1 << 30);
struct Status {
  double h, a, d, s;
  double turn(const Status& p) const {
    if (p.a == d) return -1;
    return ceil(h / (p.a - d));
  }
  double power(const Status& p, long long t = 0) const {
    if (t == 0) {
      return (a - p.d) * (turn(p) + (s > p.s ? 0 : -1));
    } else {
      return (a - p.d) * (t + (s > p.s ? 0 : -1));
    }
  }
};
int n;
Status player;
vector<Status> enemy;
void input() {
  double a, b, c, d;
  cin >> n;
  cin >> a >> b >> c >> d;
  player = Status({a, b, c, d});
  for (int((i)) = (0); ((i)) < ((n)); ((i))++) {
    cin >> a >> b >> c >> d;
    enemy.push_back(Status({a, b, c, d}));
  }
}
void calc() {
  sort(enemy.begin(), enemy.end(), [&](const Status& lth, const Status& rth) {
    return lth.power(player) < rth.power(player);
  });
  for (auto e : enemy) {
  }
  long long damage = 0;
  long long turn = 0;
  while (!enemy.empty()) {
    auto nowE = enemy.back();
    enemy.pop_back();
    auto t = nowE.turn(player);
    if (t < 0) {
      cout << -1 << endl;
      return;
    }
    turn += t;
    damage += nowE.power(player, turn);
  }
  if (damage >= player.h) {
    cout << -1 << endl;
  } else {
    cout << damage << endl;
  }
}
void output() {}
void debug() {
  int N;
  cin >> N;
}
int main() {
  input();
  calc();
  output();
  debug();
  return 0;
}
