There are water deposits in a line. They are so huge that they can be considered to have infinite capacity. Initially, each deposit has liters in it. You have a pump that you can use to transfer water from any deposit to any adjacent deposit ( or ). Each use of the pump to transfer water between two deposits has cost , where is a constant cost to connect two adjacent deposits, and is the number of liters transferred. Your goal is to minimize the cost to equally distribute the water among all the deposits.
Input consists of several cases, each with and , followed by . You can assume , , , and that the sum of all ’s is a multiple of .
For each case, print the minimum cost to equally distribute the water among all the deposits.
Input
4 42 5 5 5 5 1 8 100 7 100 10 30 14 6 50 15 15 8 10 0 0 0 0 0 0 1000000000 1000000000
Output
0 0 551 6000000070