#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 40000


struct Info{
	ll HP,attack,guard,speed;
};

struct Data{
	Data(int arg_enemy_index,ll arg_rest_count,double arg_average_damage){
		enemy_index = arg_enemy_index;
		rest_count = arg_rest_count;
		average_damage = arg_average_damage;
	}
	bool operator<(const struct Data &arg) const{
 		return average_damage < arg.average_damage;
	}
	int enemy_index;
	ll rest_count;
	double average_damage;
};

int N;
Info Hero,monster[NUM];
ll start_HP,to_hero_damage[NUM];

int main(){

	scanf("%d",&N);

	scanf("%lld %lld %lld %lld",&Hero.HP,&Hero.attack,&Hero.guard,&Hero.speed);
	start_HP = Hero.HP;

	ll give_damage,promised_count;

	priority_queue<Data> Q;

	for(int i = 0; i < N; i++){
		scanf("%lld %lld %lld %lld",&monster[i].HP,&monster[i].attack,&monster[i].guard,&monster[i].speed);
		if(monster[i].attack <= Hero.guard){
			continue;
		}

		to_hero_damage[i] = monster[i].attack-Hero.guard;
		give_damage = Hero.attack-monster[i].guard;

		if(monster[i].guard >= Hero.attack){
			printf("-1\n");
			return 0;
		}

		if(monster[i].HP%give_damage == 0){
			promised_count = monster[i].HP/give_damage;
		}else{
			promised_count = monster[i].HP/give_damage+1;
		}
		Q.push(Data(i,promised_count,(double)to_hero_damage[i]/(double)promised_count));
	}

	ll turn = 0;

	while(!Q.empty()){

		turn += Q.top().rest_count;

		if(Hero.speed < monster[Q.top().enemy_index].speed){
			Hero.HP -= turn*to_hero_damage[Q.top().enemy_index];
		}else{
			Hero.HP -= (turn-1)*to_hero_damage[Q.top().enemy_index];
		}

		if(Hero.HP <= 0)break;

		Q.pop();
	}

	if(Hero.HP <= 0){
		printf("-1\n");
	}else{
		printf("%lld\n",start_HP-Hero.HP);
	}

	return 0;
}

