Connect the houses

0

0 votes
Easy
Problem

Gupta and his friends were living in society where all the houses were in a row.They were working on a project and needed to connect their PC's to each other so that they can communicate and share data through the network. Gupta knew about star topology so he decided that they will use star topology and for that one of them had to be the hub centralized device connecting all the nodes.Help gupta and his friends to find the total length of wire to minimize the cost.

Input:
first line contains the number of testcases t. Following t lines have some integers denoting the distance of the house from the reference point such that ith entry indicates the distance of ith house. A zero indicates the end of the testcase.

Output:
The output for each testcase should be on new line. The output should contain the minimum length of total wire required. Since length can be very large print length MODULO 1000000007

constraints:
1<=t<=1000
1<=number of houses<=100000
distance<=100000


Time Limit: 0.7
Memory Limit: 256
Source Limit:
Editor Image

?