Imagine that your city is an infinite 2D plane with Cartesian coordinate system. The only crime-affected road of your city is the x-axis. Currently, there are n criminals along the road. No police station has been built on this road yet, so the mayor wants to build one.
As you are going to be in charge of this new police station, the mayor has asked you to choose a suitable position (some integer point) for building it. You should choose the best position for the police station, so that you could minimize the total time of your criminal catching mission. Your mission of catching the criminals will operate only from this station.
The new station will have only one patrol car. You will go to the criminals by this car, carry them on the car, bring them back to the police station and put them in prison. The patrol car can carry at most m criminals at a time. Note that, the criminals don't know about your mission. So, they will stay where they are instead of running away.
Your task is to find the position for the police station, so that total distance you need to cover to catch all the criminals will be minimum possible. Note that, you also can built the police station on the positions where one or more criminals already exist. In such a case all these criminals are arrested instantly.
Output
Print a single integer, that means the minimum possible distance you need to cover to catch all the criminals.
在一条数轴上有 n(1<=n<=10^6) 个罪犯,第 i 个罪犯的坐标为ai(|ai| <= 10^9)。警察们要选择一个地点作为警察局。他们有一辆警车,可容纳 m (1<=m<=10^6) 个罪犯。那么问题来了,把警察局建在哪能使警察抓捕这些罪犯的行程总和最短。
注意:罪犯不会逃走。