National Disaster: Two Towers

In a rectangle bounded by two towers, decide whether burning circles block every continuous path between the towers, which happens exactly when a connected chain of circles links two opposite walls of the rectangle.

Medium7GeometryUnion-findGraphImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

Indinesia has two fire lookout towers at (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) with x1<x2x_1 < x_2 and y1<y2y_1 < y_2. Across the country there are NN hotspots, and the ii-th hotspot is a circle with radius rir_i centered at (fxi,fyi)(fx_i, fy_i). A point (x,y)(x, y) is safe when it satisfies all of the following conditions.

  1. x1xx2x_1 \le x \le x_2,
  2. y1yy2y_1 \le y \le y_2,
  3. It does not lie strictly inside any burning area. In other words, for every 1iN1 \le i \le N, the distance from (x,y)(x, y) to (fxi,fyi)(fx_i, fy_i) is at least rir_i.

The locations of the two towers are guaranteed to be safe. The two towers can communicate properly if and only if there exists a safe path connecting them. A path is safe if and only if every point on it is safe. Here a path is any continuous curve, and it does not need to be straight.

Determine whether the two towers can communicate properly.

Input

The first line contains five integers x1x_1, y1y_1, x2x_2, y2y_2 and NN (1000000x1<x21000000-1000000 \le x_1 < x_2 \le 1000000, 1000000y1<y21000000-1000000 \le y_1 < y_2 \le 1000000, 0N10000 \le N \le 1000), denoting the locations (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) of the two towers and the number of hotspots. Each of the next NN lines contains three integers fxifx_i, fyify_i and rir_i (1000000fxi,fyi1000000-1000000 \le fx_i, fy_i \le 1000000, 1ri20000001 \le r_i \le 2000000), denoting the center of the ii-th hotspot and the radius of its burning area. No two hotspots share the same center.

Output

Print "YES" in a line when the two towers can communicate properly, and "NO" otherwise (without quotes).

Hint

The figure below is an example of a safe path connecting the two lookout towers.

Figure showing a safe path example

The figure below is an example of a case where no safe path exists.

Figure showing that no safe path exists

The two figures below show another example of a safe path connecting the two lookout towers. The point (10, 15) in the upper figure and the point (10, 30) in the lower figure are safe.

Upper figure of another safe-path example where the point (10, 15) is safe

Lower figure of another safe-path example where the point (10, 30) is safe