#include <bits/stdc++.h>
struct Character {
  int health;
  int attack;
  int defence;
  int speed;
};
struct Enemy : public Character {
  bool defeatable;
  unsigned long long dameges_per_turn;
  unsigned long long turns_for_beat;
  Enemy() : defeatable(true) {}
};
std::istream& operator>>(std::istream& stream, Character& character) {
  return (stream >> character.health >> character.attack >> character.defence >>
          character.speed);
}
int main() {
  int enemy_length;
  std::cin >> enemy_length;
  Character player;
  std::cin >> player;
  std::vector<Enemy> enemies(enemy_length);
  for (auto& enemy : enemies) std::cin >> enemy;
  for (auto& enemy : enemies) {
    int damage_for_enemy = player.attack - enemy.defence;
    int damage_for_player = enemy.attack - player.defence;
    if (damage_for_enemy <= 0)
      enemy.defeatable = false;
    else
      enemy.turns_for_beat = enemy.health / damage_for_enemy +
                             (enemy.health % damage_for_enemy ? 1 : 0);
    enemy.dameges_per_turn = damage_for_player > 0 ? damage_for_player : 0;
    if (!enemy.defeatable) {
      std::cout << -1 << std::endl;
      return 0;
    }
  }
  std::sort(enemies.begin(), enemies.end(),
            [](const Enemy& lhs, const Enemy& rhs) {
              return (rhs.dameges_per_turn * lhs.turns_for_beat) <
                     (lhs.dameges_per_turn * rhs.turns_for_beat);
            });
  unsigned long long total_damages = 0;
  for (auto& enemy : enemies)
    if (player.speed < enemy.speed) total_damages += enemy.dameges_per_turn;
  unsigned long long total_turns = 0;
  for (auto& enemy : enemies) {
    total_turns += enemy.turns_for_beat;
    total_damages += enemy.dameges_per_turn * (total_turns - 1);
    if (player.health <= total_damages) {
      std::cout << -1 << std::endl;
      return 0;
    }
  }
  std::cout << total_damages << std::endl;
  return 0;
}
