Under construction

Still being built. Things may change

Taking Medicine

Time limit1sMemory limit1024 MB

Summary
Decide whether three doses a day, each taken right after a meal within a fixed window, can keep the effect of K minutes active without a gap for N days.
Level

Medium5 of 10

Topics
Greedy, Math, Simulation
Solved
No attempts yet

Problem

Yugyeom caught a cold, and the hospital gave him medicine for NN days. Yugyeom hates being sick, so once he starts the cold medicine, he wants the effect to last without a gap until he has finished the whole course.

Yugyeom must take the medicine three times a day, right after meals, and the effect lasts KK minutes. He can eat three meals a day, each within a fixed time window. The time spent eating and taking the medicine is ignored. Determine whether you can arrange the three meal times on each day so that the effect does not lapse until the last dose on day NN is taken.

Input

The first line contains the number of days NN and the duration of the effect KK, separated by a space. (1≤N≤100 000;1≤K≤1 440)(1 \leq N \leq 100\,000; 1 \leq K \leq 1\,440)

The second line contains As,Ae,Bs,Be,Cs,CeA_s,A_e,B_s,B_e,C_s,C_e separated by spaces, where 0≤As≤Ae<Bs≤Be<Cs≤Ce<1 4400 \leq A_s \leq A_e \lt B_s \leq B_e \lt C_s \leq C_e \lt 1\,440. Each pair gives the start and end, in minutes, of one of the three windows for meals. Day 1 runs from minute 0 to minute 1439, which is 1440 minutes in total.

All numbers in the input are integers.

Output

Print YES if the effect can last without a gap until the last dose on day NN is taken. Otherwise, print NO.

Examples3

  1. Example 1

    Input
    10 480
    360 360 840 840 1320 1320
    
    Expected output
    YES
    
  2. Example 2

    Input
    3 480
    360 360 820 820 1300 1300
    
    Expected output
    NO
    
  3. Example 3

    Input
    2 476
    360 380 840 860 1320 1340
    
    Expected output
    YES