#P10949. 四叶草魔杖
四叶草魔杖
Problem Description
Freda, the guardian of the wand, merged four weapons. Then, at the top of the wand, a four-leaf clover slowly grew, and its four leaves shimmered with faint seven-colored light.
Rainbow, the guardian of the holy sword, took out a disk. On the disk, there are gems, numbered from to . The energy of the -th gem is .
If , it means the energy of this gem is too high, and it needs to transfer units of energy to other gems. If , it means the energy of this gem is too low, and it needs to obtain units of energy from other gems.
It is guaranteed that .
Only when all gems have the same energy can you insert the Clover Wand into the center of the disk and open the passage to the supernatural world.
However, energy can be transferred only between pairs of gems. For the -th pair, no matter how much energy is transferred, it costs .
The explorers want to know the minimum total cost needed to make the energy of all gems equal.
Input Format
The first line contains two integers .
The second line contains integers .
The next lines each contain three integers , meaning that transferring energy between the gems numbered and costs .
The testdata guarantees that each pair appears at most once.
Output Format
Output one integer representing the answer. If there is no solution, output Impossible.
3 3
50 -20 -30
0 1 10
1 2 20
0 2 100
30
Hint
,
,
,
,
Translated by ChatGPT 5