Choo Choo

Passengers request trips between numbered cities with per-person fares, and the train picks whom to board within its capacity to maximize total fare revenue.

Medium7GraphShortest pathDynamic programmingNo attempts yetTime limit1sMemory limit256 MB

Problem

A train runs from city 1 to city NN. It passes the cities in increasing order of their numbers: city 1, city 2, city 3, and so on up to city NN. At most PP people can be on the train at any moment.

Ai,jA_{i,j} people want to travel from city ii to city jj, and the fare for that trip is Ci,jC_{i,j} per person. A passenger boards only at the city they start from and gets off only at the city they are going to. The train picks freely which of the waiting people to take, and a person is either taken in full or not taken at all.

Write a program that computes the largest revenue the train can earn.

Input

The first line contains the number of cities NN and the train capacity PP. (1N501 \le N \le 50, 1P1001 \le P \le 100)

The next N1N-1 lines contain the numbers of people. The jj-th number on the ii-th line is Ai,i+jA_{i,i+j}, the number of people who want to go from city ii to city i+ji+j. The ii-th line has NiN-i numbers. (0Ai,j1000 \le A_{i,j} \le 100)

The next N1N-1 lines contain the fares. The jj-th number on the ii-th line is Ci,i+jC_{i,i+j}, the fare per person from city ii to city i+ji+j. The ii-th line has NiN-i numbers. (1Ci,j1001 \le C_{i,j} \le 100)

If NN is 1, both tables are empty and the input ends after the first line.

Output

Print the largest revenue the train can earn.

Hint

In the first example the train earns the most with the following plan.

At city 1 it takes 2 people going from city 1 to city 2, 2 people going from city 1 to city 3, and 1 person going from city 1 to city 4. The revenue so far is 5×2+3×2+4×1=205 \times 2 + 3 \times 2 + 4 \times 1 = 20.

At city 2 it drops the 2 people going to city 2 and takes 4 people going from city 2 to city 3. The revenue becomes 20+6×4=4420 + 6 \times 4 = 44.

At city 3 it drops the 2 people who came from city 1 and the 4 people who came from city 2, then takes 6 people going from city 3 to city 4. The revenue becomes 44+1×6=5044 + 1 \times 6 = 50.

At city 4 everyone left on board gets off. The final revenue is 50.