Restaurant Locations from Delivery Times
Time limit2sMemory limit512 MB
For each friend, print the lexicographically smallest integer point at Manhattan distance exactly t that stays at distance at least t from every friend.
Problem
Last year Kosta, a barbecue master, opened several restaurants in Manhattan. Business was good at first, but a fast food chain that opened recently took away many of his customers. That chain has no place to eat in and nobody knows where its restaurants are. It only delivers. Kosta wants to work out where those restaurants can be, using the delivery times.
The streets of Manhattan run parallel to the coordinate axes. Every restaurant and every customer therefore sits on a point of the plane with integer coordinates. The distance between and is .
When a customer orders online, delivery starts at once from the restaurant closest to that customer. If several restaurants are equally close, the food comes from any one of them. The delivery time equals the distance from the customer to that restaurant.
Kosta asked friends to order food and measure the delivery time. Write a program that finds a layout of restaurants consistent with the collected data. Several layouts can fit the same data, so the output is fixed to the single layout described below.
Input
The first line contains the integer , the number of Kosta's friends.
Each of the next lines contains three integers , and separated by a single space. The friend at measured delivery time . All friends sit on different coordinates.
, , .
At least one layout of restaurants consistent with the given data exists.
Output
Print lines. Line contains the coordinates and of the restaurant that delivered to friend , separated by a single space.
The point on line is the lexicographically smallest point with integer coordinates that satisfies both conditions below. In lexicographic order a smaller comes first, and among equal a smaller comes first.
- Its distance to friend is exactly .
- Its distance to friend is at least for every friend .
Such a point always exists, and its coordinates are always between and . The chosen points taken together form a layout consistent with the data. The same point can appear on several lines.
Note
Take the second sample. Friend 2 sits at and measured a delivery time of 2, so the restaurant must be at distance exactly 2 from . Going through the candidates by increasing , the points , , , and each lie closer to some friend than that friend's own delivery time, so no restaurant can be placed there. The next candidate is , and that is the answer for friend 2.