New Year Festival

아직 제출이 없습니다시간 제한7초메모리 제한1024 MB

문제

The ICPC (Incredibly Colossal and Particularly Comfortable) Theater is giving a number of traditional events to celebrate the New Year!

Each of the events has its own unalterable duration. Start times of the events are flexible as long as no two events overlap. An event may start immediately after another event ends.

Start times of the events influence the costs. The cost of an event is given by a continuous piecewise linear function (a polygonal line function) of its start time. Different events may have different cost functions.

You are asked to schedule all the events minimizing the total cost.

입력

The input consists of a single test case of the following format.

nn

Description_1\text{Description}\_1

\vdots

Description_n\text{Description}\_n

The first line contains an integer nn, representing the number of events. 2n112 ≤ n ≤ 11 holds. The descriptions of the events follow. The description of the ii-th event, Description_i\text{Description}\_i (1in1 ≤ i ≤ n), has the following format.

mm ll

x_1x\_1 y_1y\_1

\vdots

x_mx\_m y_my\_m

The integer mm in the first line is the number of vertices of the cost function of the event. The integer ll in the same line is the duration of the event. 1m601 ≤ m ≤ 60 and 1l1081 ≤ l ≤ 10^8 hold.

The following mm lines describe the cost function. The jj-th line of the mm lines consists of the two integers x_jx\_j and y_jy\_j specifying the jj-th vertex of the cost function. 0x_1<<x_m1080 ≤ x\_1 < \cdots < x\_m ≤ 10^8 and 0y_j1080 ≤ y\_j ≤ 10^8 hold. In addition, (y_j+1y_j)/(x_j+1x_j)(y\_{j+1} - y\_j)/(x\_{j+1} - x\_j) is an integer for any 1j<m1 ≤ j < m.

The start time tt of the event must satisfy x_1tx_mx\_1 ≤ t ≤ x\_m. For jj (1j<m1 ≤ j < m) satisfying x_jtx_j+1x\_j ≤ t ≤ x\_{j+1}, the cost of the event is given as y_j+(tx_j)×(y_j+1y_j)/(x_j+1x_j)y\_j + (t - x\_j) \times (y\_{j+1} - y\_j)/(x\_{j+1} - x\_j).

The total number of the vertices of all the cost functions is not greater than 6060.

출력

Output the minimum possible total cost of the events in a line.

It is guaranteed that there is at least one possible schedule containing no overlap. It can be proved that the answer is an integer.

힌트

For Sample Input 1, making the (start time, end time) pairs of the three events to be (330,380)(330, 380), (380,500)(380, 500), and (170,330)(170, 330), respectively, achieves the minimum total cost without event overlaps. The cost of the event 11 is 2500+(330300)×(02500)/(350300)=10002500 + (330 - 300) \times (0 - 2500)/(350 - 300) = 1000. Similarly, the costs of the events 22 and 33 are 00 and 460460, respectively.

For Sample Input 2, the minimum cost is achieved by (384,544)(384, 544), (104,384)(104, 384), (544,704)(544, 704), and (720,960)(720, 960) for the four events.

Figure K.1. Cost functions in Sample Input 1 and a sample schedule

Figure K.2. Cost functions in Sample Input 2 and a sample schedule

In Figures K.1 and K.2, polylines in the top figure represent cost functions, and rectangles in the bottom figure represent event durations of a schedule achieving the minimum total cost.