Split is a new mobile game that has recently exploded in popularity. In each level of Split, you are given two rows of non-negative integers that can be represented as arrays and
of size
. We label the first index of both arrays
and the last index
. The objective of Split is to beat each level by turning array
into array
.
In a split operation, you can split any index in
by redistributing its value to adjacent indices and setting
to
. For the case
and
, you may only redistribute its value to
and
, respectively. Note that only integer values may be distributed. The sum of values across all indices in
and
shall remain the same across all split operations,
.
For example, in one operation, you can redistribute in
to
, resulting in the array
. You can also redistribute
from the same array
to create one of
,
, or
. Finally, you can redistribute
from the same array
to
, resulting in
.
Unfortunately, the game is bugged and contains levels that are impossible to beat. The creator of Split knows that if the level can be solved, there is always a sequence of split operations that takes at most moves. Thus, determine if it is possible to transform array
into array
. If it is possible, determine a sequence of split operations that transforms array
into array
, taking at most
moves.
Constraints
Input Specification
The first line will contain 2 integers and
.
The next line will contain space seperated integers
.
The third and final line will contain space seperated integers
.
Output Specification
The first line of output should be -1
if the level of split is impossible, that is, there is no sequence of split operations that transforms array into array
. Otherwise, output a non-negative integer
indicating the number of split operations.
Each of the next lines should contain
space-separated integers
,
, and
, indicating the index to split, the value redistributed to the left, and the value redistributed to the right, respectively. Given the nature of the operation,
should equal the value of
before redistribution.
The number of moves does not have to be minimized and any valid sequence of operations such that are accepted.
Sample Input 1
15 6
2 5 1 0 2 5
8 1 1 0 2 3
Sample Output 1
7
6 5 0
5 4 3
4 2 2
3 3 0
2 6 2
3 1 1
4 1 0
Explanation For Sample Input 1
After each split operation, is as follows:
2 5 1 0 7 0
2 5 1 4 0 3
2 5 3 0 2 3
2 8 0 0 2 3
8 0 2 0 2 3
8 1 0 1 2 3
8 1 1 0 2 3
There may be multiple solutions. Output any valid one.
Sample Input 2
3 2
1 2
2 1
Sample Output 2
-1
Comments