Олимпиадный тренинг

Задача 38318. Weighing


Two-pan balances and a set of weights are given. An object weighing K grams is placed on the left side of the scale. Is it possible to bring the scales to a state of equilibrium, and if so, determine for each scale pan which weights need to be placed on it for this. Available weights are allowed to be placed on any of the scales (each weight is available only in one copy, some weights may not be used).

Input
Entered first K — the weight of the item placed on the left bowl (1≤K≤50). Next, the total number of weights N (1≤N≤10) is recorded. Next, N different natural numbers are written, not exceeding 50, — weights.

Imprint
On the first line print the weights of the weights to be placed on the left scale pan, on the second line print — weights to be placed on the right bowl. If no weights need to be placed on some bowl — print the number 0 in this line. If it is impossible to balance the scales with the help of these weights, print the single number –1. If there are several options, print any of them.
 
Examples
# Input Output
1 5
2
3 5
0
5
2 5
3
6 3 4
4
36
3 5
1
2
-1