Stepan's Exercises
Stepan is determined to excel not only in competitive programming but also in sports. However, it's been a while since his last workout, so he needs to start from scratch to get back in shape.
Finding suitable exercises proved challenging, so Stepan turned to the Internet for inspiration. He discovered a website offering several training series, each lasting N days. For each of these N days, there is an "exercise of the day" with recommendations on how many times to perform it, specified as "A_i - B_i". This means the exercise should be done between A_i and B_i times to effectively build strength. Doing it fewer than A_i or more than B_i times could be counterproductive. To avoid injury, Stepan will perform the exercise within the recommended range or not at all.
After reviewing the exercises, Stepan realized the course was not beginner-friendly, but he decided to adapt it to his level. He knows that learning the i-th exercise will cost him K_i strength levels, but performing it X times will increase his strength by F_i*X. Stepan cannot attempt an exercise if his current strength level is below K_i. On days when he lacks the strength or time, he can skip the workout, and his strength level will remain unchanged. Stepan also knows that if he performs an exercise more than T times in one day, he will need to rest for the next D days.
If Stepan exceeds T repetitions on any of the last T days of the series, he will begin his rest period the following day, continuing beyond the series' end. Stepan aims to maximize his strength gains over the N days. For each training series, help him determine the highest strength level he can achieve by the end. Initially, Stepan's strength level is zero.
**Input Format:** The first line contains a single integer N (1 ≤ N ≤ 10^5) - the number of training days.
The second line contains two integers T, D (1 ≤ T ≤ 10^6, 1 ≤ D ≤ 10^5), indicating that if Stepan performs an exercise more than T times on any day, he must rest for the next D days. The following N lines describe the exercises, with the i+2-th line detailing the exercise for day i. Each exercise is described by the numbers A_i, B_i, K_i, F_i, (0 ≤ K_i ≤ 10^9, 1 ≤ A_i ≤ B_i ≤ 10^6, 1 ≤ F_i ≤ 10^6), separated by spaces, where A_i, B_i are the recommended minimum and maximum repetitions, K_i is the strength level lost when learning the exercise, and F_i is the strength level gained per repetition.
**Output Format:** The first line should contain a single integer S - the maximum strength level Stepan can achieve by the end of the training. The second line should list N integers X_i - the number of times the exercise was performed on day i. If he rested on day i, output 0.
**Explanation of Examples:**
To maximize strength, on the first day, the exercise should be performed 4 times to avoid resting the next day. On the second day, Stepan can gain 790 strength levels (losing 10 levels when learning and performing the exercise 8 times), but he will then need to rest on the third day.
On the fourth day, he gains 48 levels, and since he performed the exercise more than 4 times, he must skip the fifth day.