spoj#GANNHAT. Closest distance
Closest distance
English | Vietnamese |
The manhattan distance between two points A(x1,y1) and B(x2,y2) is defined as following:
D(A,B) = |x1 - x2| + |y1 - y2|
Given N points A1, A2, ..., AN, for each point Ai you need to calculate the minimum D(Ai , Aj) (j ≠ i).
Input
- The first line contains a positive integer N (1 ≤ N ≤ 200000).
- The i-th line of the next N lines contains two integers x and y which are co-ordinates of the i-th point(0 ≤ x, y ≤ 107)
Output
- Print N lines, in which the i-th line contains the minimum distance for the i-th point.
Example
Input: 4 0 0 0 1 1 0 1 1 Output: 1 1 1 1