Butterfly Effect

Decide adaptively where to spend up to k double-die rolls across n chained chance events to maximize the chance the last event ends positive.

Hard8Dynamic programmingProbabilityNo attempts yetTime limit5sMemory limit256 MB

Problem

There are nn events about to happen. Each event ends with a positive outcome or a negative outcome, and that outcome changes the odds of the events that come later.

The events happen in the order given in the input. Event ii carries an integer base value bib_i. To settle an event you roll a fair die whose faces are marked 11 through mm and add the rolled number to the base value. If the sum is strictly greater than 00, the outcome is positive. Otherwise the outcome is negative, and a sum of exactly 00 counts as negative. If event ii ends positive, the base value of every later event jj becomes bj+pijb_j + p_{ij}. If it ends negative, that base value becomes bj+qijb_j + q_{ij}. All dice are rolled independently.

You have the power to intervene in an event. When you intervene, you roll two dice instead of one, look at both numbers, and keep the one you prefer. You decide whether to intervene immediately before that event's die is rolled, so you may use the outcomes of the earlier events to make the decision. You may intervene at most kk times. Compute the largest possible probability that event nn ends positive.

Input

The first line contains three integers nn, kk, and mm separated by spaces (1kn201 \le k \le n \le 20, 4m10004 \le m \le 1000): the number of events, the maximum number of interventions, and the number of faces on the die. The base values and the modifiers follow on 3n3n lines. Line numbers are counted from the first line of the input.

  • Line 3i13i - 1: the base value bib_i of event ii, with absolute value at most 20002000.
  • Line 3i3i: nin - i integers pi,i+1,,pi,np_{i,i+1}, \dots, p_{i,n} separated by spaces, the amounts added to the base values of events i+1i + 1 through nn when event ii ends positive.
  • Line 3i+13i + 1: the values qi,i+1,,qi,nq_{i,i+1}, \dots, q_{i,n} used when event ii ends negative, in the same format.

Every modifier has absolute value at most 20002000. The last event has no modifiers, so the final two lines of the input are empty.

Output

Print on a single line the largest possible probability that the last event ends positive, rounded to six digits after the decimal point. Always print exactly six digits after the decimal point.