Under construction

Still being built. Things may change

Location, Location, Location

Interview

Time limit3sMemory limit1024 MB

Summary
Given n integer points, find the point that minimizes the total Manhattan distance to all of them, breaking ties by smallest x, then smallest y.
Level

Easy3 of 10

Topics
Sorting, Math
Solved
No attempts yet

Problem

The phrase location, location, location is common in real estate and business. It stresses that the physical location of a property or business matters. In real estate, a property's desirability and value depend heavily on its location, often more than on its features or condition. In business, the success of a retail store or commercial establishment can be strongly affected by where it is.

Recently, more people are buying electric vehicles, but buyers soon find it hard to install charging piles at their apartments or houses. A charging station can earn a lot of money. Your boss, Lena, asks you to find a good place to build a charging station for electric vehicle owners.

Input

You are given nn locations as (x,y)(x, y) coordinates on a 2D plane. Each location has an apartment or house without charging infrastructure. Your task is to build a charging station at the location that is closest to all nn locations in the list. Distance is measured with Manhattan distance. The Manhattan distance between two points (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|. Find a location (x,y)(x, y) that minimizes the sum of Manhattan distances from (x,y)(x, y) to all nn locations.

Output

Print the location (x,y)(x, y) that minimizes the sum of Manhattan distances from (x,y)(x, y) to all nn locations. If there are multiple solutions, print the one with the smallest xx. If there are still multiple solutions, print the one with the smallest yy.

Constraints

1≤n≤1000001 \le n \le 100000, −100000≤xi≤100000-100000 \le x_i \le 100000 for 1≤i≤n1 \le i \le n, and −100000≤yi≤100000-100000 \le y_i \le 100000 for 1≤i≤n1 \le i \le n.

Examples2

  1. Example 1

    Input
    4
    3 1
    0 2
    2 3
    1 0
    
    Expected output
    1 1
    
  2. Example 2

    Input
    2
    0 0
    2 2
    
    Expected output
    0 0