AT_abc432_f [ABC432F] Candy Redistribution
Description
There are $ N $ children, numbered $ 1 $ to $ N $ .
Child $ i $ has $ A_i $ candies.
Your goal is to execute the following operation as few times as possible so that eventually all $ N $ children have the same number of candies.
- Choose two distinct children $ x,y $ , and choose a positive integer $ z $ not exceeding the number of candies child $ x $ has. Take $ z $ candies from child $ x $ and give them to child $ y $ .
Determine whether there exists a sequence of operations such that eventually all $ N $ children have the same number of candies. If it exists, find one such sequence with the minimum number of operations.
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ A_1 $ $ \dots $ $ A_N $
Output Format
If there is no sequence of operations such that eventually all $ N $ children have the same number of candies, output `-1`.
If it exists, output one with the minimum number of operations in the following format:
> $ q $ $ x_1 $ $ y_1 $ $ z_1 $ $ \vdots $ $ x_q $ $ y_q $ $ z_q $
Here, $ q $ represents the number of operations, and $ x_i,y_i,z_i $ represent the values of $ x,y,z $ chosen in the $ i $ -th operation.
If there are multiple solutions, outputting any of them will be considered correct.
Explanation/Hint
### Sample Explanation 1
In this sample output, the operations are executed as follows:
1. Take $ 1 $ candy from child $ 2 $ and give it to child $ 3 $ . Immediately after this, the number of candies each child has is $ 1,6,5,8 $ .
2. Take $ 1 $ candy from child $ 2 $ and give it to child $ 4 $ . Immediately after this, the number of candies each child has is $ 1,5,5,9 $ .
3. Take $ 4 $ candies from child $ 4 $ and give them to child $ 1 $ . Immediately after this, the number of candies each child has is $ 5,5,5,5 $ .
Eventually, all $ N $ children have exactly five candies each.
### Constraints
- $ 2 \leq N \leq 20 $
- $ 1 \leq A_i \leq 10^8 $
- All input values are integers.