#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

n = input()
H, A, D, S = map(int, raw_input().split())
ans = 0
flag = False
ls = []
for i in range(n):
    h, a, d, s = map(int, raw_input().split())
    a -= D
    if s < S:
        ans -= max(0, a)
    if A <= d and a > 0:
        flag = True
    elif a > 0:
        turn = h / (A - d)
        if h % (A - d) != 0:
            turn += 1
        ls.append((turn / float(a), turn, a))
if flag:
    print -1
    exit()
ls.sort()
S = 0
for p in ls:
    S += p[1]
    ans += S * p[2]
if ans < H:
    print ans
else:
    print -1

