Mars rover
The spacecraft "North-2006" has successfully reached Mars, and the rover's descent has gone as planned. Although the rover is built to navigate rough terrain, it should avoid unnecessary risks. Ideally, the rover should travel from its starting point to its destination without crossing any craters. "North-2006" captured an image of the area from space. Your task is to write a program that, using this photograph, along with the initial and final coordinates of the rover, determines if there is a safe path from the starting point to the destination.
Let's formalize the task.
The photograph of the area is a square with the bottom-left corner at coordinates (0, 0) and the top-right corner at (1000, 1000). The rover is represented as a circle with a radius of r. In the photograph, there are N identifiable craters, each shaped like a circle. The center of the k-th crater is located at (x_k, y_k), with a radius of r_k. Initially, the rover is positioned at the bottom-left corner of the map, meaning its center is at (r, r). The rover's goal is to reach the top-right corner of the map, which is at (1000-r, 1000-r). For the path to be considered safe, the rover must not venture outside the map's boundaries, although it can touch the edges. Additionally, the rover must not drive over a crater, though it can touch one. Craters may overlap, and if one crater is entirely within another, the inner crater can be disregarded.
Input
The first line of input contains two integers n and r (0 ≤ n, r ≤ 100). The following n lines provide details of the craters, with the k-th crater described by three real numbers x_k, y_k, r_k, each on a single line and separated by spaces (0 ≤ x_k, y_k, r_k ≤ 1000). All real numbers have between 0 and 5 digits after the decimal point.
Output
Print the word YES (in uppercase, without quotes) if there is a safe path for the rover; otherwise, print the word NO.