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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;


#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  LL mh, ma, md, ms; cin >> mh >> ma >> md >> ms;
  vector<PLL> en;
  LL dsum = 0;
  REP(i,N){
	LL h, a, d, s; cin >> h >> a >> d >> s;
	if(ma <= d){
	  if(a-md > 0){
		cout << -1 << endl;
		return 0;
	  }
	  continue;
	}
	en.EB((h - 1) / (ma - d) + 1, max(0LL,a-md));
	if(s < ms) dsum -= en.back().SS;
  }

  N = SZ(en);
  sort(ALL(en), [](PLL& p1, PLL& p2){
	  return p1.FF*p2.SS < p1.SS*p2.FF;
	});

  LL tsum = 0;
  for(int i=0;i<N;++i){
	tsum += en[i].FF;
	dsum += tsum * en[i].SS;
	if(dsum >= mh) break;
  }
  cout << (dsum >= mh? -1: dsum) << endl;
  
  return 0;
}