Problem: Milky Way

Milky Way

English text is not available in this practice contest.

The Milky Way Transportation Corporation is a travel agency that plans and manages interstellar travel tours. The Milky Way Transportation Corporation is planning a project called "Milky Way Crossing Orihime Hikoboshi Experience Tour". This tour departs from Vega in Lyra and travels around the stars to Altair in Aquila. You are an employee of the Milky Way Transportation Corporation and are responsible for choosing the route of the tour.

For simplicity, the Milky Way shall be on two-dimensional coordinates, and the stars shall be represented by pentagrams. The spacecraft used for the tour is equipped with a special engine and can move on the pentagram line segment without energy. On the other hand, when moving between pentagrams, energy proportional to the distance is required.

In recent years, sales of the Milky Way Transportation Corporation have been sluggish, and there is a pressing need to save various necessary expenses such as energy costs for spacecraft. Your job is to find a route that minimizes the sum of interstellar travel distances when moving from Vega to Altair, and write a program that outputs that sum.

Note that when moving from one pentagram to another that is contained within it, if the pentagrams are not in contact with each other, they are treated as interstellar movements.

Figure D-1 illustrates the third Sample Input. In the figure, the red line segment represents the part of the interstellar movement of the route that minimizes the total interstellar movement distance.

<image>

Figure D-1: Movement between stars

Input

The input consists of one or more datasets. One dataset has the following format:

> N M L
> x1 y1 a1 r1
> x2 y2 a2 r2
> ...
> xN yN aN rN
>

The first line of each test case consists of the integers N, M, L, where N is the number of stars (1 ≤ N ≤ 100), M is the Vega number (1 ≤ M ≤ N), and L is the Altair number (1 ≤ M ≤ N). Represents 1 ≤ L ≤ N). Information on each star is given in the following N lines. Each row consists of four integers, xi, yi, ai, and ri, where xi is the x-coordinate of the center of the i-th star (0 ≤ xi ≤ 1,000) and yi is the y-coordinate of the center of the i-th star (0 ≤ yi). ≤ 1,000), ai is the angle formed by the straight line connecting the center coordinates of the i-th star and the tip of the star with the y-axis (0 ≤ ai <72), and ri is from the center coordinates of the i-th star to the tip of the star. The length (1 ≤ ri ≤ 1,000). The end of the input is represented by a line containing three zeros.

The star on the left in Figure D-2 represents the star with x = 5, y = 10, a = 0, r = 5, and the star on the right is x = 15, y = 10, a = 30, r = 5. Represents the star of.

<image>

Figure D-2: Star example

Output

For each input, output the minimum total interstellar movement distance required to move from Vega to Altair on one line. The output must not have an error greater than 0.000001.

Sample Input


1 1 1
5 5 0 5
2 1 2
5 5 0 5
15 5 0 5
3 2 3
15 15 0 5
5 5 10 5
25 25 20 5
0 0 0


Output for Sample Input


0.00000000000000000000
0.48943483704846357796
9.79033725601359705593






Example

Input




Output

Solution (in JAVA):

Solution:
import java.util.*;
import java.awt.geom.*;
public class Main {
	double EPS = 1.0e-08;
	
	private void doit() {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int M = sc.nextInt()-1;
			int L = sc.nextInt()-1;
			if(n == 0 && M == -1 && L == -1) break;
			Point2D [][] point = new Point2D.Double[n][5];
			Line2D [][] line = new Line2D.Double[n][5];
			//input
			for(int i=0; i < n; i++){
				double x = sc.nextDouble();
				double y = sc.nextDouble();
				double a = sc.nextDouble();
				double r = sc.nextDouble();
				//each point
				for(int j=0; j < 5; j++){
					double rad = Math.toRadians(-a + (double)j * 72);
					double endx = x + r * Math.sin(rad);
					double endy = y + r * Math.cos(rad);
					point[i][j] = new Point2D.Double(endx, endy);
				}
				//each line
				for(int j=0; j < 5; j++){
					line[i][j] = new Line2D.Double(point[i][j] , point[i][(j+2)%5]);
				}
			}
			double [][] pass = new double[n][n];
			//calc
			for(int i=0; i < n; i++){
				pass[i][i] = 0.0;
				for(int j=i+1; j< n; j++){
					double ans = 1 << 24;
					for(int k = 0; k < 5; k++){
						for(int l = 0; l < 5; l++){
							Line2D nowi = line[i][k];
							Line2D nowj = line[j][l];
							if(nowi.intersectsLine(nowj)){
								ans = 0.0;
								continue;
							}
							double res = getDis1(nowi,nowj);
							ans = Math.min(ans, res);
						}
					}
					pass[i][j] = ans; pass[j][i] = ans;
				}
			}//end i
			
			
			for(int j=0; j < n; j++){
				for(int i = 0;i < n; i++){
					for(int k = 0; k < n; k++){
						pass[i][k] = Math.min(pass[i][k], pass[i][j] + pass[j][k]);
					}
				}
			}
			System.out.printf("%1.16f\n",pass[M][L]);
		}
	}

	private double getDis1(Line2D a, Line2D b) {
		Point2D a1 = a.getP1();
		Point2D a2 = a.getP2();
		Point2D b1 = b.getP1();
		Point2D b2 = b.getP2();
		double res = getD(a1,a2,b1);
		res = Math.min(res, getD(a1,a2,b2));
		res = Math.min(res, getD(b1,b2,a1));
		res = Math.min(res, getD(b1,b2,a2));
		return res;
	}

	private double getD(Point2D a, Point2D b, Point2D c) {
		Point2D ba = getV(b,a);
		Point2D ca = getV(c,a);
		Point2D ab = getV(a,b);
		Point2D cb = getV(c,b);
		double result;
		if(getDot(ba,ca) < EPS){
			result = a.distance(c);
		}
		else if(getDot(ab,cb) < EPS){
			result = c.distance(b);
		}
		else{
			result = Math.abs(getCross(ba,ca)) / b.distance(a);
		}
		return result;
	}

	private double getCross(Point2D a, Point2D b) {
		return (a.getX() * b.getY() - a.getY() * b.getX());
	}

	private double getDot(Point2D a, Point2D b) {
		return (a.getX() * b.getX() + a.getY() * b.getY());
	}

	private Point2D getV(Point2D a, Point2D b) {
		Point2D res = new Point2D.Double(a.getX() - b.getX(), a.getY() - b.getY());
		return res;
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}