GANNHAT - Closest distance

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

Được gửi lên bởi:Kaiel
Ngày:2008-05-02
Thời gian chạy:0.100s-1s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:CPP JAVA PAS-GPC PAS-FPC
Nguồn bài:Mr Taek

hide comments
2016-08-19 16:39:31


Last edit: 2016-08-21 13:48:57
2015-01-01 14:15:04 Hướng Thái Dương
vái cả xiết time =))) tối ưu 1 đống thứ ms tránh khỏi tle :((
2013-08-16 13:31:15 Chuyên Triết Tổng Hợp
dùng thuật toán random
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.