Cosmic Assembly
Time limit1sMemory limit1024 MB
Find integer coordinates (x, y, z) minimizing the sum of Manhattan distances to N given points, breaking ties lexicographically.
Problem
A space company is organizing a meeting of the executive directors of its divisions. Each director has a personal single-seat spaceship, and the coordinates of every director are known.
Spaceship fuel is very expensive, so the company wants to pick a meeting location that minimizes the sum of all travel distances. Space traffic rules require moving in only one of the , , or directions at any moment, so the distance of a single trip is computed as .
Given the directors' coordinates, find the most suitable meeting location. The meeting location must be easy to mark on a map, so its coordinates must be integers.
Input
The first line contains the number of directors . Each of the next lines contains three space-separated integers , , , giving the coordinates of the -th director.
Several directors may initially be at the same location.
Output
Output the coordinates of a meeting location that minimizes the total travel distance, as three space-separated integers , , . If several meeting locations are optimal, output the lexicographically smallest one: the smallest , breaking ties by the smallest , then by the smallest .