# Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Asfia’s daughter just turned 5. She is looking for a school to get her admitted. Like every other parent, she wants to admit her daughter to a popular school. But considering the countless number of schools present currently, finding the perfect school has become a cumbersome process. In this problem, we would like to help Asfia find a school for his daughter.

Consider that, Asfia lives in a 2D plane where infinitely many schools are situated. For all integers i and j, there is a school at coordinates (10i, 10j). Additionally, there are n houses at (x_{1}, y_{1}), (x_{2}, y_{2}), … (x_{n}, y_{n}). Each school at (10i, 10j) has a student from all houses (x_{i}, y_{i}) within Manhattan Distance of 10. That means, if |10i - x_{i}| + |10j - y_{i}| ≤ 10, one child from the house located at (x_{i}, y_{i}) studies in the school located at (10i, 10j). Assume that, each house has infinitely many children and multiple buildings can be situated in the same coordinate.

Asfia considers a school to be popular if it has students from lots of different houses. Now, she will provide you the coordinates of the n houses. Your job is to find the schools that have students from most number of different houses.

The first line of the input will contain a single integer **N** (1 ≤ N ≤ 10^{5}), denoting the number of houses.

The following N lines each will contain a pair of integers **x _{i}**

Output the coordinates of the most popular schools in the form x y. If there are multiple such schools, list them in ascending order of their x coordinates. If their x coordinate is same, then list them in ascending order of their y coordinates. Each coordinate must be separated by a newline.

Input | Output |
---|---|

2 2 7 4 13 | 0 10 |

## ExplanationThe image shown above corresponds to the sample test case. A portion of the 2D grid is shown. The circles represent the schools and the two dots represent houses. The numbers beside the lines denote the Manhattan Distance between the corresponding houses and schools. - The house located at (2, 7) has one child studying in school at (0, 0) and another at (0, 10)
- The house located at (4, 13) has one child studying in school at (0, 10) and another at (10, 10)
That means, the school located at (0, 10) has students from the most number of different houses. |

73% Solution Ratio

DimmyTEarliest,

EgorKulikovFastest, 0.2s

Wojciech.324122Lightest, 42 MB

SIR.24Shortest, 599B

Login to submit

We need to build an ordered hash table from school coordinates to the number of houses it has a stud...

Criterion 2020 Round 5 Ended |