#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
#define INF (1000000000)
ll N;
struct E{
  ll a,t;
  E(){}
  E(ll a,ll t) :  a(a),t(t) {}
};
bool operator < (const E& s,const E& e){  
    ll sa = s.a+e.a;
    //    printf("%lld*%lld + %lld*%lld < %lld*%lld + %lld*%lld\n",
    //	   sa,t,e.a,e.t,sa,e.t,s.a,s.t);
    if(sa*s.t+e.a*(e.t+1) < sa*e.t+s.a*(s.t+1)){
      return true;
    }
    return false;
}  
struct st{
  ll h,a,d;
};
E En[40004];
st me;
ll ms;

ll rui[40004];

inline ll damage(ll a,ll d){
  return max(a-d,(ll)0);
}
inline ll kill_turn(ll h,ll a,ll d){
  a = damage(a,d);
  if(a==0) return INF;
  //  printf("%lld %lld return = %lld\n",h,a,(h-1)/a);
  return (h-1)/a;
}

ll solve(ll dm){
  if(dm >= me.h) return -1;
  sort(En,En+N);
  for(ll i=N-1;i>-1;i--){
    rui[i]=rui[i+1]+En[i].a;
  }
  for(ll i=0;i<N;i++){
    //            printf("id=%lld a=%lld t=%lld  rui=%lld\n",i,En[i].a,En[i].t,rui[i]);
    dm += (rui[i]*En[i].t);
    //    printf("damage = %lld\n",dm);
    if(i==N-1) break;
    
    if(dm >= me.h) return -1;
    dm += rui[i+1];

    if(dm >= me.h) return -1;
    //    printf("damage = %lld\n",dm);
  }
  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);
  ll res = 0;
  bool end = false;
  for(ll i=0;i<N;i++){
    ll h,a,d;
    ll 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));
}