The NotSoIntelligent Dictator

All submissions for this problem are available.
MountainView (MV) is a linear, streetlike country.
By linear, we mean all the cities of the country are placed on a single straight line  the xaxis.
Thus every city's position can be defined by a single coordinate, xi, the distance from the left borderline of the country. You can treat all cities as single points.
Unfortunately, the dictator of telecommunication of MV (Mr. LL) is not an intelligent man. He doesn't know anything about the modern telecom technologies, except for peertopeer connections.
Even worse, his thoughts on peertopeer connections are extremely faulty: he believes that, if Pi people are living in city i, there must be at least Pi cables from city i to every other city of MV  this way he can guarantee no congestion will ever occur!
Mr. LL is not good in math and computing. He hires an engineer to find out how much cable they need to implement this telecommunication system, given the coordination of the cities
and their respective population.
Input
A number T is given in the first line and then comes T blocks, each representing a scenario.
Each scenario consists of three lines. The first line indicates the number of cities (N).
The second line indicates the coordinates of the N cities. The third line contains the population of each of the cities.
The cities needn't be in increasing order in the input..
Output
For each scenario of the input, write the length of cable needed in a single line modulo 1,000,000,007.
Constraints
1 ≤ T ≤ 20
1 ≤ N ≤ 200,000
Pi <=10,000
Border to border length of the country <= 1,000,000,000
Example
Input: 2 3 1 3 6 10 20 30 5 5 55 555 55555 555555 3333 333 333 33 35 Output: 280 463055586
Explanation
For the first test case, having 3 cities requires 3 sets of cable connections. Between city 1 and 2, which has a population of 10 and 20, respectively, Mr. Treat believes at least 10 cables should come out of city 1 for this connection, and at least 20 cables should come out of city 2 for this connection.
Thus, the connection between city 1 and city 2 will require 20 cables, each crossing a distance of 31 = 2 km.
Applying this absurd logic to connection 2,3 and 1,3, we have
[1,2] => 20 connections x 2 km = 40 km of cable
[2,3] => 30 connections x 3 km = 90 km of cable
[1,3] => 30 connections x 5 km = 150 km of cable
For a total of 280 , Output is 280 % 1000000007 = 280km of cable.
Author:  vedantbajaj96 
Tags  vedantbajaj96 
Date Added:  12122015 
Time Limit:  10 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 