#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int N,H,A,D,S;
int h,a,d,s;
vector<ll> x,y;
int t[40000];

ll sum,cnt;

bool f(const int &a,const int &b){
  ll A=x[a]*(y[a]-1)+x[b]*(y[a]+y[b]-1);
  ll B=x[b]*(y[b]-1)+x[a]*(y[a]+y[b]-1);
  return (A<B);
}

int solve(){
  N=x.size();
  for(int i=0;i<N;i++){
    t[i]=i;
    cnt+=x[i];
  }
  if(H<=sum)return -1;  
  sort(t,t+N,f);
  for(int i=0;i<N;i++){
    int id=t[i];
    sum+=x[id]*(y[id]-1);
    cnt-=x[id];
    sum+=cnt*y[id];
    if(H<=sum)return -1;
  }
  return sum;
}

int main(){
  scanf("%d %d %d %d %d",&N,&H,&A,&D,&S);
  for(int i=0;i<N;i++){
    scanf("%d %d %d %d",&h,&a,&d,&s);
    if(s>S)sum+=(max(a-D,0));
    if( a-D <= 0 )continue;
    if( A-d <= 0 ){
      cout<<-1<<endl;
      return 0;
    }
    x.push_back( a-D );
    y.push_back( (h+A-d-1)/(A-d) );
  }
  cout<<solve()<<endl;      
  return 0;  
}