#include <bits/stdc++.h>
using namespace std;
class Data {
 public:
  long long h, a, d, s;
  bool operator<(const Data& other) const { return h * other.a < other.h * a; }
};
int main() {
  int n;
  cin >> n;
  Data usagi;
  cin >> usagi.h >> usagi.a >> usagi.d >> usagi.s;
  vector<Data> enemy(n);
  for (int i = 0; i < n; ++i)
    cin >> enemy[i].h >> enemy[i].a >> enemy[i].d >> enemy[i].s;
  for (int i = 0; i < n; ++i) {
    int damage = usagi.a - enemy[i].d;
    if (damage <= 0) {
      cout << -1 << endl;
      return 0;
    }
    enemy[i].h = (enemy[i].h + damage - 1) / damage;
    if (enemy[i].s > usagi.s)
      enemy[i].s = 0;
    else
      enemy[i].s = 1;
    enemy[i].a -= usagi.d;
  }
  sort(enemy.begin(), enemy.end());
  vector<long long> sum(n, 0);
  for (int i = n - 1; i > 0; --i) sum[i - 1] = sum[i] + enemy[i].a;
  long long ret = 0;
  for (int i = 0; i < n; ++i) {
    ret += (enemy[i].h - enemy[i].s) * enemy[i].a;
    ret += enemy[i].h * sum[i];
  }
  if (ret < usagi.h)
    cout << ret << endl;
  else
    cout << -1 << endl;
  return 0;
}
