Haybale Distribution
문제
Farmer John is distributing haybales across the farm!
Farmer John's farm has barns, located at integer points on the number line. Farmer John's plan is to first have shipments of haybales delivered to some integer point and then distribute one shipment to each barn.
Unfortunately, Farmer John's distribution service is very wasteful. In particular, for some and , haybales are wasted per unit of distance left each shipment is transported, and haybales are wasted per unit of distance right each shipment is transported. Formally, for a shipment being transported from point to a barn at point , the number of haybales wasted is given by
Given independent queries each consisting of possible values of , please help Farmer John determine the fewest amount of haybales that will be wasted if he chooses optimally.
입력
The first line contains .
The next line contains .
The next line contains .
The next lines each contain two integers and .
출력
Output lines, the th line containing the answer for the th query.
예제
예제 1
5 1 4 2 3 10 4 1 1 2 1 1 2 1 4
11 13 18 30