A factory is scheduled to operate from the night of day through the night of day . Work is divided into daytime and nighttime shifts. In chronological order there are shifts: the night of day , the day and night of day , the day and night of day , and so on through the day and night of day . The factory produces goods during each daytime shift and is guarded during each nighttime shift.
The factory must recruit workers from applicants. Applicant () has skill and contribution . All skill values are distinct. If applicant is hired, they work during the night of day , the day of day , and the night of day , and receive base pay . Each hired worker therefore works on two guard shifts and one production shift.
During each shift, all workers on duty line up in order of increasing skill and form pairs from the front of the line. If there are workers, the people in positions and form a pair for every integer ().
Work can only be done in pairs. Hire workers so that the number on duty is even in every shift. A shift may have no workers, in which case nothing happens during that shift.
Each pair has the following effect, depending on the work it does.
Before the factory starts operating, before the night of day , its total production profit is .
The total pay is the sum of the base pay of the hired workers and the extra pay paid on all nights.
Given the data for the applicants, find the maximum value of (total production profit) − (total pay) and a list of workers to hire that achieves it.
The first line contains two integers and , in that order, separated by a space.
The next lines describe the applicants. Line of these () contains four space-separated integers describing applicant , in that order.
On the first line, print the maximum value of (total production profit) − (total pay).
On the next line, print the number of workers to hire.
On the next line, print the indices of those workers in any order, separated by spaces. If , you may print an empty line or omit the line.
If more than one output is valid, any one is accepted.
An optimal choice is to hire applicants and for the daytime shift on day , and applicants and for the daytime shift on day .
| 4 | 22 | For each integer (), at most applicants satisfy . |
| 5 | 31 | No additional constraints. |
Thus the total production profit is .
The total extra pay is .
The total pay is , consisting of base pay and extra pay . The final value of (total production profit) − (total pay) is .
Note that the pairs on the day and night shifts of day are different.
Hiring nobody is optimal.