Haybale Distribution
시간 제한2초메모리 제한1024 MB
각 질의 (a,b)마다 정수 y를 골라 모든 헛간에 배송할 때의 최소 낭비량을 구해 출력한다.
문제
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.