Our space military base is under attack.The virus break into our computer,and destroy the CCS(Carrier Control System).Carrier is a kind of spaceship,which has the most powerful weapon.We have tried several times to find out the way to take control of them again.Unfortunately,at last we realized that our carriers are not belong to us anymore.We nosed out that our enemy who comes from Chars,a planet with many wise cultures living in,had embezzled the command of the carriers from us.Soon after,We recived a command from our SCO(space command office).It says we have to destroy all the uncontrollable carriers.
According to the information report we got from our spy organization,All the uncontrollable carriers are fly in a circle rail.To make a easier problem,we divide the circle into equal N(N<=100000000) parts and number it from 0 to N-1. We can consider that the length every part of rail is 1.In light of our report,there are M(M<=100000) carriers are uncontrollable.The number i uncontrollable carrier is at the middle of the number p[i](0<=p[i]<=N-1) rail.To destroy the carriers,we have M remote control bombs.The number I bombs is at the middle of the number q[i](0<=q[i]<=N-1) rail.We can let a bomb move to a carrier.When it move from number i rail to number i+1(or number i-1) rail it cost 1 energy(bombs in number N-1 rail can move to number 0 rail ,it also cost 1 energy;Remember bombs cannot leave the rail ) .The more energy we used when we move,The less damage we can make to the carriers.Clearly, We must spend the minimal energy to move all the bombs on to the carrier.One bombs can just destroy one carrier,even two carrier are at the same place.
We can imagine that carrier do not move.