After receiving the intel from Julian (don't worry, he is completely safe), Geven now has to analyse it. Some statistics are already well known (such as squirrels being reptiles with a life span rivalling Greenland sharks). Unfortunately, due to the harrowing escape from the squirrels, some of Julian's intel is missing. Geven notices that the squirrel armada is actually formed in a line, with teleport portals along it. To procure the necessary statistics for the AAC committee, Geven must perform some complex maths involving the entity known as RNG (black magic).
There are
Define
Constraints
Subtask 1 [10%]
Subtask 2 [40%]
Subtask 3 [50%]
No additional constraints. This batch will only run if subtask
Input Specification
The first line of input contains two integers
The second line of input contains
The third line of input contains
Output Specification
Output one integer, the minimum cost to travel from each checkpoint to every other checkpoint modulo
Sample Input 1
5 2
2 5
4 6 1 7
Sample Output 1
56
Explanation for Sample Output 1
Travelling from checkpoint
Travelling from checkpoint
Travelling from checkpoint
Lastly, it will take
Adding all of these values up yields
Sample Input 2
10 3
9 3 8
3 8 4 1 4 4 3 4 4
Sample Output 2
334
Comments