Chain-Confined Path
There is a chain consisting of multiple circles on a plane. The first (last) circle of the chain only intersects with the next (previous) circle, and each intermediate circle intersects only with the two neighboring circles.
Your task is to find the shortest path that satisfies the following conditions.
The path connects the centers of the first circle and the last circle.
The path is confined in the chain, that is, all the points on the path are located within or on at least one of the circles.
Figure 1 shows an example of such a chain and the corresponding shortest path.
Figure 1: An example chain and the corresponding shortest path
Input
The input consists of multiple datasets. Each dataset represents the shape of a chain in the following format.
nx_1 y_1 r_1 x_2 y_2 r_2 ...x_n y_n r_n
The first line of a dataset contains an integer n (3 ≤ n ≤ 100) representing the number of the circles. Each of the following n lines contains three integers separated by a single space. (x_i, y_i) and r_i represent the center position and the radius of the i-th circle C_i. You can assume that 0 ≤ x_i ≤ 1000, 0 ≤ y_i ≤ 1000, and 1 ≤ r_i ≤ 25.
You can assume that C_i and C_i_{+1} (1 ≤ i ≤ n−1) intersect at two separate points. When j ≥ i+2, C_i and C_j are apart and either of them does not contain the other. In addition, you can assume that any circle does not contain the center of any other circle.
The end of the input is indicated by a line containing a zero.
Figure 1 corresponds to the first dataset of Sample Input below. Figure 2 shows the shortest paths for the subsequent datasets of Sample Input.
Figure 2: Example chains and the corresponding shortest paths
Output
For each dataset, output a single line containing the length of the shortest chain-confined path between the centers of the first circle and the last circle. The value should not have an error greater than 0.001. No extra characters should appear in the output.