#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <numeric>

#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

typedef long long ll;

inline int getInt(){ int s; scanf("%d", &s); return s; }

int main(){
  int n = getInt();
  vector<int> h(n);
  vector<int> a(n);
  vector<int> d(n);
  vector<int> s(n);
  vector<int> memo(n);
  vector<pair<double, int> > c(n);

  int hh = getInt();
  int aa = getInt();
  int dd = getInt();
  int ss = getInt();
  ll ans = 0;
  ll tm  = 0;

  REP(i,n){
    h[i] = getInt();
    a[i] = getInt();
    d[i] = getInt();
    s[i] = getInt();
    ll dam = aa - d[i];

    if(dam <= 0){
      if(a[i] - dd <= 0){
	i--;
	n--;
	continue;
      }else{
	goto bad;
      }
    }

    memo[i] = (h[i] + dam - 1) / dam;

    if(s[i] > ss)
      c[i].first = (double)max(0, a[i] - dd) / (memo[i]);
    else
      c[i].first = (double)max(0, a[i] - dd) / (memo[i]);
    c[i].second = i;
  }

  c.resize(n);

  sort(c.rbegin(), c.rend());

  REP(i,n){
    int ii = c[i].second;
    int tt = memo[ii] - 1;

    if(s[ii] > ss) tt++;
    ans += (tm + tt) * max(0, a[ii] - dd);
    if(ans >= hh) goto bad;    
    tm  += memo[ii];
  }

  printf("%d\n", (int)ans);

  return 0;

 bad:
  puts("-1");

  return 0;
}