class kartezien{
double x[];
public kartezien(double xi,double yi)
{x=new double[2];
 x[0]=xi;x[1]=yi;}
 public kartezien(double xi[])
{x=new double[2];
 x[0]=xi[0];x[1]=xi[1];}
public kartezien(kartezien k)
{x=new double[2];
 x[0]=k.x[0];x[1]=k.x[1];}

 public double[] cikti()
{return x;}

public double R()
{return Math.sqrt(x[0]*x[0]+x[1]*x[1]);}
}

class koordinat{
kartezien[] k;
int r[];
    public koordinat(String x) 
    { 
    double sh[][]=Text.readDouble(x);
    for(int i=0;i<sh.length;i++)
      {k[i] = new kartezien(sh[i]);r[i]=i;}
    }
    
    public koordinat(double[][] xyi) 
    {int n=xyi.length;
    double[][] sh=new double[n][2];
    for(int i=0;i<n;i++)
      for(int j=0;j<2;j++)
      {sh[i][j]=xyi[i][j]; }
    for(int i=0;i<n;i++)
      {k[i] = new kartezien(sh[i]);r[i]=i;}
    }
    
    public int[] sira(int[] s1)
    { for(int i=0;i<k.length;i++)
      {r[i] = s1[i];}
      return r;
    }
    
    public double mesafe()
    { double mesafe=0;
        for(int i=1;i<k.length;i++)
           mesafe+=Math.abs(k[r[i]].R()-k[r[i-1]].R());
        return mesafe;
    }
    
    public double mesafe(int ri[])
    {   sira(ri);
	    double mesafe=0;
        for(int i=1;i<k.length;i++)
           mesafe+=Math.abs(k[r[i]].R()-k[r[i-1]].R());
        return mesafe;
    }
}