#include <bits/stdc++.h>
using namespace std;
long long N;
struct E {
  long long a, t;
  E() {}
  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;
};
E En[40004];
st me;
long long ms;
long long rui[40004];
inline long long damage(long long a, long long d) {
  return max(a - d, (long long)0);
}
inline long long kill_turn(long long h, long long a, long long d) {
  a = damage(a, d);
  if (a == 0) return -1;
  return (h - 1) / a;
}
long long solve(long long dm) {
  if (dm >= me.h) return -1;
  sort(En, En + N);
  for (long long i = N - 1; i > -1; i--) {
    rui[i] = rui[i + 1] + En[i].a;
  }
  for (long long i = 0; i < N; i++) {
    dm += (rui[i] * En[i].t);
    if (i == N - 1) break;
    if (dm >= me.h) return -1;
    dm += rui[i + 1];
    if (dm >= me.h) return -1;
  }
  if (dm >= me.h) return -1;
  return dm;
}
int main() {
  scanf("%d", &N);
  scanf("%lld %lld %lld %lld", &me.h, &me.a, &me.d, &ms);
  long long res = 0;
  bool end = false;
  for (long long i = 0; i < N; i++) {
    long long h, a, d;
    long long s;
    scanf("%lld %lld %lld %lld", &h, &a, &d, &s);
    En[i] = E(damage(a, me.d), kill_turn(h, me.a, d));
    if (En[i].t == -1) end = true;
    if (s > ms) res += En[i].a;
  }
  if (end)
    printf("-1\n");
  else
    printf("%lld\n", solve(res));
}
