acm International Collegiate Programming Contest

Links

A B C D E F G H

Problem G

Fair Deal of Dice

You are serving as the gamemaster of a two-player game in which several cubic dice are used. Each face of the dice has a number on it. Unlike conventional dice, the numbers are not necessarily one through six.

Before starting a game, you select a predefined number of dice from the set of dice at hand and deal them out to the two players. Here, the numbers of dice the two players receive are not necessarily the same, but both players receive at least one die.

Both of the players cast all of the dice dealt in some situations of the game. At that time, the greater the sum of the numbers on the top faces of the dice of a player is, the more advantage the player gains.

For more exciting games, selecting and dealing the dice in a way that achieves the least unfairness is the best.

Definition of the unfairness: Let x denote the sum of the numbers on the top of the dice of one player, and y denote that of the other player. The unfairness is defined as the expected value of (x − y)2. Here, each side of a die comes to the top with probability 1/6 independently of the other dice.

Please compute the minimum achievable unfairness with the dice at hand.

Input

The input consists of multiple datasets, each in the following format.

nm
a1,1a1,2a1,3a1,4a1,5a1,6
 ⋮
an,1an,2an,3an,4an,5an,6

n is the number of dice you have, and m is the number of dice you select to deal to players. n and m are integers that satisfy 2 ≤ mn ≤ 60. aij gives the number on the j-th face of the i-th die. aij is an integer that satisfies 0 ≤ aij ≤ 60.

The end of the input is indicated by a line consisting of two zeros. The number of datasets does not exceed 100.

Output

For each dataset, output the minimum achievable value of the unfairness multiplied by 36 in a line. Note that this value can be proved to be an integer.

Sample Input

4 3
1 2 3 4 5 6
10 10 10 20 20 20
10 11 12 13 14 15
60 0 60 0 60 0
2 2
0 0 0 0 0 0
60 60 60 60 60 60
8 6
58 43 60 42 53 37
13 41 55 4 21 50
35 13 54 43 24 5
40 60 57 48 60 32
51 32 58 44 60 52
40 29 25 22 0 44
31 22 26 30 49 23
16 34 4 40 21 6
0 0

Output for the Sample Input

1146
129600
31878
(End of Problem G) A B C D E F G H