This page is still under construction.

Parts of this page are still being built. What you see may change.

Walking Santa Claus

Time limit1sMemory limit128 MB

Summary
Place a depot on a huge grid so that twice the sum of Manhattan distances to all houses, minus the farthest one, is minimized, and print the best cell.
Level

Medium6 of 10

Topics
Math, Geometry, Greedy, Sorting
Solved
No attempts yet

Problem

Santa Claus wants to hand out chocolate cakes to the children of a certain district. The district's roads form a grid: there are WW north-south roads and HH east-west roads. The north-south roads are numbered 1,2,…,W1, 2, \dots, W from west to east, and the east-west roads are numbered 1,2,…,H1, 2, \dots, H from south to north. The intersection of the xx-th north-south road (counting from the west) and the yy-th east-west road (counting from the south) is written as (x,y)(x, y). Every house sits on an intersection, and there are NN houses in total. Santa can move only along the roads, and moving between two adjacent intersections takes time 11 (so the travel time between intersections (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) is ∣x1−x2∣+∣y1−y2∣|x_1 - x_2| + |y_1 - y_2|).

Santa parks Rudolph at one intersection and walks from there to deliver the cakes. He can carry only one cake at a time, so after delivering to a house he must return to the intersection where Rudolph waits, pick up the next cake, and set out again. He wants to minimize the total time needed to deliver a cake to every house. However, after delivering the cake to the last house he does not go back to Rudolph, so that final return trip is not counted.

Given the positions of the houses, determine at which intersection Santa should park Rudolph so that the delivery time is minimized, and report that minimum time.

Input

The first line contains the number of north-south roads WW and the number of east-west roads HH. (1≤W,H≤1091 \le W, H \le 10^9)

The second line contains the number of houses NN. (1≤N≤1051 \le N \le 10^5)

Each of the next NN lines contains the position xx and yy of one house. No intersection holds more than one house.

Output

On the first line, print the minimum time needed to deliver a cake to every house. On the second line, print the position xx and yy of the intersection where Rudolph should be parked. If several intersections achieve the minimum, print the one farthest to the west (smallest xx); if there is still a tie, print the one farthest to the south (smallest yy).

Examples2

  1. Example 1

    Input
    5 4
    3
    1 1
    3 4
    5 3
    
    Expected output
    10
    3 3
    
  2. Example 2

    Input
    4 6
    8
    1 3
    3 2
    4 4
    2 5
    2 3
    3 3
    3 4
    2 4
    
    Expected output
    21
    2 3