Under construction

Still being built. Things may change

Training, Round 2

Time limit6sMemory limit2048 MB

Summary
Given n problems with implementation and thinking skill ranges, find the most problems Ashley can solve in order when each solve raises one of her skills by one.
Level

Medium6 of 10

Topics
Dynamic programming, Intervals, Bit manipulation
Solved
No attempts yet

Problem

Ashley is training for another programming contest on Brandon's Online Judge. The judge still lets Ashley's coach, Tom, load a list of problems for Ashley to work on.

Tom has curated some problems. Each problem has an implementation difficulty range and a thinking difficulty range. Ashley starts with an implementation skill ii and a thinking skill tt. She looks at the problems in the order Tom loaded them, and for each one she either solves it or skips it. Once she skips a problem, she cannot go back to it.

Ashley can solve a problem only if both her current implementation skill and her current thinking skill are inside that problem's ranges, endpoints included. After each solved problem, she reflects and raises either her implementation skill or her thinking skill by one. She cannot raise both at once, and she cannot skip the reflection.

Find the maximum number of problems Ashley can solve if she chooses her reflections optimally.

Input

The first line contains three integers nn, ii, and tt (1≤n≤50001 \le n \le 5000, 0≤i,t≤1090 \le i, t \le 10^9), where nn is the number of problems, ii is Ashley's starting implementation skill, and tt is her starting thinking skill.

Each of the next nn lines contains four integers ilowi_{low}, ihighi_{high}, tlowt_{low}, and thight_{high} (0≤ilow≤ihigh≤2⋅1090 \le i_{low} \le i_{high} \le 2 \cdot 10^9, 0≤tlow≤thigh≤2⋅1090 \le t_{low} \le t_{high} \le 2 \cdot 10^9). Each line describes one problem. Its implementation range is [ilow,ihigh][i_{low}, i_{high}] and its thinking range is [tlow,thigh][t_{low}, t_{high}], both inclusive.

Output

Print one integer, the maximum number of problems Ashley can solve when she chooses her reflections optimally.

Examples1

  1. Example 1

    Input
    3 0 0
    0 1 0 1
    1 1 0 1
    1 1 1 1
    
    Expected output
    3