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.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.*;
public class Main {
    Scanner in = new Scanner(System.in);
    public static void main(String[] args) {
        new Main();
    }
    public Main() {
        new AOJ2402().doIt();
    }
    class AOJ2402{
        int n,m,l;
        ArrayList<ArrayList<Line2D>> stars;
        double[][] cost;
        int INF = Integer.MAX_VALUE/2;
        void makeLine(int x,int y,int a,int r){
            stars.add(new ArrayList<Line2D>());
            Point2D[] p = new Point2D[5];
            int angle = -a;
            for(int i=0;i<5;i++){
                Robot robot = new Robot(x, y ,angle);
                robot.fd(r);
                p[i] = robot.toPoint();
                //   System.out.println(p[i]);
                angle+=72;
            }
            stars.get(stars.size()-1).add(new Line2D.Double(p[0],p[2]));
            stars.get(stars.size()-1).add(new Line2D.Double(p[2],p[4]));
            stars.get(stars.size()-1).add(new Line2D.Double(p[1],p[4]));
            stars.get(stars.size()-1).add(new Line2D.Double(p[1],p[3]));
            stars.get(stars.size()-1).add(new Line2D.Double(p[0],p[3]));
//            for(int i=0;i<5;i++){
//                Point2D p1 = p[i];
//                Point2D p2 = p[(i+1)%5];
//                Line2D l = new Line2D.Double(p1, p2);
//                stars.get(stars.size()-1).add(l);
//            }
            //   for(int i=0;i<stars.get(stars.size()-1).size();i++){
            //   System.out.println(stars.get(stars.size()-1).get(i).getP1()+" "+stars.get(stars.size()-1).get(i).getP2());
            //   }
        }
        void input(){
            for(int i=0;i<n;i++)makeLine(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt());
        }
        void getMin(){
            for(int i=0;i<n;i++)for(int s=i;s<n;s++){
                if(s==i){
                    cost[i][s]=cost[s][i]=0;continue;
                }
                double min = INF;
                for(int k=0;k<5;k++)for(int j=0;j<5;j++){
                    min = Math.min(min, segSegDist(stars.get(i).get(k),stars.get(s).get(j)));
                }
                cost[i][s] = cost[s][i] = min;
            }
        }
 
        void solve(){
            stars = new ArrayList<ArrayList<Line2D>>();//★の線
            input();
            cost = new double[n][n];
            for(int i=0;i<n;i++)Arrays.fill(cost[i], INF);
            getMin();
//          for(int i=0;i<n;i++){
//              for(int s=0;s<n;s++)System.out.print(cost[i][s]+" ");
//              System.out.println();
//          }
            PriorityQueue<State> q = new PriorityQueue<State>();
            q.add(new State(m,0.0));
            double memo[] = new double[n];
            memo[m]=0.0;
            double result = -1;
            Arrays.fill(memo, INF);
            while(q.size()>0){
                State now = q.remove();
//              System.out.println(now.v+" "+now.cost);
                int v = now.v;
                double c = now.cost;
                if(v==l){
                    result = c;
                    break;
                }
                for(int i=0;i<n;i++)if(cost[v][i]!=INF){
                    double ncost = c+cost[v][i];
                    if(memo[i] <= ncost)continue;
                    memo[i] = ncost;
//                  System.out.println(v+" "+i+" "+ncost);
                    q.add(new State(i, ncost));
                }
            }
            System.out.printf("%.15f\n",result);
        }
        void doIt(){
            while(in.hasNext()){
                n = in.nextInt();
                m = in.nextInt();
                l =in.nextInt();
                if(n+m+l==0)break;
                m--;l--;
                solve();
            }
        }
 
        double segSegDist(Line2D l1,Line2D l2){
            return l1.intersectsLine(l2)? 0:Math.min(Math.min(l1.ptSegDist(l2.getP1()),l1.ptSegDist(l2.getP2())),Math.min(l2.ptSegDist(l1.getP1()), l2.ptSegDist(l1.getP2())));
        }
 
        class Robot{
            double x,y,angle;
            public Robot(int x,int y, int angle) {
                this.x = x;
                this.y = y;
                this.angle = angle;
            }
            void fd(int go){
                x += Math.sin(Math.PI*angle/180.0)*go;
                y += Math.cos(Math.PI*angle/180.0)*go;
            }
            Point2D toPoint(){
                return new Point2D.Double(x,y);
            }
        }
        class State implements Comparable<State>{
            double cost;
            int v;
            public State(int v,double cost) {
                this.v = v;
                this.cost = cost;
            }
            public int compareTo(State o) {
                if(this.cost > o.cost)return 1;
                else if(this.cost < o.cost)return -1;
                return 0;
            }
        }
    }
}