CF BUDDY
← Problems·

1979E · Manhattan Triangle

2400 · binary search, constructive algorithms, data structures

Problem: The Manhattan distance between two points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) is defined as: x1x2+y1y2.|x_1 - x_2| + |y_1 - y_2|.

We call a Manhattan triangle three points on the plane, the Manhattan distances between each pair of which are equal.

You are given a set of pairwise distinct points and an even integer dd. Your task is to find any Manhattan triangle, composed of three distinct points from the given set, where the Manhattan distance between any pair of vertices is equal to dd.

Input Format: Each test consists of multiple test cases. The first line contains one integer tt (1t1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn and dd (3n21053 \le n \le 2 \cdot 10^5, 2d41052 \le d \le 4 \cdot 10^5, dd is even) — the number of points and the required Manhattan distance between the vertices of the triangle.

The (i+1)(i + 1)-th line of each test case contains two integers xix_i and yiy_i (105xi,yi105-10^5 \le x_i, y_i \le 10^5) — the coordinates of the ii-th point. It is guaranteed that all points are pairwise distinct.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output Format: For each test case, output three distinct integers ii, jj, and kk (1i,j,kn1 \le i,j,k \le n) — the indices of the points forming the Manhattan triangle. If there is no solution, output "0 0 00\ 0\ 0" (without quotes).

If there are multiple solutions, output any of them.

Note: In the first test case:

Points AA, BB, and FF form a Manhattan triangle, the Manhattan distance between each pair of vertices is 44. Points DD, EE, and FF can also be the answer.

In the third test case:

Points AA, CC, and EE form a Manhattan triangle, the Manhattan distance between each pair of vertices is 66.

In the fourth test case, there are no two points with a Manhattan distance of 44, and therefore there is no suitable Manhattan triangle.

Sample Cases

Case 1

Input

6
6 4
3 1
0 0
0 -2
5 -3
3 -5
2 -2
5 4
0 0
0 -2
5 -3
3 -5
2 -2
6 6
3 1
0 0
0 -2
5 -3
3 -5
2 -2
4 4
3 0
0 3
-3 0
0 -3
10 8
2 1
-5 -1
-4 -1
-5 -3
0 1
-2 5
-4 4
-4 2
0 0
-4 1
4 400000
100000 100000
-100000 100000
100000 -100000
-100000 -100000

Output

2 6 1
4 3 5
3 5 1
0 0 0
6 1 3
0 0 0

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback