Minimum Weight

You have to weigh all integral weights from 1 to N. You can use weights in either pan. Such as if you have weight 2 and 3. You can weigh 1 using 3 in one pan and 2 in other pan. You can also weigh 5 (3 + 2 = 5) though you cannot weigh 4. For a given N, you have to find out minimum number of weights which are enough to weigh any integral weight from 1 to N. Input The input file contains several sets of inputs. The description of each set is given below: First line of each set contains two integers N (Fits within signed 64-bit integer) and K (0 ≤ K ≤ 100). The next line contains K positive integers less than N. You have to show a combination of weights which will make those weights. Input is terminated by a case where N and K both are zero. This case should not be processed. Output For each set of input produce (K + 1) lines of output. In the first line print the total number of weights required to measure all the integral weights from 1 to N. For each input print minimum number of weights required followed by the weights in ascending order. If multiple output is possible, take the combination which contains largest weights. Next show the combination of these weights to make the weight for each query. The weights should be in descending order irrespective of sign. Sample Input 82 34 13 5 7 8 10 11 12 00 Sample Output 3139 3 3+1 3139 9-3+1 9-1 9+1 9+3-1 9+3