/*
 * File:   main.cpp
 * Author: liuyubo
 *
 * Created on March 11, 2012, 11:29 PM
 */

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

#include <utility>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <queue>
#include <map>

using namespace std;

#define INF 2000000000

void loadData( void );
double proc( void );
void printRes( double );

typedef struct Item{
    int c,t,index;
}item;

typedef struct Cart{
    int stoolIndex;
    int minPrice;
    vector<item> pencils;
    vector<bool> inCart;
}cart;

int n,k;
double sum;
item items[1000];

vector<cart> carts;

bool icmp( const item &ia , const item &ib );
double calcPrice( void );
void unionCarts( void );
void seperateCarts( void );

bool lyb_debug = false;

void printCarts( void );

int main(int argc, char** argv) {

    loadData();
    printRes( proc() );

    return 0;
}

void printCarts( void ){

    printf("== carts size:%d k:%d ==\n",carts.size(),k);
    for( int i = 0 ; i < carts.size() ; i ++ ){
        printf("* stoolIndex:%d minPrice:%d pencils:",carts[i].stoolIndex,carts[i].minPrice);
        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ )
            if( carts[i].inCart[j] )
                printf("%d ",carts[i].pencils[j].index);
        printf("\n");
    }

    return;
}

double calcPrice( void ){

    double res = sum;
    for( int i = 0 ; i < carts.size() ; i ++ )
        res -= (double)( carts[i].stoolIndex == -1 ? 0 : carts[i].minPrice )/2.0;
    return res;
}

void unionCarts( void ){

    for( int i = carts.size() - 1 ; i >= k ; i -- ){

        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ ){
            carts[k-1].pencils.push_back( carts[i].pencils[j] );
            carts[k-1].inCart.push_back( true );
            carts[k-1].minPrice = min( carts[k-1].minPrice , carts[i].pencils[j].c );
        }
    }

    while( carts.size() != k )
        carts.pop_back();
    return;
}

void seperateCarts( void ){

    for( int i = 0 ; ; i ++ )
        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ ){

            cart newCart;
            newCart.stoolIndex = -1;
            newCart.minPrice = carts[i].pencils[j].c;
            newCart.pencils.clear();
            newCart.inCart.clear();

            newCart.pencils.push_back( carts[i].pencils[j] );
            newCart.inCart.push_back( true );

            carts.push_back( newCart );

            carts[i].inCart[j] = false;

            if( carts.size() == k )
                return;
        }

    return;
}

double proc( void ){

    sort( items , items + n , icmp );

    carts.clear();
    int start = 0;

    int stoolIndex = -1;
    for( int i = start; i <= n ; ){

        if( i < n && items[i].t == 1 )
            stoolIndex = items[i].index;
        if( i >= n && start >= n )
            break;
        if( i == n || items[i].t == 1 ){

            cart newCart;
            newCart.stoolIndex = stoolIndex;
            newCart.minPrice = ( stoolIndex == -1 ? INF : items[stoolIndex].c );
            newCart.pencils.clear();
            newCart.inCart.clear();
            for( int j = start ; j <= min( n-1 , i ) ; j ++ ){
                if( items[j].index != stoolIndex ){
                    newCart.pencils.push_back( items[j] );
                    newCart.inCart.push_back( true );
                    newCart.minPrice = min( newCart.minPrice , items[j].c );
                }
            }

            carts.push_back( newCart );

            start = i + 1;
            i = start;

            stoolIndex = -1;
        }
        else
            i ++;
    }

    if( lyb_debug ){
        printf("After initial seperation:\n");
        printCarts();
    }

    if( k == carts.size() )
        return calcPrice();
    else if( k < carts.size() )
        unionCarts();
    else
        seperateCarts();

    return calcPrice();
}

bool icmp( const item &ia , const item &ib ){
    if( ia.c != ib.c )
        return ia.c > ib.c;

    return ia.t < ib.t;
}

void loadData( void ){

    scanf("%d%d",&n,&k);

    sum = 0.0;
    for( int i = 0 ; i < n ; i ++ ){
        scanf("%d%d",&items[i].c,&items[i].t);
        items[i].index = i;
        sum += (double)items[i].c;
    }
    return;
}

void printRes( double res ){

    printf("%.1lf\n",res);
    for( int i = 0 ; i < carts.size() ; i ++ ){
        int carts_size = 0;
        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ )
            if( carts[i].inCart[j] )
                carts_size ++;
        printf("%d",carts_size + ( carts[i].stoolIndex == -1 ? 0 : 1 ) );
        if( carts[i].stoolIndex != -1 )
            printf(" %d",carts[i].stoolIndex+1);
        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ )
            if( carts[i].inCart[j] )
                printf(" %d",carts[i].pencils[j].index+1);
        printf("\n");
    }
    return;
}


/*
 * File:   main.cpp
 * Author: liuyubo
 *
 * Created on March 11, 2012, 11:29 PM
 */

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

#include <utility>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <queue>
#include <map>

using namespace std;

#define INF 2000000000

void loadData( void );
double proc( void );
void printRes( double );

typedef struct Item{
    int c,t,index;
}item;

typedef struct Cart{
    int stoolIndex;
    int minPrice;
    vector<item> pencils;
    vector<bool> inCart;
}cart;

int n,k;
double sum;
item items[1000];

vector<cart> carts;

bool icmp( const item &ia , const item &ib );
double calcPrice( void );
void unionCarts( void );
void seperateCarts( void );

bool lyb_debug = false;

void printCarts( void );

int main(int argc, char** argv) {

    loadData();
    printRes( proc() );

    return 0;
}

void printCarts( void ){

    printf("== carts size:%d k:%d ==\n",carts.size(),k);
    for( int i = 0 ; i < carts.size() ; i ++ ){
        printf("* stoolIndex:%d minPrice:%d pencils:",carts[i].stoolIndex,carts[i].minPrice);
        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ )
            if( carts[i].inCart[j] )
                printf("%d ",carts[i].pencils[j].index);
        printf("\n");
    }

    return;
}

double calcPrice( void ){

    double res = sum;
    for( int i = 0 ; i < carts.size() ; i ++ )
        res -= (double)( carts[i].stoolIndex == -1 ? 0 : carts[i].minPrice )/2.0;
    return res;
}

void unionCarts( void ){

    for( int i = carts.size() - 1 ; i >= k ; i -- ){

        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ ){
            carts[k-1].pencils.push_back( carts[i].pencils[j] );
            carts[k-1].inCart.push_back( true );
            carts[k-1].minPrice = min( carts[k-1].minPrice , carts[i].pencils[j].c );
        }

        if( carts[i].stoolIndex != -1 ){
            item newFakePencle;
            newFakePencle.index = carts[i].stoolIndex;
            carts[k-1].pencils.push_back( newFakePencle );
            carts[k-1].inCart.push_back( true );
            carts[k-1].minPrice = min( carts[k-1].minPrice , carts[i].minPrice );
        }

        if( lyb_debug ){
            printf("After union carts %d:\n",i);
            printCarts();
        }
    }

    while( carts.size() != k )
        carts.pop_back();
    return;
}

void seperateCarts( void ){

    for( int i = 0 ; ; i ++ )
        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ ){

            cart newCart;
            newCart.stoolIndex = -1;
            newCart.minPrice = carts[i].pencils[j].c;
            newCart.pencils.clear();
            newCart.inCart.clear();

            newCart.pencils.push_back( carts[i].pencils[j] );
            newCart.inCart.push_back( true );

            carts.push_back( newCart );

            carts[i].inCart[j] = false;

            if( carts.size() == k )
                return;
        }

    return;
}

double proc( void ){

    sort( items , items + n , icmp );

    carts.clear();
    int start = 0;

    int stoolIndex = -1;
    for( int i = start; i <= n ; ){

        if( i < n && items[i].t == 1 )
            stoolIndex = items[i].index;
        if( i >= n && start >= n )
            break;
        if( i == n || items[i].t == 1 ){

            cart newCart;
            newCart.stoolIndex = stoolIndex;
            newCart.minPrice = ( stoolIndex == -1 ? INF : items[stoolIndex].c );
            newCart.pencils.clear();
            newCart.inCart.clear();
            for( int j = start ; j <= min( n-1 , i ) ; j ++ ){
                if( items[j].index != stoolIndex ){
                    newCart.pencils.push_back( items[j] );
                    newCart.inCart.push_back( true );
                    newCart.minPrice = min( newCart.minPrice , items[j].c );
                }
            }

            carts.push_back( newCart );

            start = i + 1;
            i = start;

            stoolIndex = -1;
        }
        else
            i ++;
    }

    if( lyb_debug ){
        printf("After initial seperation:\n");
        printCarts();
    }

    if( k == carts.size() )
        return calcPrice();
    else if( k < carts.size() )
        unionCarts();
    else
        seperateCarts();

    return calcPrice();
}

bool icmp( const item &ia , const item &ib ){
    if( ia.c != ib.c )
        return ia.c > ib.c;

    return ia.t < ib.t;
}

void loadData( void ){

    scanf("%d%d",&n,&k);

    sum = 0.0;
    for( int i = 0 ; i < n ; i ++ ){
        scanf("%d%d",&items[i].c,&items[i].t);
        items[i].index = i;
        sum += (double)items[i].c;
    }
    return;
}

void printRes( double res ){

    printf("%.1lf\n",res);
    for( int i = 0 ; i < carts.size() ; i ++ ){
        int carts_size = 0;
        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ )
            if( carts[i].inCart[j] )
                carts_size ++;
        printf("%d",carts_size + ( carts[i].stoolIndex == -1 ? 0 : 1 ) );
        if( carts[i].stoolIndex != -1 )
            printf(" %d",carts[i].stoolIndex+1);
        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ )
            if( carts[i].inCart[j] )
                printf(" %d",carts[i].pencils[j].index+1);
        printf("\n");
    }
    return;
}


/*
 * File:   main.cpp
 * Author: liuyubo
 *
 * Created on March 11, 2012, 11:29 PM
 */

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

#include <utility>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <queue>
#include <map>

using namespace std;

#define INF 2000000000

void loadData( void );
double proc( void );
void printRes( double );

typedef struct Item{
    int c,t,index;
}item;

typedef struct Cart{
    int stoolIndex;
    int minPrice;
    vector<item> pencils;
    vector<bool> inCart;
}cart;

int n,k;
double sum;
item items[1000];

vector<cart> carts;

bool icmp( const item &ia , const item &ib );
double calcPrice( void );
void unionCarts( void );
void seperateCarts( void );

bool lyb_debug = false;

void printCarts( void );

int main(int argc, char** argv) {

    loadData();
    printRes( proc() );

    return 0;
}

void printCarts( void ){

    printf("== carts size:%d k:%d sum:%.0lf==\n",carts.size(),k,sum);
    for( int i = 0 ; i < carts.size() ; i ++ ){
        printf("* stoolIndex:%d minPrice:%d pencils:",carts[i].stoolIndex,carts[i].minPrice);
        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ )
            if( carts[i].inCart[j] )
                printf("%d ",carts[i].pencils[j].index);
        printf("\n");
    }

    return;
}

double calcPrice( void ){

    double res = sum;
    for( int i = 0 ; i < carts.size() ; i ++ )
        res -= (double)( carts[i].stoolIndex == -1 ? 0 : carts[i].minPrice )/2.0;
    return res;
}

void unionCarts( void ){

    for( int i = carts.size() - 1 ; i >= k ; i -- ){

        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ ){
            carts[k-1].pencils.push_back( carts[i].pencils[j] );
            carts[k-1].inCart.push_back( true );
            carts[k-1].minPrice = min( carts[k-1].minPrice , carts[i].pencils[j].c );
        }

        if( carts[i].stoolIndex != -1 ){
            item newFakePencle;
            newFakePencle.index = carts[i].stoolIndex;
            carts[k-1].pencils.push_back( newFakePencle );
            carts[k-1].inCart.push_back( true );
            carts[k-1].minPrice = min( carts[k-1].minPrice , carts[i].minPrice );
        }

        if( lyb_debug ){
            printf("After union carts %d:\n",i);
            printCarts();
        }
    }

    while( carts.size() != k )
        carts.pop_back();
    return;
}

void seperateCarts( void ){

    for( int i = 0 ; ; i ++ )
        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ ){

            cart newCart;
            newCart.stoolIndex = -1;
            newCart.minPrice = 0;
            newCart.pencils.clear();
            newCart.inCart.clear();

            newCart.pencils.push_back( carts[i].pencils[j] );
            newCart.inCart.push_back( true );

            carts.push_back( newCart );

            carts[i].inCart[j] = false;

            if( carts.size() == k ){
                if( lyb_debug ){
                    printf("After seperate carts:\n");
                    printCarts();
                }
                return;
            }
        }

    if( lyb_debug ){
        printf("After seperate carts:\n");
        printCarts();
    }

    return;
}

double proc( void ){

    sort( items , items + n , icmp );

    carts.clear();
    int start = 0;

    int stoolIndex = -1;
    for( int i = start; i <= n ; ){

        if( i < n && items[i].t == 1 )
            stoolIndex = i;
        if( i >= n && start >= n )
            break;
        if( i == n || items[i].t == 1 ){

            cart newCart;
            newCart.stoolIndex = ( stoolIndex == -1 ? -1 : items[i].index);
            newCart.minPrice = ( stoolIndex == -1 ? INF : items[i].c );
            newCart.pencils.clear();
            newCart.inCart.clear();
            for( int j = start ; j <= min( n-1 , i ) ; j ++ ){
                if( items[j].index != (stoolIndex==-1?-1:items[i].index) ){
                    newCart.pencils.push_back( items[j] );
                    newCart.inCart.push_back( true );
                    newCart.minPrice = min( newCart.minPrice , items[j].c );
                }
            }

            carts.push_back( newCart );

            start = i + 1;
            i = start;

            stoolIndex = -1;
        }
        else
            i ++;
    }

    if( lyb_debug ){
        printf("After initial seperation:\n");
        printCarts();
    }

    if( k == carts.size() )
        return calcPrice();
    else if( k < carts.size() )
        unionCarts();
    else
        seperateCarts();

    return calcPrice();
}

bool icmp( const item &ia , const item &ib ){
    if( ia.c != ib.c )
        return ia.c > ib.c;

    return ia.t > ib.t;
}

void loadData( void ){

    scanf("%d%d",&n,&k);

    sum = 0.0;
    for( int i = 0 ; i < n ; i ++ ){
        scanf("%d%d",&items[i].c,&items[i].t);
        items[i].index = i;
        sum += (double)items[i].c;
    }
    return;
}

void printRes( double res ){

    printf("%.1lf\n",res);
    for( int i = 0 ; i < carts.size() ; i ++ ){
        int carts_size = 0;
        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ )
            if( carts[i].inCart[j] )
                carts_size ++;
        printf("%d",carts_size + ( carts[i].stoolIndex == -1 ? 0 : 1 ) );
        if( carts[i].stoolIndex != -1 )
            printf(" %d",carts[i].stoolIndex+1);
        for( int j = 0 ; j < carts[i].pencils.size() ; j ++ )
            if( carts[i].inCart[j] )
                printf(" %d",carts[i].pencils[j].index+1);
        printf("\n");
    }
    return;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;
struct tovar
{int i, c, naz;
} a[1005];
bool cmp(tovar a, tovar b)
{return a.c>b.c;}
vector <int> ans[1005];
double s=0;
int main()
{//freopen("i.txt","r",stdin);
int n,k; cin>>n>>k;
for (int i=1;i<=n;i++)
{a[i].i=i; cin>>a[i].c>>a[i].naz;}
sort(a+1,a+n+1,cmp);
//for (int i=1;i<=n;i++)  cout<<a[i].i<<"   "<<a[i].c<<"  "<<a[i].naz<<endl;
int j=1;
for (int i=1;i<=n;i++)
{ans[j].push_back(a[i].i);
 if (a[i].naz==1&&(j!=k||i==n)) {s+=(a[i].c+0.0)/2;j++;}
   else
    {if (i==n) s+=(a[i].c+0.0)/2; else s+=a[i].c;
     if (n-i==k-j) j++;
   }
}
cout.precision(1);
cout.setf(cout.fixed);
cout<<s<<endl;
for (int i=1;i<=k;i++)
{cout<<ans[i].size()<<" ";
  for (int j=0;j<ans[i].size();j++)
   cout<<ans[i][j]<<" ";
  cout<<endl;
}
return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;
struct tovar
{int i, c, naz;
} a[1005];
bool cmp(tovar a, tovar b)
{return a.c>b.c;}
vector <int> ans[1005];
double s=0;
int main()
{freopen("i.txt","r",stdin);
int n,k; cin>>n>>k;
for (int i=1;i<=n;i++)
{a[i].i=i; cin>>a[i].c>>a[i].naz;}
sort(a+1,a+n+1,cmp);
//for (int i=1;i<=n;i++)  cout<<a[i].i<<"   "<<a[i].c<<"  "<<a[i].naz<<endl;
int j=1;
for (int i=1;i<=n;i++)
{ans[j].push_back(a[i].i);
 if (a[i].naz==1&&(j!=k||i==n)) {s+=(a[i].c+0.0)/2;j++;}
   else {s+=a[i].c; if (n-i==k-j) j++;}
}
cout.precision(1);
cout.setf(cout.fixed);
cout<<s<<endl;
for (int i=1;i<=k;i++)
{cout<<ans[i].size()<<" ";
  for (int j=0;j<ans[i].size();j++)
   cout<<ans[i][j]<<" ";
  cout<<endl;
}
return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;
struct tovar
{int i, c, naz;
} a[1005];
bool cmp(tovar a, tovar b)
{return a.c>b.c;}
vector <int> ans[1005];
double s=0;
int main()
{//freopen("i.txt","r",stdin);
int n,k; cin>>n>>k;
int kt=0;
for (int i=1;i<=n;i++)
{a[i].i=i;  cin>>a[i].c>>a[i].naz;
if (a[i].naz==1) kt++;
}
sort(a+1,a+n+1,cmp);
//for (int i=1;i<=n;i++)  cout<<a[i].i<<"   "<<a[i].c<<"  "<<a[i].naz<<endl;
int j=1;
for (int i=1;i<=n;i++)
{ans[j].push_back(a[i].i);
 if (a[i].naz==1&&(j!=k||i==n))
    {s+=(a[i].c+0.0)/2;j++;}
   else
    {if (i==n&&kt>=k) s+=(a[i].c+0.0)/2; else s+=a[i].c;
     if (n-i==k-j) j++;
   }
}
cout.precision(1);
cout.setf(cout.fixed);
cout<<s<<endl;
for (int i=1;i<=k;i++)
{cout<<ans[i].size()<<" ";
  for (int j=0;j<ans[i].size();j++)
   cout<<ans[i][j]<<" ";
  cout<<endl;
}
return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;
struct tovar
{int i, c, naz;
} a[1005];
bool cmp(tovar a, tovar b)
{return a.c>b.c;}
vector <int> ans[1005];
double s=0;
int main()
{//freopen("i.txt","r",stdin);
int n,k; cin>>n>>k;
for (int i=1;i<=n;i++)
{a[i].i=i; cin>>a[i].c>>a[i].naz;}
sort(a+1,a+n+1,cmp);
//for (int i=1;i<=n;i++)  cout<<a[i].i<<"   "<<a[i].c<<"  "<<a[i].naz<<endl;
int j=1;
for (int i=1;i<=n;i++)
{ans[j].push_back(a[i].i);
 if (a[i].naz==1&&(j!=k||i==n)) {s+=(a[i].c+0.0)/2;j++;}
   else {s+=a[i].c; if (n-i==k-j) j++;}
}
cout.precision(1);
cout.setf(cout.fixed);
cout<<s<<endl;
for (int i=1;i<=k;i++)
{cout<<ans[i].size()<<" ";
  for (int j=0;j<ans[i].size();j++)
   cout<<ans[i][j]<<" ";
  cout<<endl;
}
return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

const int MAXN = 1007;

struct item {
  int price;
  int index;
  item(int p, int i) { price = p; index = i; }
  item() { price=index = 0; }
};

vector<item> magic,regular;
int n,k,p,t;

bool fp(item a, item b) {
  return a.price>=b.price;
}

vector<item> cart[MAXN];
bool magical[MAXN];

int main() {
  scanf("%d%d", &n,&k);
  while(k>n);
  for(int i=1; i<=n; ++i) {
    scanf("%d%d",&p,&t);
    if(t==1) magic.push_back(item(p,i));
    else regular.push_back(item(p,i));
  }
  sort(magic.begin(), magic.end(),fp);
  sort(regular.begin(), regular.end(),fp);

  vector<item>::iterator mit = magic.begin();
  vector<item>::iterator rit = regular.begin();

  long long rp=0,mp=0;

  for(int i=1; i<=k; ++i) {
    if(i==k) {
      while(mit!=magic.end()) {
        cart[i].push_back(*mit);
        mit++;
        magical[i] = true;
      }
      while(rit!=regular.end()) {
        cart[i].push_back(*rit);
        rit++;
      }
    } else {
      if(mit!=magic.end()) {
        cart[i].push_back(*mit);
        ++mit;
        magical[i]=true;
      } else {
        cart[i].push_back(*rit);
        ++rit;
      }
    }
    sort(cart[i].begin(), cart[i].end(),fp);
    for(int j=0; j<cart[i].size()-1; ++j) {
      rp+=cart[i][j].price;
    }
    if(magical[i])
      mp+=cart[i][cart[i].size()-1].price;
    else
      rp+=cart[i][cart[i].size()-1].price;
  }
  printf("%I64d", mp/2+rp); // change this.
  if(mp%2) printf(".5");
  else printf(".0");
  printf("\n");
  for(int i=1; i<=k; ++i) {
    printf("%d ", cart[i].size());
    for(int j=0; j<cart[i].size(); ++j)
      printf("%d ", cart[i][j].index);
    printf("\n");
  }
}


#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

const int MAXN = 1007;

struct item {
  int price;
  int index;
  item(int p, int i) { price = p; index = i; }
  item() { price=index = 0; }
};

vector<item> magic,regular;
int n,k,p,t;

bool fp(item a, item b) {
  return a.price>=b.price;
}

vector<item> cart[MAXN];
bool magical[MAXN];

int main() {
  scanf("%d%d", &n,&k);
  while(k>n);
  for(int i=1; i<=n; ++i) {
    scanf("%d%d",&p,&t);
    if(t==1) magic.push_back(item(p,i));
    else regular.push_back(item(p,i));
  }
  sort(magic.begin(), magic.end(),fp);
  sort(regular.begin(), regular.end(),fp);

  vector<item>::iterator mit = magic.begin();
  vector<item>::iterator rit = regular.begin();

  long long rp=0,mp=0;

  for(int i=1; i<=k; ++i) {
    if(i==k) {
      while(mit!=magic.end()) {
        cart[i].push_back(*mit);
        mit++;
        magical[i] = true;
      }
      while(rit!=regular.end()) {
        cart[i].push_back(*rit);
        rit++;
      }
    } else {
      if(mit!=magic.end()) {
        cart[i].push_back(*mit);
        ++mit;
        magical[i]=true;
      } else {
        while(rit==regular.end());
        cart[i].push_back(*rit);
        ++rit;
      }
    }
    sort(cart[i].begin(), cart[i].end(),fp);
    for(int j=0; j<cart[i].size()-1; ++j) {
      rp+=cart[i][j].price;
    }
    if(magical[i])
      mp+=cart[i][cart[i].size()-1].price;
    else
      rp+=cart[i][cart[i].size()-1].price;
  }
  printf("%I64d", mp/2+rp); // change this.
  if(mp%2) printf(".5");
  else printf(".0");
  printf("\n");
  for(int i=1; i<=k; ++i) {
    printf("%d ", cart[i].size());
    for(int j=0; j<cart[i].size(); ++j)
      printf("%d ", cart[i][j].index);
    printf("\n");
  }
}


#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

const int MAXN = 1007;

struct item {
  int price;
  int index;
  item(int p, int i) { price = p; index = i; }
  item() { price=index = 0; }
};

vector<item> magic,regular;
int n,k,p,t;

bool fp(item a, item b) {
  return a.price>b.price;
}

vector<item> cart[MAXN];
bool magical[MAXN];

int main() {
  scanf("%d%d", &n,&k);
  for(int i=1; i<=n; ++i) {
    scanf("%d%d",&p,&t);
    if(t==1) magic.push_back(item(p,i));
    else regular.push_back(item(p,i));
  }
  sort(magic.begin(), magic.end(),fp);
  sort(regular.begin(), regular.end(),fp);

  vector<item>::iterator mit = magic.begin();
  vector<item>::iterator rit = regular.begin();

  long long rp=0,mp=0;

  for(int i=1; i<=k; ++i) {
    if(i==k) {
      while(mit!=magic.end()) {
        cart[i].push_back(*mit);
        mit++;
        magical[i] = true;
      }
      while(rit!=regular.end()) {
        cart[i].push_back(*rit);
        rit++;
      }
    } else {
      if(mit!=magic.end()) {
        cart[i].push_back(*mit);
        ++mit;
        magical[i]=true;
      } else {
        cart[i].push_back(*rit);
        ++rit;
      }
    }
    sort(cart[i].begin(), cart[i].end(),fp);
    for(int j=0; j<cart[i].size()-1; ++j) {
      rp+=cart[i][j].price;
    }
    if(magical[i])
      mp+=cart[i][cart[i].size()-1].price;
    else
      rp+=cart[i][cart[i].size()-1].price;
  }
  printf("%I64d", mp/2+rp); // change this.
  if(mp%2) printf(".5");
  else printf(".0");
  printf("\n");
  for(int i=1; i<=k; ++i) {
    printf("%d ", cart[i].size());
    for(int j=0; j<cart[i].size(); ++j)
      printf("%d ", cart[i][j].index);
    printf("\n");
  }
}


#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

const int MAXN = 1007;

struct item {
  int price;
  int index;
  item(int p, int i) { price = p; index = i; }
  item() { price=index = 0; }
};

vector<item> magic,regular;
int n,k,p,t;

bool fp(item a, item b) {
  return a.price>=b.price;
}

vector<item> cart[MAXN];
bool magical[MAXN];

int main() {
  scanf("%d%d", &n,&k);
  for(int i=1; i<=n; ++i) {
    scanf("%d%d",&p,&t);
    if(t==1) magic.push_back(item(p,i));
    else regular.push_back(item(p,i));
  }
  sort(magic.begin(), magic.end(),fp);
  sort(regular.begin(), regular.end(),fp);
  vector<item>::iterator mit = magic.begin();
  vector<item>::iterator rit = regular.begin();

  long long rp=0,mp=0;

  for(int i=1; i<=k; ++i) {
    if(i==k) {
      while(mit!=magic.end()) {
        cart[i].push_back(*mit);
        mit++;
        magical[i] = true;
      }
      while(rit!=regular.end()) {
        cart[i].push_back(*rit);
        rit++;
      }
    } else {
      if(mit!=magic.end()) {
        cart[i].push_back(*mit);
        ++mit;
        magical[i]=true;
      } else {
        cart[i].push_back(*rit);
        ++rit;
      }
    }
    sort(cart[i].begin(), cart[i].end(),fp);
    for(int j=0; j<cart[i].size()-1; ++j) {
      rp+=cart[i][j].price;
    }
    if(magical[i])
      mp+=cart[i][cart[i].size()-1].price;
    else
      rp+=cart[i][cart[i].size()-1].price;
  }
  printf("%I64d", mp/2+rp); // change this.
  if(mp%2) printf(".5");
  else printf(".0");
  printf("\n");
  for(int i=1; i<=k; ++i) {
    printf("%d ", cart[i].size());
    for(int j=0; j<cart[i].size(); ++j)
      printf("%d ", cart[i][j].index);
    printf("\n");
  }
}


#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

const int MAXN = 1007;

struct item {
  int price;
  int index;
  item(int p, int i) { price = p; index = i; }
  item() { price=index = 0; }
};

vector<item> magic,regular;
int n,k,p,t;

bool fp(item a, item b) {
  return a.price>=b.price;
}

vector<item> cart[MAXN];
bool magical[MAXN];

int main() {
  scanf("%d%d", &n,&k);
  for(int i=1; i<=n; ++i) {
    scanf("%d%d",&p,&t);
    if(t==1) magic.push_back(item(p,i));
    else regular.push_back(item(p,i));
  }
  sort(magic.begin(), magic.end(),fp);
  sort(regular.begin(), regular.end(),fp);

  vector<item>::iterator mit = magic.begin();
  vector<item>::iterator rit = regular.begin();

  long long rp=0,mp=0;

  for(int i=1; i<=k; ++i) {
    if(i==k) {
      while(mit!=magic.end()) {
        cart[i].push_back(*mit);
        mit++;
        magical[i] = true;
      }
      while(rit!=regular.end()) {
        cart[i].push_back(*rit);
        rit++;
      }
    } else {
      if(mit!=magic.end()) {
        cart[i].push_back(*mit);
        ++mit;
        magical[i]=true;
      } else {
        cart[i].push_back(*rit);
        ++rit;
      }
    }
    while(cart[i].size() == 0);
    sort(cart[i].begin(), cart[i].end(),fp);
    for(int j=0; j<cart[i].size()-1; ++j) {
      rp+=cart[i][j].price;
    }
    if(magical[i])
      mp+=cart[i][cart[i].size()-1].price;
    else
      rp+=cart[i][cart[i].size()-1].price;
  }
  printf("%I64d", mp/2+rp); // change this.
  if(mp%2) printf(".5");
  else printf(".0");
  printf("\n");
  for(int i=1; i<=k; ++i) {
    printf("%d ", cart[i].size());
    for(int j=0; j<cart[i].size(); ++j)
      printf("%d ", cart[i][j].index);
    printf("\n");
  }
}


#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

const int MAXN = 1007;

struct item {
  int price;
  int index;
  item(int p, int i) { price = p; index = i; }
  item() { price=index = 0; }
};

vector<item> magic,regular;
int n,k,p,t;

bool fp(item a, item b) {
  return a.price>=b.price;
}

vector<item> cart[MAXN];
bool magical[MAXN];

int main() {
  scanf("%d%d", &n,&k);
  while(k>MAXN-1);
  for(int i=1; i<=n; ++i) {
    scanf("%d%d",&p,&t);
    if(t==1) magic.push_back(item(p,i));
    else regular.push_back(item(p,i));
  }
  sort(magic.begin(), magic.end(),fp);
  sort(regular.begin(), regular.end(),fp);

  vector<item>::iterator mit = magic.begin();
  vector<item>::iterator rit = regular.begin();

  long long rp=0,mp=0;

  for(int i=1; i<=k; ++i) {
    if(i==k) {
      while(mit!=magic.end()) {
        cart[i].push_back(*mit);
        mit++;
        magical[i] = true;
      }
      while(rit!=regular.end()) {
        cart[i].push_back(*rit);
        rit++;
      }
    } else {
      if(mit!=magic.end()) {
        cart[i].push_back(*mit);
        ++mit;
        magical[i]=true;
      } else {
        cart[i].push_back(*rit);
        ++rit;
      }
    }
    sort(cart[i].begin(), cart[i].end(),fp);
    for(int j=0; j<cart[i].size()-1; ++j) {
      rp+=cart[i][j].price;
    }
    if(magical[i])
      mp+=cart[i][cart[i].size()-1].price;
    else
      rp+=cart[i][cart[i].size()-1].price;
  }
  printf("%I64d", mp/2+rp); // change this.
  if(mp%2) printf(".5");
  else printf(".0");
  printf("\n");
  for(int i=1; i<=k; ++i) {
    printf("%d ", cart[i].size());
    for(int j=0; j<cart[i].size(); ++j)
      printf("%d ", cart[i][j].index);
    printf("\n");
  }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.LinkedList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author baukaman
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public static int pointId = 0;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int ax, ay, bx, by, tx, ty;

            Point adil = new Point(in.nextInt(), in.nextInt());
            Point beta = new Point(in.nextInt(), in.nextInt());
            Point trash = new Point(in.nextInt(), in.nextInt());

            int n = in.nextInt();
            List<Point> bottles = new LinkedList<Point>();
            double total = 0;

            for (int i = 0; i < n; i++) {
                Point bottle = new Point(in.nextInt(), in.nextInt());
                bottles.add(bottle);
                total += trash.dist(bottle);
            }

            double ans = Double.MAX_VALUE;

            PriorityQueue<Decision> aQueue = getDecision(adil, bottles, trash);
            PriorityQueue<Decision> bQueue = getDecision(beta, bottles, trash);

            aQueue.add(new Decision());
            bQueue.add(new Decision());

            for (Decision aDecision : aQueue.toArray(new Decision[0])) {
                for (Decision bDecision : bQueue.toArray(new Decision[0])) {
                    double localAns = 2. * total;
                    localAns += aDecision.dist;

                    if (bDecision.id != aDecision.id)
                        localAns += bDecision.dist;

                    ans = Math.min(ans, localAns);
                }
            }

            out.println(ans);
        }

        private PriorityQueue<Decision> getDecision(Point adil, List<Point> bottles, Point trash) {
            PriorityQueue<Decision> aQueue = new PriorityQueue<>();

            for (Point bottle : bottles) {
                aQueue.add(new Decision(adil.dist(bottle) - bottle.dist(trash), bottle.id));
                if (aQueue.size() > 2) {
                    aQueue.poll();
                }
            }
            return aQueue;
        }

        public class Point {
            int x;
            int y;
            public int id;

            public Point(int xx, int yy) {
                x = xx;
                y = yy;
                this.id = pointId++;
            }

            public double dist(Point p) {
                return Math.hypot(x - p.x, y - p.y);
            }

        }

        public class Decision implements Comparable<Decision> {
            double dist;
            int id;

            public Decision() {
                dist = 0.0;
                id = -1;
            }

            public Decision(double dist, int id) {
                this.dist = dist;
                this.id = id;
            }

            public int compareTo(Decision o) {
                return -(dist < o.dist ? -1 : 1);
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.PriorityQueue;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.LinkedList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author baukaman
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public static int pointId = 0;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int ax, ay, bx, by, tx, ty;

            double t = Math.hypot(3, 5);
            System.out.println(t);

            Point adil = new Point(in.nextInt(), in.nextInt());
            Point beta = new Point(in.nextInt(), in.nextInt());
            Point trash = new Point(in.nextInt(), in.nextInt());

            int n = in.nextInt();
            List<Point> bottles = new LinkedList<Point>();
            double total = 0;

            for (int i = 0; i < n; i++) {
                Point bottle = new Point(in.nextInt(), in.nextInt());
                bottles.add(bottle);
                total += trash.dist(bottle);
            }

            double ans = 2 * total;

            PriorityQueue<Decision> aQueue = getDecision(adil, bottles, trash);
            PriorityQueue<Decision> bQueue = getDecision(beta, bottles, trash);

            aQueue.add(new Decision());
            bQueue.add(new Decision());

            for (Decision aDecision : aQueue.toArray(new Decision[0])) {
                for (Decision bDecision : bQueue.toArray(new Decision[0])) {
                    double localAns = 2. * total;
                    localAns += aDecision.dist;

                    if (bDecision.id != aDecision.id)
                        localAns += bDecision.dist;

                    ans = Math.min(ans, localAns);
                }
            }

            out.println(ans);
        }

        private PriorityQueue<Decision> getDecision(Point adil, List<Point> bottles, Point trash) {
            PriorityQueue<Decision> aQueue = new PriorityQueue<>();

            for (Point bottle : bottles) {
                aQueue.add(new Decision(adil.dist(bottle) - bottle.dist(trash), bottle.id));
                if (aQueue.size() > 2) {
                    aQueue.poll();
                }
            }
            return aQueue;
        }

        public class Point {
            int x;
            int y;
            public int id;

            public Point(int xx, int yy) {
                x = xx;
                y = yy;
                this.id = pointId++;
            }

            public double dist(Point p) {
                return Math.hypot(x - p.x, y - p.y);
            }

        }

        public class Decision implements Comparable<Decision> {
            double dist;
            int id;

            public Decision() {
                dist = 0.0;
                id = -1;
            }

            public Decision(double dist, int id) {
                this.dist = dist;
                this.id = id;
            }

            public int compareTo(Decision o) {
                return -(dist < o.dist ? -1 : 1);
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
#include<limits.h>
int ax,ay,bx,by,tx,ty,n;
double sqr(double t){
    return t*t;
}
double min(double a,double b){
    if(a<b){
        return a;
    }
    return b;
}
double measure_distance(int x,int y,int btl[][2],int index){
    return sqrt(sqr(btl[index][0]-x)+sqr(btl[index][1]-y));
}
void swap(double *a,double *b){
    double t=*a;
    *a=*b;
    *b=t;
}
double fix(int a,int b,double bin_btl[],double adi_btl[],double ban_btl[]){
    //adi is going to a and ban is going to b
    return adi_btl[a]-bin_btl[a]+ban_btl[b]-bin_btl[b];
}

double fix2(int i,double bin_btl[],double user_btl[]){
    return user_btl[i]-bin_btl[i];
}

int main(){
    scanf("%d %d %d %d %d %d",&ax,&ay,&bx,&by,&tx,&ty);
    scanf("%d",&n);
    int bottle[n][2];
    for(int i=0;i<n;i++){
        scanf("%d %d",&bottle[i][0],&bottle[i][1]);
    }
    double bin_btl[n],adi_btl[n],ban_btl[n];
    double T=0;
    for(int i=0;i<n;i++){
        bin_btl[i]=measure_distance(tx,ty,bottle,i);
        adi_btl[i]=measure_distance(ax,ay,bottle,i);
        ban_btl[i]=measure_distance(bx,by,bottle,i);
        T+=bin_btl[i];
    }
    T=2*T;
    double A[n],B[n];
    for(int i=0;i<n;i++){
        A[i]=adi_btl[i]-bin_btl[i];
        B[i]=ban_btl[i]-bin_btl[i];
    }
    double ans=DBL_MAX;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i!=j && ans>A[i]+B[j]){
                ans=A[i]+B[j];
            }
        }
    }
    ans+=T;
    /*
    double min_a1=DBL_MAX,min_a2=DBL_MAX,min_b1=DBL_MAX,min_b2=DBL_MAX;
    int a,b;
    for(int i=0;i<n;i++){
        if(min_a1>fix2(i,bin_btl,adi_btl)){
            min_a2=min_a1;
            min_a1=fix2(i,bin_btl,adi_btl);
            a=i;
        }
        else if(min_a2>fix2(i,bin_btl,adi_btl)){
            min_a2=fix2(i,bin_btl,adi_btl);
        }

        if(min_b1>fix2(i,bin_btl,ban_btl)){
            min_b2=min_b1;
            min_b1=fix2(i,bin_btl,ban_btl);
            b=i;
        }
        else if(min_b2>fix2(i,bin_btl,ban_btl)){
            min_b2=fix2(i,bin_btl,ban_btl);
        }

    }

        if(a==b){
            if(min_a1+min_b2<min_a2+min_b1){
                swap(min_b1,min_b2);
            }
            else{
                swap(min_a1,min_a2);
            }
        }
        double final_fix=min_a1+min_b1;
        double ans=T+final_fix;
        */
        printf("%.12lf\n",ans);
        return 0;
    }


#include<bits/stdc++.h>
using namespace std;
#include<limits.h>
int ax,ay,bx,by,tx,ty,n;
double sqr(double t){
    return t*t;
}
double min(double a,double b){
    if(a<b){
        return a;
    }
    return b;
}
double measure_distance(int x,int y,int btl[][2],int index){
    return sqrt(sqr(btl[index][0]-x)+sqr(btl[index][1]-y));
}
void swap(double *a,double *b){
    double t=*a;
    *a=*b;
    *b=t;
}
double fix(int a,int b,double bin_btl[],double adi_btl[],double ban_btl[]){
    //adi is going to a and ban is going to b
    return adi_btl[a]-bin_btl[a]+ban_btl[b]-bin_btl[b];
}

double fix2(int i,double bin_btl[],double user_btl[]){
    return user_btl[i]-bin_btl[i];
}

int main(){
    scanf("%d %d %d %d %d %d",&ax,&ay,&bx,&by,&tx,&ty);
    scanf("%d",&n);
    int bottle[n][2];
    for(int i=0;i<n;i++){
        scanf("%d %d",&bottle[i][0],&bottle[i][1]);
    }
    double bin_btl[n],adi_btl[n],ban_btl[n];
    double T=0;
    for(int i=0;i<n;i++){
        bin_btl[i]=measure_distance(tx,ty,bottle,i);
        adi_btl[i]=measure_distance(ax,ay,bottle,i);
        ban_btl[i]=measure_distance(bx,by,bottle,i);
        T+=bin_btl[i];
    }
    T=2*T;
    double ans=T;
    pair<double,int> A[n];
    pair<double,int> B[n];
    //printf("A\t\tB\n");
    for(int i=0;i<n;i++){
        A[i]=make_pair(adi_btl[i]-bin_btl[i],i);
        B[i]=make_pair(ban_btl[i]-bin_btl[i],i);
      //  printf("%lf\t\t%lf\n",A[i],B[i]);
    }
    sort(A,A+n);
    sort(B,B+n);
    int pt1=A[0].second,pt2=B[0].second;
    double d1=A[0].first,d2=B[0].first;
    //printf("d1:%lf d2:%lf T:%lf\n",d1,d2,T);
    if(d1>=0 || d2>=0){
      //  printf("case 1:\n");
        ans+=min(d1,d2);
    }else if(pt1==pt2){
        //printf("case 2:\n");
        double ans1=d1;
        double ans2=d2;
        double ans3=d1+B[1].first;
        double ans4=d2+A[1].first;
        double add=min(ans1,ans2);
        add=min(add,ans3);
        add=min(add,ans4);
        ans+=add;
    }
    else
    {
       // printf("case 3:\n");
        ans+=d1+d2;
    }

    /*
    double min_a1=DBL_MAX,min_a2=DBL_MAX,min_b1=DBL_MAX,min_b2=DBL_MAX;
    int a,b;
    for(int i=0;i<n;i++){
        if(min_a1>fix2(i,bin_btl,adi_btl)){
            min_a2=min_a1;
            min_a1=fix2(i,bin_btl,adi_btl);
            a=i;
        }
        else if(min_a2>fix2(i,bin_btl,adi_btl)){
            min_a2=fix2(i,bin_btl,adi_btl);
        }

        if(min_b1>fix2(i,bin_btl,ban_btl)){
            min_b2=min_b1;
            min_b1=fix2(i,bin_btl,ban_btl);
            b=i;
        }
        else if(min_b2>fix2(i,bin_btl,ban_btl)){
            min_b2=fix2(i,bin_btl,ban_btl);
        }

    }

        if(a==b){
            if(min_a1+min_b2<min_a2+min_b1){
                swap(min_b1,min_b2);
            }
            else{
                swap(min_a1,min_a2);
            }
        }
        double final_fix=min_a1+min_b1;
        double ans=T+final_fix;
        */
        printf("%.12lf\n",ans);
        return 0;
    }


#include<bits/stdc++.h>
using namespace std;
#include<limits.h>
int ax,ay,bx,by,tx,ty,n;
double sqr(double t){
    return t*t;
}
double min(double a,double b){
    if(a<b){
        return a;
    }
    return b;
}
double measure_distance(int x,int y,int btl[][2],int index){
    return sqrt(sqr(btl[index][0]-x)+sqr(btl[index][1]-y));
}
void swap(double *a,double *b){
    double t=*a;
    *a=*b;
    *b=t;
}
double fix(int a,int b,double bin_btl[],double adi_btl[],double ban_btl[]){
    //adi is going to a and ban is going to b
    return adi_btl[a]-bin_btl[a]+ban_btl[b]-bin_btl[b];
}

double fix2(int i,double bin_btl[],double user_btl[]){
    return user_btl[i]-bin_btl[i];
}

int main(){
    scanf("%d %d %d %d %d %d",&ax,&ay,&bx,&by,&tx,&ty);
    scanf("%d",&n);
    int bottle[n][2];
    for(int i=0;i<n;i++){
        scanf("%d %d",&bottle[i][0],&bottle[i][1]);
    }
    double bin_btl[n],adi_btl[n],ban_btl[n];
    double T=0;
    for(int i=0;i<n;i++){
        bin_btl[i]=measure_distance(tx,ty,bottle,i);
        adi_btl[i]=measure_distance(ax,ay,bottle,i);
        ban_btl[i]=measure_distance(bx,by,bottle,i);
        T+=bin_btl[i];
    }
    T=2*T;
    double min_a1=DBL_MAX,min_a2=DBL_MAX,min_b1=DBL_MAX,min_b2=DBL_MAX;
    int a,b;
    for(int i=0;i<n;i++){
        if(min_a1>fix2(i,bin_btl,adi_btl)){
            min_a2=min_a1;
            min_a1=fix2(i,bin_btl,adi_btl);
            a=i;
        }
        else if(min_a2>fix2(i,bin_btl,adi_btl)){
            min_a2=fix2(i,bin_btl,adi_btl);
        }

        if(min_b1>fix2(i,bin_btl,ban_btl)){
            min_b2=min_b1;
            min_b1=fix2(i,bin_btl,ban_btl);
            b=i;
        }
        else if(min_b2>fix2(i,bin_btl,ban_btl)){
            min_b2=fix2(i,bin_btl,ban_btl);
        }

    }

        if(a==b){
            if(min_a1+min_b2<min_a2+min_b1){
                swap(min_b1,min_b2);
            }
            else{
                swap(min_a1,min_a2);
            }
        }
        double final_fix=min_a1+min_b1;
        double ans=T+final_fix;
        printf("%.12lf\n",ans);
        return 0;
    }


#include<bits/stdc++.h>
using namespace std;
#include<limits.h>
int ax,ay,bx,by,tx,ty,n;
double sqr(double t){
    return t*t;
}
double min(double a,double b){
    if(a<b){
        return a;
    }
    return b;
}
double measure_distance(int x,int y,int btl[][2],int index){
    return sqrt(sqr(btl[index][0]-x)+sqr(btl[index][1]-y));
}
void swap(double *a,double *b){
    double t=*a;
    *a=*b;
    *b=t;
}
double fix(int a,int b,double bin_btl[],double adi_btl[],double ban_btl[]){
    //adi is going to a and ban is going to b
    return adi_btl[a]-bin_btl[a]+ban_btl[b]-bin_btl[b];
}

double fix2(int i,double bin_btl[],double user_btl[]){
    return user_btl[i]-bin_btl[i];
}

int main(){
    scanf("%d %d %d %d %d %d",&ax,&ay,&bx,&by,&tx,&ty);
    scanf("%d",&n);
    int bottle[n][2];
    for(int i=0;i<n;i++){
        scanf("%d %d",&bottle[i][0],&bottle[i][1]);
    }
    double bin_btl[n],adi_btl[n],ban_btl[n];
    double T=0;
    for(int i=0;i<n;i++){
        bin_btl[i]=measure_distance(tx,ty,bottle,i);
        adi_btl[i]=measure_distance(ax,ay,bottle,i);
        ban_btl[i]=measure_distance(bx,by,bottle,i);
        T+=bin_btl[i];
    }
    T=2*T;
    double A[n],B[n];
    for(int i=0;i<n;i++){
        A[i]=adi_btl[i]-bin_btl[i];
        B[i]=ban_btl[i]-bin_btl[i];
    }
    double distance1=DBL_MAX,distance2=DBL_MAX,distance3=DBL_MAX,p,q,ans;
    for(int i=0;i<n;i++){
        if(distance1>A[i]){
            distance1=A[i];
            p=i;
        }
        if(distance2>B[i]){
            distance3=distance2;
            distance2=B[i];
            q=i;
        }else if(distance3>B[i]){
            distance3=B[i];
        }
    }
    if(p==q){
        ans=T+distance1+distance3;
    }
    else{
        ans=T+distance1+distance2;
    }
    /*
    double min_a1=DBL_MAX,min_a2=DBL_MAX,min_b1=DBL_MAX,min_b2=DBL_MAX;
    int a,b;
    for(int i=0;i<n;i++){
        if(min_a1>fix2(i,bin_btl,adi_btl)){
            min_a2=min_a1;
            min_a1=fix2(i,bin_btl,adi_btl);
            a=i;
        }
        else if(min_a2>fix2(i,bin_btl,adi_btl)){
            min_a2=fix2(i,bin_btl,adi_btl);
        }

        if(min_b1>fix2(i,bin_btl,ban_btl)){
            min_b2=min_b1;
            min_b1=fix2(i,bin_btl,ban_btl);
            b=i;
        }
        else if(min_b2>fix2(i,bin_btl,ban_btl)){
            min_b2=fix2(i,bin_btl,ban_btl);
        }

    }

        if(a==b){
            if(min_a1+min_b2<min_a2+min_b1){
                swap(min_b1,min_b2);
            }
            else{
                swap(min_a1,min_a2);
            }
        }
        double final_fix=min_a1+min_b1;
        double ans=T+final_fix;
        */
        printf("%.12lf\n",ans);
        return 0;
    }


//print long double %0.12Lf
#include<bits/stdc++.h>
using namespace std;
int main(){
    int ax,ay,bx,by,tx,ty,n;
    scanf("%d %d %d %d %d %d",&ax,&ay,&bx,&by,&tx,&ty);
    scanf("%d",&n);
    int X[n],Y[n];
    for(int i=0;i<n;i++){
        scanf("%d %d",&X[i],&Y[i]);
    }
    long double T=0;
    for(int i=0;i<n;i++){
        long long int tmp=((X[i]-tx)*(X[i]-tx))+((Y[i]-ty)*(Y[i]-ty));
        T+=sqrt(tmp);
    }
    T=2*T;
    long double A[n],B[n];
    for(int i=0;i<n;i++){
        long double tmp=sqrt(((X[i]-tx)*(X[i]-tx))+((Y[i]-ty)*(Y[i]-ty)));
        long double addi_to_bottle=sqrt(((X[i]-ax)*(X[i]-ax))+((Y[i]-ay)*(Y[i]-ay)));
        long double bera_to_bottle=sqrt(((X[i]-bx)*(X[i]-bx))+((Y[i]-by)*(Y[i]-by)));
        A[i]=addi_to_bottle-tmp;
        B[i]=bera_to_bottle-tmp;
    }
    int a1,a2,b1,b2;
    long double min1=10000000000000,min2=10000000000000,min3=10000000000000,min4=10000000000000;
    int a,b;
    for(int i=0;i<n;i++){
        if(min1>A[i]){
            min2=min1;
            min1=A[i];
            a=i;
        }
        else if(min2>A[i]){
            min2=A[i];
        }
        if(min3>B[i]){
                min4=min3;
                min3=B[i];
                b=i;
        }
        else if(min4>B[i]){
            min4=B[i];
        }
    }
    long double ans=T;
    if(a==b){
        if(min2+min3<min1+min4){
            ans+=min2+min3;
        }
        else
        {
            ans+=min1+min4;
        }
    }
    else
    {
        ans+=min1+min3;
    }
  //  printf("%.12Lf\n",ans);
    cout<<setprecision(14)<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#include<limits.h>
int ax,ay,bx,by,tx,ty,n;
double sqr(double t){
    return t*t;
}
double min(double a,double b){
    if(a<b){
        return a;
    }
    return b;
}
double measure_distance(int x,int y,int btl[][2],int index){
    return sqrt(sqr(btl[index][0]-x)+sqr(btl[index][1]-y));
}
void swap(double *a,double *b){
    double t=*a;
    *a=*b;
    *b=t;
}
double fix(int a,int b,double bin_btl[],double adi_btl[],double ban_btl[]){
    //adi is going to a and ban is going to b
    return adi_btl[a]-bin_btl[a]+ban_btl[b]-bin_btl[b];
}

double fix2(int i,double bin_btl[],double user_btl[]){
    return user_btl[i]-bin_btl[i];
}

int main(){
    scanf("%d %d %d %d %d %d",&ax,&ay,&bx,&by,&tx,&ty);
    scanf("%d",&n);
    int bottle[n][2];
    for(int i=0;i<n;i++){
        scanf("%d %d",&bottle[i][0],&bottle[i][1]);
    }
    double bin_btl[n],adi_btl[n],ban_btl[n];
    double T=0;
    for(int i=0;i<n;i++){
        bin_btl[i]=measure_distance(tx,ty,bottle,i);
        adi_btl[i]=measure_distance(ax,ay,bottle,i);
        ban_btl[i]=measure_distance(bx,by,bottle,i);
        T+=bin_btl[i];
    }
    T=2*T;
    double ans;
    pair<double,int> A[n];
    pair<double,int> B[n];
    for(int i=0;i<n;i++){
        A[i]=make_pair(adi_btl[i]-bin_btl[i],i);
        B[i]=make_pair(ban_btl[i]-bin_btl[i],i);
    }
    sort(A,A+n);
    sort(B,B+n);
    if(A[0].second==B[0].second){
        if(n!=1){
        if(A[0].first+B[1].first<A[1].first+B[0].first){
            ans=A[0].first+B[1].first+T;
        }
        else
        {
            ans=A[1].first+B[0].first+T;
        }
        }
        else
        {
            if(A[0].first<B[0].first){
                ans=T+A[0].first;
            }
            else
            {
                ans=T+B[0].first;
            }
        }
    }else{
        ans=T+A[0].first+B[0].first;
    }
    /*
    double min_a1=DBL_MAX,min_a2=DBL_MAX,min_b1=DBL_MAX,min_b2=DBL_MAX;
    int a,b;
    for(int i=0;i<n;i++){
        if(min_a1>fix2(i,bin_btl,adi_btl)){
            min_a2=min_a1;
            min_a1=fix2(i,bin_btl,adi_btl);
            a=i;
        }
        else if(min_a2>fix2(i,bin_btl,adi_btl)){
            min_a2=fix2(i,bin_btl,adi_btl);
        }

        if(min_b1>fix2(i,bin_btl,ban_btl)){
            min_b2=min_b1;
            min_b1=fix2(i,bin_btl,ban_btl);
            b=i;
        }
        else if(min_b2>fix2(i,bin_btl,ban_btl)){
            min_b2=fix2(i,bin_btl,ban_btl);
        }

    }

        if(a==b){
            if(min_a1+min_b2<min_a2+min_b1){
                swap(min_b1,min_b2);
            }
            else{
                swap(min_a1,min_a2);
            }
        }
        double final_fix=min_a1+min_b1;
        double ans=T+final_fix;
        */
        printf("%.12lf\n",ans);
        return 0;
    }


//print long double %0.12Lf
#include<bits/stdc++.h>
using namespace std;
int main(){
    int ax,ay,bx,by,tx,ty,n;
    scanf("%d %d %d %d %d %d",&ax,&ay,&bx,&by,&tx,&ty);
    scanf("%d",&n);
    int X[n],Y[n];
    for(int i=0;i<n;i++){
        scanf("%d %d",&X[i],&Y[i]);
    }
    long double T=0;
    for(int i=0;i<n;i++){
        long long int tmp=((X[i]-tx)*(X[i]-tx))+((Y[i]-ty)*(Y[i]-ty));
        T+=sqrt(tmp);
    }
    T=2*T;
    long double A[n],B[n];
    for(int i=0;i<n;i++){
        long double tmp=sqrt(((X[i]-tx)*(X[i]-tx))+((Y[i]-ty)*(Y[i]-ty)));
        long double addi_to_bottle=sqrt(((X[i]-ax)*(X[i]-ax))+((Y[i]-ay)*(Y[i]-ay)));
        long double bera_to_bottle=sqrt(((X[i]-bx)*(X[i]-bx))+((Y[i]-by)*(Y[i]-by)));
        A[i]=addi_to_bottle-tmp;
        B[i]=bera_to_bottle-tmp;
    }
    int a1,a2,b1,b2;
    long double min1=10000000000000,min2=10000000000000,min3=10000000000000,min4=10000000000000;
    int a,b;
    for(int i=0;i<n;i++){
        if(min1>A[i]){
            min2=min1;
            min1=A[i];
            a=i;
        }
        else if(min2>A[i]){
            min2=A[i];
        }
        if(min3>B[i]){
                min4=min3;
                min3=B[i];
                b=i;
        }
        else if(min4>B[i]){
            min4=B[i];
        }
    }
    long double ans=T;
    if(a==b){
        if(min2+min3<min1+min4){
            ans+=min2+min3;
        }
        else
        {
            ans+=min1+min4;
        }
    }
    else
    {
        ans+=min1+min3;
    }
    printf("%.12Lf\n",ans);
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

const int maxn = 100000+10;
#define mk make_pair
#define X first
#define Y second
typedef long long LL;
typedef pair<double,int> pp;
struct Point{
    int x,y;
    Point(int x=0,int y = 0):x(x),y(y){}
}P[maxn];
double BtoR[maxn];
pp AdtoB[maxn],BetoB[maxn];
int n,ax,ay,bx,by,tx,ty;
inline double dist(int x1,int y1,int x2,int y2) {
    return sqrt(double(x1-x2)*(x1-x2)+double(y1-y2)*(y1-y2));
}

int main() {

	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
	#endif
    cin >> ax >> ay >> bx >> by >> tx >> ty;
    cin >> n;
    double ret = 0.0;
    for(int i = 0; i < n; i++) cin >> P[i].x >> P[i].y;
    for(int i = 0; i < n; i++) {
        BtoR[i] = dist(P[i].x,P[i].y,tx,ty);
        ret += 2*BtoR[i];
    }
    for(int i = 0; i < n; i++) {
        AdtoB[i] = mk(dist(P[i].x,P[i].y,ax,ay)-BtoR[i],i);
    }
    for(int i = 0; i < n; i++){
        BetoB[i] = mk(dist(P[i].x,P[i].y,bx,by)-BtoR[i],i);
    }
    sort(AdtoB,AdtoB+n);
    sort(BetoB,BetoB+n);

    if(AdtoB[0].Y==BetoB[0].Y) {
        if(AdtoB[0].X > 0 && BetoB[0].X > 0) {
            ret += min(BetoB[0].X,AdtoB[0].X);
        }
        else if(AdtoB[0].X > 0) {
            ret += min(BetoB[0].X,0.0);
        }
        else if(BetoB[0].X > 0) {
            ret += min(AdtoB[0].X,0.0);
        }
        else{
            if(AdtoB[0].X+BetoB[1].X < BetoB[0].X+AdtoB[1].X) {
                ret += AdtoB[0].X+BetoB[1].X;
            }
            else{
                ret += BetoB[0].X+AdtoB[1].X;
            }
        }
    }
    else{
        ret += min(BetoB[0].X,0.0)+min(AdtoB[0].X,0.0);
        if(BetoB[0].X > 0 && AdtoB[0].X > 0) ret += min(BetoB[0].X,AdtoB[0].X);
    }

    printf("%.12f\n",ret);
    //cout<<ret<<endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

const int maxn = 100000+10;
#define mk make_pair
#define X first
#define Y second
typedef long long LL;
typedef pair<double,int> pp;
struct Point{
    int x,y;
    Point(int x=0,int y = 0):x(x),y(y){}
}P[maxn];
double BtoR[maxn];
pp AdtoB[maxn],BetoB[maxn];
int n,ax,ay,bx,by,tx,ty;
inline double dist(int x1,int y1,int x2,int y2) {
    return sqrt(double(x1-x2)*(x1-x2)+double(y1-y2)*(y1-y2));
}

int main() {

	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
	#endif
    cin >> ax >> ay >> bx >> by >> tx >> ty;
    cin >> n;
    double ret = 0.0;
    for(int i = 0; i < n; i++) cin >> P[i].x >> P[i].y;
    for(int i = 0; i < n; i++) {
        BtoR[i] = dist(P[i].x,P[i].y,tx,ty);
        ret += 2*BtoR[i];
    }
    for(int i = 0; i < n; i++) {
        AdtoB[i] = mk(dist(P[i].x,P[i].y,ax,ay)-BtoR[i],i);
    }
    for(int i = 0; i < n; i++){
        BetoB[i] = mk(dist(P[i].x,P[i].y,bx,by)-BtoR[i],i);
    }
    sort(AdtoB,AdtoB+n);
    sort(BetoB,BetoB+n);

    if(AdtoB[0].Y==BetoB[0].Y) {
        if(AdtoB[0].X >= 0 && BetoB[0].X >= 0) {
            ret += min(BetoB[0].X,AdtoB[0].X);
        }
        if(AdtoB[0].X >= 0 && BetoB[0].X <= 0) {
            ret += min(BetoB[0].X,0.0);
        }
        if(BetoB[0].X >= 0 && AdtoB[0].X <= 0) {
            ret += min(AdtoB[0].X,0.0);
        }
        if(BetoB[0].X <= 0 && AdtoB[0].X <= 0){
            if(AdtoB[1].X >= 0 || BetoB[1].X >= 0) {
                ret += min(BetoB[0].X,AdtoB[0].X);
            }
            else if(AdtoB[0].X+BetoB[1].X < BetoB[0].X+AdtoB[1].X) {
                ret += AdtoB[0].X+BetoB[1].X;
                //cout<<ret<<endl;
            }
            else{
                ret += BetoB[0].X+AdtoB[1].X;
            }
        }
    }
    else{
        ret += min(BetoB[0].X,0.0)+min(AdtoB[0].X,0.0);
        if(BetoB[0].X > 0 && AdtoB[0].X > 0) ret += min(BetoB[0].X,AdtoB[0].X);
    }

    printf("%.12f\n",ret);
    //cout<<ret<<endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

const int maxn = 100000+10;
#define mk make_pair
#define X first
#define Y second
typedef long long LL;
typedef pair<double,int> pp;
struct Point{
    int x,y;
    Point(int x=0,int y = 0):x(x),y(y){}
}P[maxn];
double BtoR[maxn];
pp AdtoB[maxn],BetoB[maxn];
int n,ax,ay,bx,by,tx,ty;
inline double dist(int x1,int y1,int x2,int y2) {
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int main() {

	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
	#endif
    cin >> ax >> ay >> bx >> by >> tx >> ty;
    cin >> n;
    double ret = 0.0;
    for(int i = 0; i < n; i++) cin >> P[i].x >> P[i].y;
    for(int i = 0; i < n; i++) {
        BtoR[i] = dist(P[i].x,P[i].y,tx,ty);
        ret += 2*BtoR[i];
    }
    for(int i = 0; i < n; i++) {

        AdtoB[i] = mk(dist(P[i].x,P[i].y,ax,ay)-BtoR[i],i);
    }
    for(int i = 0; i < n; i++){
        BetoB[i] = mk(dist(P[i].x,P[i].y,bx,by)-BtoR[i],i);
    }

    sort(AdtoB,AdtoB+n);
    sort(BetoB,BetoB+n);

    int f1 = -1,f2 = -1;
    if(AdtoB[0].Y==BetoB[0].Y) {
        if(AdtoB[0].X+BetoB[1].X < BetoB[0].X+AdtoB[1].X) {
            f1 = 0;
            f2 = 1;
        }
        else{
            f1 = 1;
            f2 = 0;
        }
    }
    else{
        f1 = f2 = 0;
    }
    ret += min(BetoB[f2].X,0.0);
    ret += min(AdtoB[f1].X,0.0);
    if(BetoB[f2].X > 0 && AdtoB[f1].X > 0) ret += min(BetoB[f2].X,AdtoB[f1].X);
    cout<<ret<<endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

const int maxn = 100000+10;
#define mk make_pair
#define X first
#define Y second
typedef long long LL;
typedef pair<double,int> pp;
struct Point{
    int x,y;
    Point(int x=0,int y = 0):x(x),y(y){}
}P[maxn];
double BtoR[maxn];
pp AdtoB[maxn],BetoB[maxn];
int n,ax,ay,bx,by,tx,ty;
inline double dist(int x1,int y1,int x2,int y2) {
    return sqrt(double(x1-x2)*(x1-x2)+double(y1-y2)*(y1-y2));
}

int main() {

	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
	#endif
    cin >> ax >> ay >> bx >> by >> tx >> ty;
    cin >> n;
    double ret = 0.0;
    for(int i = 0; i < n; i++) cin >> P[i].x >> P[i].y;
    for(int i = 0; i < n; i++) {
        BtoR[i] = dist(P[i].x,P[i].y,tx,ty);
        ret += 2*BtoR[i];
    }
    for(int i = 0; i < n; i++) {
        AdtoB[i] = mk(dist(P[i].x,P[i].y,ax,ay)-BtoR[i],i);
    }
    for(int i = 0; i < n; i++){
        BetoB[i] = mk(dist(P[i].x,P[i].y,bx,by)-BtoR[i],i);
    }

    sort(AdtoB,AdtoB+n);
    sort(BetoB,BetoB+n);

    int f1 = -1,f2 = -1;
    if(AdtoB[0].Y==BetoB[0].Y) {
        if(AdtoB[0].X+BetoB[1].X < BetoB[0].X+AdtoB[1].X) {
            f1 = 0;
            f2 = 1;
        }
        else{
            f1 = 1;
            f2 = 0;
        }
    }
    else{
        f1 = f2 = 0;
    }
    ret += min(BetoB[f2].X,0.0);
    ret += min(AdtoB[f1].X,0.0);
    if(BetoB[f2].X > 0 && AdtoB[f1].X > 0) ret += min(BetoB[f2].X,AdtoB[f1].X);
    printf("%.12f\n",ret);
    //cout<<ret<<endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

const int maxn = 100000+10;
const double INF = 1e18;

#define X first
#define Y second
double AdtoB[maxn],BetoB[maxn];
double pre[maxn],suf[maxn];

int n,ax,ay,bx,by,tx,ty;
inline double dist(int x1,int y1,int x2,int y2) {
    return sqrt(double(x1-x2)*(x1-x2)+double(y1-y2)*(y1-y2));
}

int main() {

	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
	#endif
    cin >> ax >> ay >> bx >> by >> tx >> ty;
    cin >> n;
    double S = 0.0;
    for(int i = 1; i <= n; i++) {
        int x,y;
        cin >> x >> y;
        double BtoR = dist(x,y,tx,ty);
        AdtoB[i] = dist(x,y,ax,ay)-BtoR;
        BetoB[i] = dist(x,y,bx,by)-BtoR;
        S += 2*BtoR;
    }
    pre[0] = suf[n+1] = INF;
    for(int i = 1; i <= n; i++) {
        pre[i] = min(pre[i-1],AdtoB[i]);
        suf[n-i+1] = min(suf[n-i+2],AdtoB[n-i+1]);
    }

    double ret = S + pre[n];
    for(int i = 1; i <= n; i++) {
        ret = min(ret,S+min(0.0,min(pre[i-1],suf[i+1]))+BetoB[i]);
    }
    printf("%.12f\n",ret);

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

const int maxn = 100000+10;
const double INF = 1e18;

#define X first
#define Y second
typedef long long LL;
typedef pair<int,int> Point;
Point P[maxn];
double AdtoB[maxn],BetoB[maxn];
double pre[maxn],suf[maxn];

int n,ax,ay,bx,by,tx,ty;
inline double dist(int x1,int y1,int x2,int y2) {
    return sqrt(double(x1-x2)*(x1-x2)+double(y1-y2)*(y1-y2));
}

int main() {

	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
	#endif
    cin >> ax >> ay >> bx >> by >> tx >> ty;
    cin >> n;
    double S = 0.0;
    for(int i = 1; i <= n; i++) cin >> P[i].X >> P[i].Y;
    for(int i = 1; i <= n; i++) {
        double BtoR = dist(P[i].X,P[i].Y,tx,ty);
        AdtoB[i] = dist(P[i].X,P[i].Y,ax,ay)-BtoR;
        BetoB[i] = dist(P[i].X,P[i].Y,bx,by)-BtoR;
        S += 2*BtoR;
    }
    pre[0] = suf[n+1] = INF;
    for(int i = 1; i <= n; i++) {
        pre[i] = min(pre[i-1],AdtoB[i]);
    }
    for(int i = n; i >= 1; i--) {
        suf[i] = min(suf[n+1],AdtoB[i]);
    }
    double ret = S + pre[n];
    for(int i = 1; i <= n; i++) {
        ret = min(ret,S+min(0.0,min(pre[i-1],suf[i+1]))+BetoB[i]);
    }
    printf("%.12f\n",ret);

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

const int maxn = 100000+10;
#define mk make_pair
#define X first
#define Y second
typedef long long LL;
typedef pair<double,int> pp;
struct Point{
    int x,y;
    Point(int x=0,int y = 0):x(x),y(y){}
}P[maxn];
double BtoR[maxn];
pp AdtoB[maxn],BetoB[maxn];
int n,ax,ay,bx,by,tx,ty;
inline double dist(int x1,int y1,int x2,int y2) {
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int main() {

	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
	#endif
    cin >> ax >> ay >> bx >> by >> tx >> ty;
    cin >> n;
    double ret = 0.0;
    for(int i = 0; i < n; i++) cin >> P[i].x >> P[i].y;
    for(int i = 0; i < n; i++) {
        BtoR[i] = dist(P[i].x,P[i].y,tx,ty);
        ret += 2*BtoR[i];
    }
    for(int i = 0; i < n; i++) {

        AdtoB[i] = mk(dist(P[i].x,P[i].y,ax,ay)-BtoR[i],i);
    }
    for(int i = 0; i < n; i++){
        BetoB[i] = mk(dist(P[i].x,P[i].y,bx,by)-BtoR[i],i);
    }

    sort(AdtoB,AdtoB+n);
    sort(BetoB,BetoB+n);

    int f1 = -1,f2 = -1;
    if(AdtoB[0].Y==BetoB[0].Y) {
        if(AdtoB[0].X+BetoB[1].X < BetoB[0].X+AdtoB[1].X) {
            f1 = 0;
            f2 = 1;
        }
        else{
            f1 = 1;
            f2 = 0;
        }
    }
    else{
        f1 = f2 = 0;
    }
    ret += min(BetoB[f2].X,0.0);
    ret += min(AdtoB[f1].X,0.0);
    if(BetoB[f2].X > 0 && AdtoB[f1].X > 0) ret += min(BetoB[f2].X,AdtoB[f1].X);
    printf("%.12f\n",ret);
    //cout<<ret<<endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

const int maxn = 100000+10;
const double INF = 1e20;
#define mk make_pair
#define X first
#define Y second
typedef long long LL;
typedef pair<int,int> Point;
Point P[maxn];
double BtoR[maxn];
double AdtoB[maxn],BetoB[maxn];
double pre[maxn],suf[maxn];

int n,ax,ay,bx,by,tx,ty;
inline double dist(int x1,int y1,int x2,int y2) {
    return sqrt(double(x1-x2)*(x1-x2)+double(y1-y2)*(y1-y2));
}

int main() {

	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
	#endif
    cin >> ax >> ay >> bx >> by >> tx >> ty;
    cin >> n;
    double S = 0.0;
    for(int i = 1; i <= n; i++) cin >> P[i].X >> P[i].Y;
    for(int i = 1; i <= n; i++) {
        BtoR[i] = dist(P[i].X,P[i].Y,tx,ty);
        AdtoB[i] = dist(P[i].X,P[i].Y,ax,ay)-BtoR[i];
        BetoB[i] = dist(P[i].X,P[i].Y,bx,by)-BtoR[i];
        S += 2*BtoR[i];
    }
    pre[0] = suf[n+1] = INF;
    for(int i = 1; i <= n; i++) {
        pre[i] = min(pre[i-1],AdtoB[i]);
    }
    for(int i = n; i >= 1; i--) {
        suf[i] = min(suf[n+1],AdtoB[n]);
    }
    double ret = S + pre[n];
    for(int i = 1; i <= n; i++) {
        ret = min(ret,S+min(0.0,min(pre[i-1],suf[i+1]))+BetoB[i]);
    }
    printf("%.12f\n",ret);

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

const int maxn = 100000+10;
const double INF = 1e18;

#define X first
#define Y second
double AdtoB[maxn],BetoB[maxn];
double pre[maxn],suf[maxn];

int n,ax,ay,bx,by,tx,ty;
inline double dist(int x1,int y1,int x2,int y2) {
    return sqrt(double(x1-x2)*(x1-x2)+double(y1-y2)*(y1-y2));
}

int main() {

	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    cin >> ax >> ay >> bx >> by >> tx >> ty;
    cin >> n;
    double S = 0.0;
    for(int i = 1; i <= n; i++) {
        int x,y;
        cin >> x >> y;
        double BtoR = dist(x,y,tx,ty);
        AdtoB[i] = dist(x,y,ax,ay)-BtoR;
        BetoB[i] = dist(x,y,bx,by)-BtoR;
        S += 2*BtoR;
    }
    pre[0] = suf[n+1] = INF;
    for(int i = 1; i <= n; i++) {
        pre[i] = min(pre[i-1],AdtoB[i]);
        suf[n-i+1] = min(suf[n-i+2],AdtoB[n-i+1]);
    }

    double ret = S + pre[n];
    for(int i = 1; i <= n; i++) {
        ret = min(ret,S+min(0.0,min(pre[i-1],suf[i+1]))+BetoB[i]);
    }
    printf("%.12f\n",ret);

    return 0;
}


/*
 Author: LargeDumpling
 Email: LargeDumpling@qq.com
 Edit History:
	2016-05-15	File created.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=100050;
const double INF=1e60;
int n;
double xa,xb,xt,ya,yb,yt,d[MAXN],x[MAXN],y[MAXN],ans,tot=0;
double da[MAXN],db[MAXN],p[MAXN],s[MAXN];
double dis(double xx,double yy) { return sqrt(xx*xx+yy*yy); }
int main()
{
	scanf("%lf%lf%lf%lf%lf%lf",&xa,&ya,&xb,&yb,&xt,&yt);
	xa-=xt; ya-=yt;
	xb-=xt; yb-=yt;
	scanf("%d",&n);
	p[0]=s[0]=p[n+1]=s[n+1]=INF;
	for(int i=1;i<=n;i++)
	{
		scanf("%lf%lf",&x[i],&y[i]);
		x[i]-=xt; y[i]-=yt;
		d[i]=dis(x[i],y[i]);
		da[i]=dis(x[i]-xa,y[i]-ya);
		db[i]=dis(x[i]-xb,y[i]-yb);
		s[i]=p[i]=db[i]-d[i];
		tot+=d[i]*2.;
	}
	for(int i=1;i<=n;i++) p[i]=min(p[i-1],p[i]);
	for(int i=n;i;i--) s[i]=min(s[i+1],s[i]);
	ans=tot+s[1];
	for(int i=1;i<=n;i++)
		ans=min(ans,tot+da[i]-d[i]+min(0.0,min(p[i-1],s[i+1])));
	printf("%.12lf\n",ans);
	return 0;
}


/*
 Author: LargeDumpling
 Email: LargeDumpling@qq.com
 Edit History:
	2016-05-15	File created.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=100050;
const double INF=1e60;
int n;
double xa,xb,xt,ya,yb,yt,d[MAXN],x[MAXN],y[MAXN],ans,tot=0;
double da[MAXN],db[MAXN],p[MAXN],s[MAXN];
double dis(double xx,double yy) { return sqrt(xx*xx+yy*yy); }
int main()
{
	scanf("%lf%lf%lf%lf%lf%lf",&xa,&ya,&xb,&yb,&xt,&yt);
	xa-=xt; ya-=yt;
	xb-=xt; yb-=yt;
	scanf("%d",&n);
	p[0]=s[0]=p[n+1]=s[n+1]=INF;
	for(int i=1;i<=n;i++)
	{
		scanf("%lf%lf",&x[i],&y[i]);
		x[i]-=xt; y[i]-=yt;
		d[i]=dis(x[i],y[i]);
		da[i]=dis(x[i]-xa,y[i]-ya);
		db[i]=dis(x[i]-xb,y[i]-yb);
		tot+=d[i]*2.;
	}
	for(int i=1;i<=n;i++) p[i]=min(p[i-1],db[i]-d[i]);
	for(int i=n;i;i--) s[i]=min(s[i+1],db[i]-d[i]);
	ans=INF;
	for(int i=1;i<=n;i++)
		ans=min(ans,tot+da[i]-d[i]+min(p[i-1],s[i+1]));
	printf("%lf",ans);
	return 0;
}


/*
 Author: LargeDumpling
 Email: LargeDumpling@qq.com
 Edit History:
	2016-05-15	File created.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=100050;
const double INF=1e60;
int n;
double xa,xb,xt,ya,yb,yt,d[MAXN],x[MAXN],y[MAXN],ans,tot=0;
double da[MAXN],db[MAXN],p[MAXN],s[MAXN];
double dis(double xx,double yy) { return sqrt(xx*xx+yy*yy); }
int main()
{
	scanf("%lf%lf%lf%lf%lf%lf",&xa,&ya,&xb,&yb,&xt,&yt);
	xa-=xt; ya-=yt;
	xb-=xt; yb-=yt;
	scanf("%d",&n);
	p[0]=s[0]=p[n+1]=s[n+1]=INF;
	for(int i=1;i<=n;i++)
	{
		scanf("%lf%lf",&x[i],&y[i]);
		x[i]-=xt; y[i]-=yt;
		d[i]=dis(x[i],y[i]);
		da[i]=dis(x[i]-xa,y[i]-ya);
		db[i]=dis(x[i]-xb,y[i]-yb);
		s[i]=p[i]=db[i]-d[i];
		tot+=d[i]*2.;
	}
	for(int i=1;i<=n;i++) p[i]=min(p[i-1],p[i]);
	for(int i=n;i;i--) s[i]=min(s[i+1],s[i]);
	ans=tot+s[1];
	for(int i=1;i<=n;i++)
		ans=min(ans,tot+da[i]-d[i]+min(0.0,min(p[i-1],s[i+1])));
	printf("%.12lf",ans);
	return 0;
}


/*
 Author: LargeDumpling
 Email: LargeDumpling@qq.com
 Edit History:
	2016-05-15	File created.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=100050;
const double INF=1e60;
int n;
double xa,xb,xt,ya,yb,yt,d[MAXN],x[MAXN],y[MAXN],ans,tot=0;
double da[MAXN],db[MAXN],p[MAXN],s[MAXN];
double dis(double xx,double yy) { return sqrt(xx*xx+yy*yy); }
int main()
{
	scanf("%lf%lf%lf%lf%lf%lf",&xa,&ya,&xb,&yb,&xt,&yt);
	xa-=xt; ya-=yt;
	xb-=xt; yb-=yt;
	scanf("%d",&n);
	p[0]=s[0]=p[n+1]=s[n+1]=INF;
	for(int i=1;i<=n;i++)
	{
		scanf("%lf%lf",&x[i],&y[i]);
		x[i]-=xt; y[i]-=yt;
		d[i]=dis(x[i],y[i]);
		da[i]=dis(x[i]-xa,y[i]-ya);
		db[i]=dis(x[i]-xb,y[i]-yb);
		tot+=d[i]*2.;
	}
	for(int i=1;i<=n;i++) p[i]=min(p[i-1],db[i]-d[i]);
	for(int i=n;i;i--) s[i]=min(s[i+1],db[i]-d[i]);
	ans=INF;
	for(int i=1;i<=n;i++)
		ans=min(ans,tot+da[i]-d[i]+min(p[i-1],s[i+1]));
	for(int i=1;i<=n;i++)
		ans=min(ans,tot+min(da[i]-d[i],min(p[i-1],s[i+1])));
	printf("%.12lf",ans);
	return 0;
}


/*
 Author: LargeDumpling
 Email: LargeDumpling@qq.com
 Edit History:
	2016-05-15	File created.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=100050;
const double INF=1e18+5;
int n;
double xa,xb,xt,ya,yb,yt,d[MAXN],x[MAXN],y[MAXN],ans,tot=0;
double da[MAXN],db[MAXN],p[MAXN],s[MAXN];
double dis(double xx,double yy) { return sqrt((long long)xx*xx+(long long)yy*yy); }
int main()
{
	scanf("%lf%lf%lf%lf%lf%lf",&xa,&ya,&xb,&yb,&xt,&yt);
	xa-=xt; ya-=yt;
	xb-=xt; yb-=yt;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lf%lf",&x[i],&y[i]);
		x[i]-=xt; y[i]-=yt;
		d[i]=dis(x[i],y[i]);
		da[i]=dis(x[i]-xa,y[i]-ya);
		db[i]=dis(x[i]-xb,y[i]-yb);
		tot+=d[i]*2.;
	}
	p[0]=s[n+1]=INF;
	for(int i=1;i<=n;i++) p[i]=min(p[i-1],db[i]-d[i]);
	for(int i=n;i;i--) s[i]=min(s[i+1],db[i]-d[i]);
	ans=INF;
	for(int i=1;i<=n;i++)
		ans=min(ans,tot+da[i]-d[i]+min(0.0,min(p[i-1],s[i+1])));
	printf("%.12lf",ans);
	return 0;
}


/*
 Author: LargeDumpling
 Email: LargeDumpling@qq.com
 Edit History:
	2016-05-15	File created.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=100050;
const double INF=1e60;
int n;
double xa,xb,xt,ya,yb,yt,d[MAXN],x[MAXN],y[MAXN],ans,tot=0;
double da[MAXN],db[MAXN],p[MAXN],s[MAXN];
double dis(double xx,double yy) { return sqrt(xx*xx+yy*yy); }
int main()
{
	scanf("%lf%lf%lf%lf%lf%lf",&xa,&ya,&xb,&yb,&xt,&yt);
	xa-=xt; ya-=yt;
	xb-=xt; yb-=yt;
	scanf("%d",&n);
	p[0]=s[0]=p[n+1]=s[n+1]=INF;
	for(int i=1;i<=n;i++)
	{
		scanf("%lf%lf",&x[i],&y[i]);
		x[i]-=xt; y[i]-=yt;
		d[i]=dis(x[i],y[i]);
		da[i]=dis(x[i]-xa,y[i]-ya);
		db[i]=dis(x[i]-xb,y[i]-yb);
		tot+=d[i]*2.;
	}
	for(int i=1;i<=n;i++) p[i]=min(p[i-1],db[i]-d[i]);
	for(int i=n;i;i--) s[i]=min(s[i+1],db[i]-d[i]);
	ans=INF;
	for(int i=1;i<=n;i++)
		ans=min(ans,tot+da[i]-d[i]+min(p[i-1],s[i+1]));
	printf("%.12lf",ans);
	return 0;
}


#include <iostream>
#include <math.h>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
double calD(double x, double y, double x_, double y_)
{
    return sqrt((x-x_)*(x-x_)+(y-y_)*(y-y_));
}
int main()
{
    double ax,ay,bx,by,tx,ty;
    scanf("%lf%lf%lf%lf%lf%lf",&ax,&ay,&bx,&by,&tx,&ty);
    int n;
    scanf("%d",&n);
    int i;
    double x,y;
    vector<pair<double,double> >v;
    vector<pair<double,int> >a;
    vector<pair<double,int> >b;
    vector<double>tc;
    for(i=0;i<n;i++)
    {
        scanf("%lf%lf",&x,&y);
        v.push_back(make_pair(x,y));
    }
    if(n==1)
    {
        double d=calD(tx,ty,v[0].first,v[0].second);
        printf("%.12lf",min(calD(ax,ay,v[0].first,v[0].second)+d,calD(bx,by,v[0].first,v[0].second)+d));
        return 0;
    }
    double d=0,sum=0;
    for(i=0;i<n;i++)
    {
        d=calD(tx,ty,v[i].first,v[i].second);
        tc.push_back(d*2);
        sum+=(d*2);
    }
    for(i=0;i<n;i++)
    {
        d=calD(ax,ay,v[i].first,v[i].second);
        d-=calD(tx,ty,v[i].first,v[i].second);
        a.push_back(make_pair(d,i));
    }
    for(i=0;i<n;i++)
    {
        d=calD(bx,by,v[i].first,v[i].second);
        d-=calD(tx,ty,v[i].first,v[i].second);
        b.push_back(make_pair(d,i));
    }
    double ans=sum;
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(a[0].second==b[0].second)
    {
        ans=sum-calD(tx,ty,v[a[1].second].first,v[a[1].second].second)
        -calD(tx,ty,v[b[0].second].first,v[b[0].second].second)
        +calD(bx,by,v[b[0].second].first,v[b[0].second].second)
        +calD(ax,ay,v[a[1].second].first,v[a[1].second].second);
        ans=min(ans,sum-calD(tx,ty,v[a[0].second].first,v[a[0].second].second)
        -calD(tx,ty,v[b[1].second].first,v[b[1].second].second)
        +calD(bx,by,v[b[1].second].first,v[b[1].second].second)
        +calD(ax,ay,v[a[0].second].first,v[a[0].second].second));
    }
    else
        ans=min(ans,sum-calD(tx,ty,v[a[0].second].first,v[a[0].second].second)
        -calD(tx,ty,v[b[0].second].first,v[b[0].second].second)
        +calD(bx,by,v[b[0].second].first,v[b[0].second].second)
        +calD(ax,ay,v[a[0].second].first,v[a[0].second].second));
    for(i=0;i<n;i++)
    {
        d=calD(ax,ay,v[i].first,v[i].second);
        d+=calD(tx,ty,v[i].first,v[i].second);
        ans=min(ans,sum-tc[i]+d);
    }
    for(i=0;i<n;i++)
    {
        d=calD(bx,by,v[i].first,v[i].second);
        d+=calD(tx,ty,v[i].first,v[i].second);
        ans=min(ans,sum-tc[i]+d);
    }
    printf("%.12lf",ans);
    return 0;
}


#include <iostream>
#include <math.h>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
double calD(double x, double y, double x_, double y_)
{
    return sqrt((x-x_)*(x-x_)+(y-y_)*(y-y_));
}
int main()
{
    double ax,ay,bx,by,tx,ty;
    cin>>ax>>ay>>bx>>by>>tx>>ty;
    int n;
    cin>>n;
    int i;
    double x,y;
    vector<pair<double,double> >v;
    vector<pair<double,int> >a;
    vector<pair<double,int> >b;
    vector<double>tc;
    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        v.push_back(make_pair(x,y));
    }
    double d=0,sum=0;
    for(i=0;i<n;i++)
    {
        d=calD(tx,ty,v[i].first,v[i].second);
        tc.push_back(d*2);
        sum+=(d*2);
    }
    for(i=0;i<n;i++)
    {
        d=calD(ax,ay,v[i].first,v[i].second);
        d-=calD(tx,ty,v[i].first,v[i].second);
        a.push_back(make_pair(d,i));
    }
    for(i=0;i<n;i++)
    {
        d=calD(bx,by,v[i].first,v[i].second);
        d-=calD(tx,ty,v[i].first,v[i].second);
        b.push_back(make_pair(d,i));
    }
    double ans=sum;
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(a[0].second==b[0].second)
    {
        ans=sum-calD(tx,ty,v[a[1].second].first,v[a[1].second].second)
        -calD(tx,ty,v[b[0].second].first,v[b[0].second].second)
        +calD(bx,by,v[b[0].second].first,v[b[0].second].second)
        +calD(ax,ay,v[a[1].second].first,v[a[1].second].second);
        ans=min(ans,sum-calD(tx,ty,v[a[0].second].first,v[a[0].second].second)
        -calD(tx,ty,v[b[1].second].first,v[b[1].second].second)
        +calD(bx,by,v[b[1].second].first,v[b[1].second].second)
        +calD(ax,ay,v[a[0].second].first,v[a[0].second].second));
    }
    else
        ans=min(ans,sum-calD(tx,ty,v[a[0].second].first,v[a[0].second].second)
        -calD(tx,ty,v[b[0].second].first,v[b[0].second].second)
        +calD(bx,by,v[b[0].second].first,v[b[0].second].second)
        +calD(ax,ay,v[a[0].second].first,v[a[0].second].second));
    printf("%.12lf",ans);
    return 0;
}


#include <iostream>
#include <math.h>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
double calD(double x, double y, double x_, double y_)
{
    return sqrt((x-x_)*(x-x_)+(y-y_)*(y-y_));
}
int main()
{
    double ax,ay,bx,by,tx,ty;
    scanf("%lf%lf%lf%lf%lf%lf",&ax,&ay,&bx,&by,&tx,&ty);
    int n;
    scanf("%d",&n);
    int i;
    double x,y;
    vector<pair<double,double> >v;
    vector<pair<double,int> >a;
    vector<pair<double,int> >b;
    vector<double>tc;
    for(i=0;i<n;i++)
    {
        scanf("%lf%lf",&x,&y);
        v.push_back(make_pair(x,y));
    }
    if(n==1)
    {
        double d=calD(tx,ty,v[0].first,v[0].second);
        printf("%.12lf",min(calD(ax,ay,v[0].first,v[0].second)+d,calD(bx,by,v[0].first,v[0].second)+d));
        return 0;
    }
    double d=0,sum=0;
    for(i=0;i<n;i++)
    {
        d=calD(tx,ty,v[i].first,v[i].second);
        tc.push_back(d*2);
        sum+=(d*2);
    }
    for(i=0;i<n;i++)
    {
        d=calD(ax,ay,v[i].first,v[i].second);
        d-=calD(tx,ty,v[i].first,v[i].second);
        a.push_back(make_pair(d,i));
    }
    for(i=0;i<n;i++)
    {
        d=calD(bx,by,v[i].first,v[i].second);
        d-=calD(tx,ty,v[i].first,v[i].second);
        b.push_back(make_pair(d,i));
    }
    double ans;
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(a[0].second==b[0].second)
    {
        ans=sum-calD(tx,ty,v[a[1].second].first,v[a[1].second].second)
        -calD(tx,ty,v[b[0].second].first,v[b[0].second].second)
        +calD(bx,by,v[b[0].second].first,v[b[0].second].second)
        +calD(ax,ay,v[a[1].second].first,v[a[1].second].second);
        ans=min(ans,sum-calD(tx,ty,v[a[0].second].first,v[a[0].second].second)
        -calD(tx,ty,v[b[1].second].first,v[b[1].second].second)
        +calD(bx,by,v[b[1].second].first,v[b[1].second].second)
        +calD(ax,ay,v[a[0].second].first,v[a[0].second].second));
    }
    else
        ans=sum-calD(tx,ty,v[a[0].second].first,v[a[0].second].second)
        -calD(tx,ty,v[b[0].second].first,v[b[0].second].second)
        +calD(bx,by,v[b[0].second].first,v[b[0].second].second)
        +calD(ax,ay,v[a[0].second].first,v[a[0].second].second);
    for(i=0;i<n;i++)
    {
        d=calD(ax,ay,v[i].first,v[i].second);
        d+=calD(tx,ty,v[i].first,v[i].second);
        ans=min(ans,sum-tc[i]+d);
        d=calD(bx,by,v[i].first,v[i].second);
        d+=calD(tx,ty,v[i].first,v[i].second);
        ans=min(ans,sum-tc[i]+d);
    }
    printf("%.12lf",ans);
    return 0;
}


#include <iostream>
#include <math.h>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
double calD(double x, double y, double x_, double y_)
{
    return sqrt((x-x_)*(x-x_)+(y-y_)*(y-y_));
}
int main()
{
    double ax,ay,bx,by,tx,ty;
    cin>>ax>>ay>>bx>>by>>tx>>ty;
    int n;
    cin>>n;
    int i;
    double x,y;
    vector<pair<double,double> >v;
    vector<pair<double,int> >a;
    vector<pair<double,int> >b;
    vector<double>tc;
    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        v.push_back(make_pair(x,y));
    }
    double d=0,sum=0;
    for(i=0;i<n;i++)
    {
        d=calD(tx,ty,v[i].first,v[i].second);
        tc.push_back(d*2);
        sum+=(d*2);
    }
    for(i=0;i<n;i++)
    {
        d=calD(ax,ay,v[i].first,v[i].second);
        d-=calD(tx,ty,v[i].first,v[i].second);
        a.push_back(make_pair(d,i));
    }
    for(i=0;i<n;i++)
    {
        d=calD(bx,by,v[i].first,v[i].second);
        d-=calD(tx,ty,v[i].first,v[i].second);
        b.push_back(make_pair(d,i));
    }
    double ans=sum;
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(a[0].second==b[0].second)
    {
        ans=sum-calD(tx,ty,v[a[1].second].first,v[a[1].second].second)
        -calD(tx,ty,v[b[0].second].first,v[b[0].second].second)
        +calD(bx,by,v[b[0].second].first,v[b[0].second].second)
        +calD(ax,ay,v[a[1].second].first,v[a[1].second].second);
        ans=min(ans,sum-calD(tx,ty,v[a[0].second].first,v[a[0].second].second)
        -calD(tx,ty,v[b[1].second].first,v[b[1].second].second)
        +calD(bx,by,v[b[1].second].first,v[b[1].second].second)
        +calD(ax,ay,v[a[0].second].first,v[a[0].second].second));
    }
    else
        ans=min(ans,sum-calD(tx,ty,v[a[0].second].first,v[a[0].second].second)
        -calD(tx,ty,v[b[0].second].first,v[b[0].second].second)
        +calD(bx,by,v[b[0].second].first,v[b[0].second].second)
        +calD(ax,ay,v[a[0].second].first,v[a[0].second].second));
    for(i=0;i<n;i++)
    {
        d=calD(ax,ay,v[i].first,v[i].second);
        d+=calD(tx,ty,v[i].first,v[i].second);
        ans=min(ans,sum-tc[i]+d);
    }
    for(i=0;i<n;i++)
    {
        d=calD(bx,by,v[i].first,v[i].second);
        d+=calD(tx,ty,v[i].first,v[i].second);
        ans=min(ans,sum-tc[i]+d);
    }
    printf("%.12lf",ans);
    return 0;
}


#include <iostream>
#include <math.h>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
double calD(double x, double y, double x_, double y_)
{
    return sqrt((x-x_)*(x-x_)+(y-y_)*(y-y_));
}
int main()
{
    double ax,ay,bx,by,tx,ty;
    cin>>ax>>ay>>bx>>by>>tx>>ty;
    int n;
    cin>>n;
    int i;
    double x,y;
    vector<pair<double,double> >v;
    vector<pair<double,int> >a;
    vector<pair<double,int> >b;
    vector<double>tc;
    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        v.push_back(make_pair(x,y));
    }
    if(n==1)
    {
        cout<<min(calD(ax,ay,v[0].first,v[0].second)+calD(tx,ty,v[0].first,v[0].second),min(calD(bx,by,v[0].first,v[0].second)+calD(tx,ty,v[0].first,v[0].second),calD(tx,ty,v[0].first,v[0].second*2)));
        return 0;
    }
    double d=0,sum=0;
    for(i=0;i<n;i++)
    {
        d=calD(tx,ty,v[i].first,v[i].second);
        tc.push_back(d*2);
        sum+=(d*2);
    }
    for(i=0;i<n;i++)
    {
        d=calD(ax,ay,v[i].first,v[i].second);
        d-=calD(tx,ty,v[i].first,v[i].second);
        a.push_back(make_pair(d,i));
    }
    for(i=0;i<n;i++)
    {
        d=calD(bx,by,v[i].first,v[i].second);
        d-=calD(tx,ty,v[i].first,v[i].second);
        b.push_back(make_pair(d,i));
    }
    double ans=sum;
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(a[0].second==b[0].second)
    {
        ans=sum-calD(tx,ty,v[a[1].second].first,v[a[1].second].second)
        -calD(tx,ty,v[b[0].second].first,v[b[0].second].second)
        +calD(bx,by,v[b[0].second].first,v[b[0].second].second)
        +calD(ax,ay,v[a[1].second].first,v[a[1].second].second);
        ans=min(ans,sum-calD(tx,ty,v[a[0].second].first,v[a[0].second].second)
        -calD(tx,ty,v[b[1].second].first,v[b[1].second].second)
        +calD(bx,by,v[b[1].second].first,v[b[1].second].second)
        +calD(ax,ay,v[a[0].second].first,v[a[0].second].second));
    }
    else
        ans=min(ans,sum-calD(tx,ty,v[a[0].second].first,v[a[0].second].second)
        -calD(tx,ty,v[b[0].second].first,v[b[0].second].second)
        +calD(bx,by,v[b[0].second].first,v[b[0].second].second)
        +calD(ax,ay,v[a[0].second].first,v[a[0].second].second));
    for(i=0;i<n;i++)
    {
        d=calD(ax,ay,v[i].first,v[i].second);
        d+=calD(tx,ty,v[i].first,v[i].second);
        ans=min(ans,sum-tc[i]+d);
    }
    for(i=0;i<n;i++)
    {
        d=calD(bx,by,v[i].first,v[i].second);
        d+=calD(tx,ty,v[i].first,v[i].second);
        ans=min(ans,sum-tc[i]+d);
    }
    printf("%.12lf",ans);
    return 0;
}


#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
typedef __int64 ll;
int n;
const int maxn = 1e5 + 10;
struct Point{
    int x, y;
    Point(int x = 0, int y = 0) : x(x), y(y) {}
}arr[maxn];
const int inf = 0x3f3f3f3f;
struct Point A, B, C;

double d(int x, int y){
    return sqrt((double)(x - C.x) * (x - C.x) + (double)(y - C.y) * (y - C.y));
}

double dist(int x1, int y1, int x2, int y2){
    double d1 = x1 - x2;
    double d2 = y1 - y2;
    return sqrt(d1 * d1 + d2 * d2);
}
int main(){
    //freopen("in.txt", "r", stdin);
    //1-9 :: 1
    //10 - 99: 2
    //100 -999 :
    while(~scanf("%d%d%d%d%d%d", &A.x, & A.y, &B.x, &B.y, &C.x, &C.y)){
        double ans = 0;
        scanf("%d", &n);
        for(int i = 0; i < n; i++) scanf("%d%d", &arr[i].x, &arr[i].y);
        for(int i = 0; i < n; i++) ans += d(arr[i].x, arr[i].y) * 2;
        int idx0, idx1;
        double mini0 = inf, mini1 = inf;
        for(int i = 0; i < n; i++){
            double tem = -d(arr[i].x, arr[i].y) + dist(A.x, A.y, arr[i].x, arr[i].y);
            if(mini0 > tem) mini0 = tem, idx0 = i;
        }
        //mini = inf;
        for(int i = 0; i < n; i++){
            double tem = -d(arr[i].x, arr[i].y) + dist(B.x, B.y, arr[i].x, arr[i].y);
            if(mini1 > tem) mini1 = tem, idx1 = i;
        }
        if(idx0 != idx1){
            printf("%.10f\n", ans + mini0 + mini1);
        }else{
            double add0 = inf, add1 = inf;
            for(int i = 0; i < n; i++){
                if(i == idx0) continue;
                double tem = -d(arr[i].x, arr[i].y) + dist(A.x, A.y, arr[i].x, arr[i].y);
                if(add0 > tem) add0 = tem;
            }
            for(int i = 0; i < n; i++){
                if(i == idx0) continue;
                double tem = -d(arr[i].x, arr[i].y) + dist(B.x, B.y, arr[i].x, arr[i].y);
                if(add1 > tem) add1 = tem;
            }
            double ans1 = ans + mini0 + add1;
            double ans2 = ans + mini1 + add0;
            printf("%.10f\n", min(ans1, ans2));
        }
    }
    return 0;
}


#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
typedef __int64 ll;
int n;
const int maxn = 1e5 + 10;
struct Point{
    int x, y;
    Point(int x = 0, int y = 0) : x(x), y(y) {}
}arr[maxn];
const double inf = 1e10 * 1e10;
struct Point A, B, C;

double d(int x, int y){
    return sqrt((double)(x - C.x) * (x - C.x) + (double)(y - C.y) * (y - C.y));
}

double dist(int x1, int y1, int x2, int y2){
    double d1 = x1 - x2;
    double d2 = y1 - y2;
    return sqrt(d1 * d1 + d2 * d2);
}
int main(){
    //freopen("in.txt", "r", stdin);
    //1-9 :: 1
    //10 - 99: 2
    //100 -999 :
    while(~scanf("%d%d%d%d%d%d", &A.x, & A.y, &B.x, &B.y, &C.x, &C.y)){
        double ans = 0;
        scanf("%d", &n);
        for(int i = 0; i < n; i++) scanf("%d%d", &arr[i].x, &arr[i].y);
        for(int i = 0; i < n; i++) ans += d(arr[i].x, arr[i].y) * 2;
        int idx0, idx1;
        double mini0 = inf, mini1 = inf;
        for(int i = 0; i < n; i++){
            double tem = -d(arr[i].x, arr[i].y) + dist(A.x, A.y, arr[i].x, arr[i].y);
            if(mini0 > tem) mini0 = tem, idx0 = i;
        }
        //mini = inf;
        for(int i = 0; i < n; i++){
            double tem = -d(arr[i].x, arr[i].y) + dist(B.x, B.y, arr[i].x, arr[i].y);
            if(mini1 > tem) mini1 = tem, idx1 = i;
        }
        if(idx0 != idx1){
            printf("%.10f\n", ans + mini0 + mini1);
        }else{
            double add0 = inf, add1 = inf;
            for(int i = 0; i < n; i++){
                if(i == idx0) continue;
                double tem = -d(arr[i].x, arr[i].y) + dist(A.x, A.y, arr[i].x, arr[i].y);
                if(add0 > tem) add0 = tem;
            }
            for(int i = 0; i < n; i++){
                if(i == idx0) continue;
                double tem = -d(arr[i].x, arr[i].y) + dist(B.x, B.y, arr[i].x, arr[i].y);
                if(add1 > tem) add1 = tem;
            }
            double ans1 = ans + mini0 + min(add1,0);
            double ans2 = ans + mini1 + min(add0,0);

            printf("%.10f\n", min(ans1, ans2));
        }
    }
    return 0;
}


#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
typedef __int64 ll;
int n;
const int maxn = 1e5 + 10;
struct Point{
    int x, y;
    Point(int x = 0, int y = 0) : x(x), y(y) {}
}arr[maxn];
const double inf = 1e10 * 1e10;
struct Point A, B, C;

double d(int x, int y){
    double d1 = x - C.x, d2 = y - C.y;
    return sqrt(d1 * d1 + d2 * d2);
}

double dist(int x1, int y1, int x2, int y2){
    double d1 = x1 - x2;
    double d2 = y1 - y2;
    return sqrt(d1 * d1 + d2 * d2);
}
int main(){
    //freopen("in.txt", "r", stdin);
    //1-9 :: 1
    //10 - 99: 2
    //100 -999 :
    while(~scanf("%d%d%d%d%d%d", &A.x, & A.y, &B.x, &B.y, &C.x, &C.y)){
        double ans = 0;
        scanf("%d", &n);
        for(int i = 0; i < n; i++) scanf("%d%d", &arr[i].x, &arr[i].y);
        for(int i = 0; i < n; i++) ans += d(arr[i].x, arr[i].y) * 2;
        int idx0, idx1;
        double mini0 = inf, mini1 = inf;
        for(int i = 0; i < n; i++){
            double tem = -d(arr[i].x, arr[i].y) + dist(A.x, A.y, arr[i].x, arr[i].y);
            if(mini0 > tem) mini0 = tem, idx0 = i;
        }
        //mini = inf;
        for(int i = 0; i < n; i++){
            double tem = -d(arr[i].x, arr[i].y) + dist(B.x, B.y, arr[i].x, arr[i].y);
            if(mini1 > tem) mini1 = tem, idx1 = i;
        }
        if(idx0 != idx1){
            //printf("%.10f\n", ans + mini0 + mini1);
            ans += min(mini1, min(mini0 + mini1, mini0));
            printf("%.10f\n", ans);
        }else{
            double add0 = inf, add1 = inf;
            for(int i = 0; i < n; i++){
                if(i == idx0) continue;
                double tem = -d(arr[i].x, arr[i].y) + dist(A.x, A.y, arr[i].x, arr[i].y);
                if(add0 > tem) add0 = tem;
            }
            for(int i = 0; i < n; i++){
                if(i == idx0) continue;
                double tem = -d(arr[i].x, arr[i].y) + dist(B.x, B.y, arr[i].x, arr[i].y);
                if(add1 > tem) add1 = tem;
            }
            double ans1 = ans + mini0 + min(0., add1);
            double ans2 = ans + mini1 + min(0., add0);
            printf("%.10f\n", min(ans1, ans2));
        }
    }
    return 0;
}


#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
typedef __int64 ll;
int n;
const int maxn = 1e5 + 10;
struct Point{
    int x, y;
    Point(int x = 0, int y = 0) : x(x), y(y) {}
}arr[maxn];
const double inf = 1e10 * 1e10;
struct Point A, B, C;

double d(int x, int y){
    return sqrt((double)(x - C.x) * (x - C.x) + (double)(y - C.y) * (y - C.y));
}

double dist(int x1, int y1, int x2, int y2){
    double d1 = x1 - x2;
    double d2 = y1 - y2;
    return sqrt(d1 * d1 + d2 * d2);
}
int main(){
    //freopen("in.txt", "r", stdin);
    //1-9 :: 1
    //10 - 99: 2
    //100 -999 :
    while(~scanf("%d%d%d%d%d%d", &A.x, & A.y, &B.x, &B.y, &C.x, &C.y)){
        double ans = 0;
        scanf("%d", &n);
        for(int i = 0; i < n; i++) scanf("%d%d", &arr[i].x, &arr[i].y);
        for(int i = 0; i < n; i++) ans += d(arr[i].x, arr[i].y) * 2;
        int idx0, idx1;
        double mini0 = inf, mini1 = inf;
        for(int i = 0; i < n; i++){
            double tem = -d(arr[i].x, arr[i].y) + dist(A.x, A.y, arr[i].x, arr[i].y);
            if(mini0 > tem) mini0 = tem, idx0 = i;
        }
        //mini = inf;
        for(int i = 0; i < n; i++){
            double tem = -d(arr[i].x, arr[i].y) + dist(B.x, B.y, arr[i].x, arr[i].y);
            if(mini1 > tem) mini1 = tem, idx1 = i;
        }
        if(idx0 != idx1){
            printf("%.10f\n", ans + mini0 + mini1);
        }else{
            double add0 = inf, add1 = inf;
            for(int i = 0; i < n; i++){
                if(i == idx0) continue;
                double tem = -d(arr[i].x, arr[i].y) + dist(A.x, A.y, arr[i].x, arr[i].y);
                if(add0 > tem) add0 = tem;
            }
            for(int i = 0; i < n; i++){
                if(i == idx0) continue;
                double tem = -d(arr[i].x, arr[i].y) + dist(B.x, B.y, arr[i].x, arr[i].y);
                if(add1 > tem) add1 = tem;
            }
            double ans1 = ans + mini0 + min(0., add1);
            double ans2 = ans + mini1 + min(0., add0);
            printf("%.10f\n", min(ans1, ans2));
        }
    }
    return 0;
}


#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
typedef __int64 ll;
int n;
const int maxn = 1e5 + 10;
struct Point{
    int x, y;
    Point(int x = 0, int y = 0) : x(x), y(y) {}
}arr[maxn];
const double inf = 1e10 * 1e10;
struct Point A, B, C;

double d(int x, int y){
    double d1 = x - C.x, d2 = y - C.y;
    return sqrt(d1 * d1 + d2 * d2);
}

double dist(int x1, int y1, int x2, int y2){
    double d1 = x1 - x2;
    double d2 = y1 - y2;
    return sqrt(d1 * d1 + d2 * d2);
}
int main(){
    //freopen("in.txt", "r", stdin);
    //1-9 :: 1
    //10 - 99: 2
    //100 -999 :
    while(~scanf("%d%d%d%d%d%d", &A.x, & A.y, &B.x, &B.y, &C.x, &C.y)){
        double ans = 0;
        scanf("%d", &n);
        for(int i = 0; i < n; i++) scanf("%d%d", &arr[i].x, &arr[i].y);
        for(int i = 0; i < n; i++) ans += d(arr[i].x, arr[i].y) * 2;
        int idx0, idx1;
        double mini0 = inf, mini1 = inf;
        for(int i = 0; i < n; i++){
            double tem = -d(arr[i].x, arr[i].y) + dist(A.x, A.y, arr[i].x, arr[i].y);
            if(mini0 > tem) mini0 = tem, idx0 = i;
        }
        //mini = inf;
        for(int i = 0; i < n; i++){
            double tem = -d(arr[i].x, arr[i].y) + dist(B.x, B.y, arr[i].x, arr[i].y);
            if(mini1 > tem) mini1 = tem, idx1 = i;
        }
        if(idx0 != idx1){
            //printf("%.10f\n", ans + mini0 + mini1);
            ans = min(mini1, min(mini0 + mini1, mini0));
            printf("%.10f\n", ans);
        }else{
            double add0 = inf, add1 = inf;
            for(int i = 0; i < n; i++){
                if(i == idx0) continue;
                double tem = -d(arr[i].x, arr[i].y) + dist(A.x, A.y, arr[i].x, arr[i].y);
                if(add0 > tem) add0 = tem;
            }
            for(int i = 0; i < n; i++){
                if(i == idx0) continue;
                double tem = -d(arr[i].x, arr[i].y) + dist(B.x, B.y, arr[i].x, arr[i].y);
                if(add1 > tem) add1 = tem;
            }
            double ans1 = ans + mini0 + min(0., add1);
            double ans2 = ans + mini1 + min(0., add0);
            printf("%.10f\n", min(ans1, ans2));
        }
    }
    return 0;
}


#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
typedef __int64 ll;
int n;
const int maxn = 1e5 + 10;
struct Point{
    int x, y;
    Point(int x = 0, int y = 0) : x(x), y(y) {}
}arr[maxn];
const double inf = 1e10 * 1e10;
struct Point A, B, C;

double d(int x, int y){
    return sqrt((double)(x - C.x) * (x - C.x) + (double)(y - C.y) * (y - C.y));
}

double dist(int x1, int y1, int x2, int y2){
    double d1 = x1 - x2;
    double d2 = y1 - y2;
    return sqrt(d1 * d1 + d2 * d2);
}
int main(){
    //freopen("in.txt", "r", stdin);
    //1-9 :: 1
    //10 - 99: 2
    //100 -999 :
    while(~scanf("%d%d%d%d%d%d", &A.x, & A.y, &B.x, &B.y, &C.x, &C.y)){
        double ans = 0;
        scanf("%d", &n);
        for(int i = 0; i < n; i++) scanf("%d%d", &arr[i].x, &arr[i].y);
        for(int i = 0; i < n; i++) ans += d(arr[i].x, arr[i].y) * 2;
        int idx0, idx1;
        double mini0 = inf, mini1 = inf;
        for(int i = 0; i < n; i++){
            double tem = -d(arr[i].x, arr[i].y) + dist(A.x, A.y, arr[i].x, arr[i].y);
            if(mini0 > tem) mini0 = tem, idx0 = i;
        }
        //mini = inf;
        for(int i = 0; i < n; i++){
            double tem = -d(arr[i].x, arr[i].y) + dist(B.x, B.y, arr[i].x, arr[i].y);
            if(mini1 > tem) mini1 = tem, idx1 = i;
        }
        if(idx0 != idx1){
            printf("%.10f\n", ans + mini0 + mini1);
        }else{
            double add0 = inf, add1 = inf;
            for(int i = 0; i < n; i++){
                if(i == idx0) continue;
                double tem = -d(arr[i].x, arr[i].y) + dist(A.x, A.y, arr[i].x, arr[i].y);
                if(add0 > tem) add0 = tem;
            }
            for(int i = 0; i < n; i++){
                if(i == idx0) continue;
                double tem = -d(arr[i].x, arr[i].y) + dist(B.x, B.y, arr[i].x, arr[i].y);
                if(add1 > tem) add1 = tem;
            }
            double ans1 = ans + mini0 + add1;
            double ans2 = ans + mini1 + add0;
            printf("%.10f\n", min(ans1, ans2));
        }
    }
    return 0;
}