Amazing Race#7539

Amazing Race

2 seconds
256 megabytes
Hard

A scavenger hunt is being organized for programming contest participants. In addition to the starting and ending locations of the race, there are (n \le 20) other locations for competitors to travel to. At each location (1 \le i \le n), there is a task that must be performed to earn p_i points. The task at each location takes t_i minutes to complete. However, each task can only be performed once, so a competitor may not travel to the same location more than once. The competitor cannot return to the starting location after the race begins, and the race finishes as soon as the ending location is reached.

The scavenger hunt must be completed within minutes. That is, the time between leaving the starting location and arriving at the ending location must be no more than minutes. In addition, some tasks have a specific deadline d_i, meaning that the task must be completed within d_i minutes since leaving the starting location. Again, note that if a competitor arrives at location , the task at location must be performed. If the competitor were to arrive at the location too late and would not finish the task at that location by the deadline, then the competitor would not be allowed to travel to the location at all.

What is the maximum total number of points that can be obtained from the tasks?

Input

The first line contains two positive integers and (t \le 1440). Each of the next lines contains three integers p_i (1 \le p_i \le 100), t_i (1 \le t_i \le 1440), and d_i (-1 \le d_i \le 1440). If d_i = -1 then there is no deadline for task . Finally, the last n + 2 lines each contains n + 2 nonnegative integers. The entry in the -th row and -th column is the number of minutes () it takes to travel from location to location . The indices of the starting and ending locations are n + 1 and n + 2, respectively.

It is guaranteed that the time to travel from a location to itself is , but the time to travel between two locations in different directions may not be the same (e.g. uphill instead of downhill).

Output

Print the maximum total number of points that can be obtained on the first line. In the second line, print a set of indices of the tasks that need to be performed to achieve this maximum. The indices should be separated by a single space. If there are multiple sets of tasks that can achieve the maximum, print the one that is lexicographically smallest. That is, if two sets of tasks achieve the same maximum, the index of the first task in the set should be as small as possible. If there is a tie, the index of the second task in the set should be as small as possible, and so on.

If the maximum number of points that can be obtained is , output a blank line for the indices of the tasks to be performed.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading