Cordon Bleu

Given N bottle positions, M courier bases, and one restaurant, a courier collects one or two bottles per trip; find the minimum total Manhattan distance.

Medium7GreedySortingMathImplementationNo attempts yetTime limit7sMemory limit512 MB

Problem

A Parisian entrepreneur has opened a new restaurant called "Au bon cordon bleu", named after a famous French recipe. Nobody around him knows which wine goes with that dish, so he plans to taste many different wines before he writes the wine menu.

The bottles he wants to taste come from wine merchants in and around Paris. High quality wine is a delicate product, so only highly trained couriers on motorbikes may carry it, and those couriers are expensive.

One courier can carry several bottles, but only one bottle at a time. Every courier is paid at the same rate of one euro per kilometer. Each leg of a trip is measured with the Manhattan distance: the distance from a point (x1,y1)(x_1, y_1) to a point (x2,y2)(x_2, y_2) is x1x2+y1y2|x_1 - x_2| + |y_1 - y_2|.

A courier in charge of a single bottle is paid the sum of two distances: from the courier base to the wine merchant, then from the wine merchant to the restaurant.

A courier in charge of two bottles, one after the other, moves from the base to the first bottle, then to the restaurant, then to the second bottle, then to the restaurant, and is paid the sum of those four distances.

Help the entrepreneur spend as little as possible on couriers. Given the coordinates of the available courier bases, the coordinates of the bottles that have to be collected, and the coordinates of the restaurant, compute the smallest number of kilometers the couriers are paid for. There is no obligation to use every courier, and the bottles may be collected in any order.

Input

The input has several lines. Each line holds integers separated by single spaces.

  • The first line holds the number NN of wine bottles to collect and the number MM of available couriers.
  • Each of the next NN lines holds the coordinates xx and yy of one bottle, as two integers.
  • Each of the next MM lines holds the coordinates xx and yy of one courier base, as two integers.
  • The last line holds the coordinates xx and yy of the restaurant.

Limits

  • 1N10001 \le N \le 1000
  • 1M10001 \le M \le 1000
  • every coordinate satisfies 1000x1000-1000 \le x \le 1000 and 1000y1000-1000 \le y \le 1000

Output

Print a single integer: the smallest number of euros that has to be paid to collect every bottle.

Hint

Several items may sit at the same initial position. Two bottles, ten couriers and the restaurant may all start at the same point.

In the arrangement drawn above, only courier C2 moves. That courier collects the bottles B1 and B2 and brings them to the restaurant R with the four moves labeled 1 to 4. The total is 5 kilometers, which is one of the optimal solutions.