Mirko got an array of integers for his birthday from his grandmother Norma. As any other kid, he was hoping for some money, but got an array. Luckily, in his town there is a pawn shop that buys up arrays. The cost of an array of integers is min·max·L kunas, where min is the minimal integer in the array, max is the maximal and L is the array length. Mirko is going to sell a subsequence of consecutive numbers from his array. He calculated the average price of all such subsequences.
In order to check his result, he wants you to do the same. He will be pleased with only the last 9 digits of the sum of all prices, so you don’t need to bother with large and real numbers.
입력 2 1 3 출력 16 입력 4 2 4 1 4 출력 109 입력 6 8 1 3 9 7 4 출력 1042 Clarification of the first example: The array consists of two integers, 1 and 3. The possible subsequences Mirko can sell are (1), (3) and (1,3), their prices being 1, 9 and 6, respectively, which is 16 summed up. Clarification of the second example: The possible subsequences Mirko can sell are (2), (4), (1), (4), (2, 4), (4, 1), (1, 4), (2,4,1), (4,1,4) and (2,4,1,4). Their prices are 4, 16, 1, 16, 16, 8, 8, 12, 12 and 16, respectively, which is 109 summed up.
출처:coci_2013/2014_contest2 6/6