#include <bits/stdc++.h>
using namespace std;
int N;
struct E {
  long long a, t;
  E(long long a, long long t) : a(a), t(t) {}
  bool operator<(const E& e) const {
    long long sa = a + e.a;
    if (sa * t + e.a * e.t < sa * e.t + a * t) {
      return true;
    }
    return false;
  }
};
struct st {
  long long h, a, d;
};
vector<E> En;
st me;
int ms;
long long Sa = 0;
long long rui[40004];
inline long long damage(int a, int d) { return a - d > 0 ? a - d : 0; }
inline long long kill_turn(int h, int a, int d) {
  a = damage(a, d);
  if (a == 0) return -1;
  return (h - 1) / a;
}
long long solve(long long dm) {
  sort(En.begin(), En.end());
  for (int i = N - 1; i > -1; i--) {
    rui[i] = rui[i + 1] + En[i].a;
  }
  for (int i = 0; i < N; i++) {
    dm += (rui[i] * En[i].t);
    if (i == N - 1) break;
    dm += rui[i + 1];
  }
  if (dm > me.h) return -1;
  return dm;
}
int main() {
  scanf("%d", &N);
  scanf("%lld %lld %lld %d", &me.h, &me.a, &me.d, &ms);
  long long res = 0;
  bool end = false;
  for (int i = 0; i < N; i++) {
    int h, a, d, s;
    scanf("%d %d %d %d", &h, &a, &d, &s);
    En.push_back(E(damage(a, (int)me.d), kill_turn(h, (int)me.a, d)));
    if (En[i].t == -1) end = true;
    Sa += En[i].a;
    if (s > ms) res += En[i].a;
  }
  if (end)
    puts("-1");
  else
    printf("%lld\n", solve(res));
}
