#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>

int main() {
	std::cin.tie(0); std::cin.sync_with_stdio(false);
	int n; std::cin >> n;
	std::vector<long long int> distances(n, 0);
	for (auto i = 2; i < n; ++i) {
		std::cout << "1 1 2 " << i + 1 << std::endl;
		std::cin >> distances[i];
	}
	std::vector<bool> area12(n, false), area_far(n, false);
	for (auto i = 2; i < n; ++i) {
		std::cout << "2 1 2 " << i + 1 << std::endl;
		int sign; std::cin >> sign;
		area12[i] = sign == 1;
	}
	std::vector<int> indices(n); std::iota(indices.begin(), indices.end(), 0);
	const auto true_count = std::count(std::next(area12.begin(), 2), area12.end(), true);
	if (true_count == n - 2 || true_count == 0) {
		auto far = *std::max_element(indices.begin(), indices.end(), [&distances](int i, int j) {return distances[i] < distances[j]; });
		for (auto i = 2; i < n; ++i) if (i != far) {
			std::cout << "2 1 " << far + 1 << ' ' << i + 1 << std::endl;
			int sign; std::cin >> sign;
			area_far[i] = sign == 1;
		}
		std::vector<int> for_false, for_true;
		for (auto i = 2; i < n; ++i) if (i != far) {
			if (area_far[i]) for_true.push_back(i);
			else for_false.push_back(i);
		}
		std::sort(for_false.begin(), for_false.end(), [&distances](int i, int j) {return distances[i] < distances[j]; });
		std::sort(for_true.begin(), for_true.end(), [&distances](int i, int j) {return distances[i] > distances[j]; });
		if (true_count == n - 2) {
			std::cout << "0 1 2";
		}
		else {
			std::cout << "0 1";
		}
		for (auto f : for_false) {
			std::cout << " " << f + 1;
		}
		std::cout << " " << far + 1;
		for (auto t : for_true) {
			std::cout << " " << t + 1;
		}
		if (true_count == 0) {
			std::cout << " 2";
		}
		std::cout << std::endl;
	}
	else {
		int far1 = 0, far2 = 0;
		for (auto i = 2; i < n; ++i) {
			if (area12[i]) {
				if (distances[far1] < distances[i]) {
					far1 = i;
				}
			}
			else {
				if (distances[far2] < distances[i]) {
					far2 = i;
				}
			}
		}
		for (auto i = 2; i < n; ++i) if (i != far1 && i != far2) {
			std::cout << "2 " << far2 + 1 << ' ' << far1 + 1 << ' ' << i + 1 << std::endl;
			int sign; std::cin >> sign;
			area_far[i] = sign == 1;
		}
		std::vector<int> for_true_false, for_true_true, for_false_true, for_false_false;
		for (auto i = 2; i < n; ++i) if (i != far1 && i != far2) {
			if (area12[i]) {
				if (area_far[i]) for_true_true.push_back(i);
				else for_true_false.push_back(i);
			}
			else {
				if (area_far[i]) for_false_true.push_back(i);
				else for_false_false.push_back(i);
			}
		}
		std::sort(for_true_false.begin(), for_true_false.end(), [&distances](int i, int j) {return distances[i] < distances[j]; });
		std::sort(for_false_true.begin(), for_false_true.end(), [&distances](int i, int j) {return distances[i] < distances[j]; });
		std::sort(for_true_true.begin(), for_true_true.end(), [&distances](int i, int j) {return distances[i] > distances[j]; });
		std::sort(for_false_false.begin(), for_false_false.end(), [&distances](int i, int j) {return distances[i] > distances[j]; });
		std::cout << "0 " << 1;
		for (auto ft : for_false_true) {
			std::cout << ' ' << ft + 1;
		}
		std::cout << ' ' << far2 + 1;
		for (auto ff : for_false_false) {
			std::cout << ' ' << ff + 1;
		}
		std::cout << " " << 2;
		for (auto tf : for_true_false) {
			std::cout << ' ' << tf + 1;
		}
		std::cout << ' ' << far1 + 1;
		for (auto tt : for_true_true) {
			std::cout << ' ' << tt + 1;
		}
		std::cout << std::endl;
	}
}


#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>

int main() {
	std::cin.tie(0); std::cin.sync_with_stdio(false);
	int n; std::cin >> n;
	std::vector<long long int> distances(n, 0);
	for (auto i = 2; i < n; ++i) {
		std::cout << "1 1 2 " << i + 1 << std::endl;
		std::cin >> distances[i];
	}
	std::vector<bool> area12(n, false), area_far(n, false);
	for (auto i = 2; i < n; ++i) {
		std::cout << "2 1 2 " << i + 1 << std::endl;
		int sign; std::cin >> sign;
		area12[i] = sign == 1;
	}
	std::vector<int> indices(n); std::iota(indices.begin(), indices.end(), 0);
	const auto true_count = std::count(std::next(area12.begin(), 2), area12.end(), true);
	if (true_count == n - 2 || true_count == 0) {
		auto far = *std::max_element(indices.begin(), indices.end(), [&distances](int i, int j) {return distances[i] < distances[j]; });
		for (auto i = 2; i < n; ++i) if (i != far) {
			std::cout << "2 1 " << far + 1 << ' ' << i + 1 << std::endl;
			int sign; std::cin >> sign;
			area_far[i] = sign == 1;
		}
		std::vector<int> for_false, for_true;
		for (auto i = 2; i < n; ++i) if (i != far) {
			if (area_far[i]) for_true.push_back(i);
			else for_false.push_back(i);
		}
		std::sort(for_false.begin(), for_false.end(), [&distances](int i, int j) {return distances[i] < distances[j]; });
		std::sort(for_true.begin(), for_true.end(), [&distances](int i, int j) {return distances[i] > distances[j]; });
		if (true_count == n - 2) {
			std::cout << "0 1 2";
		}
		else {
			std::cout << "0 1";
		}
		for (auto f : for_false) {
			std::cout << " " << f + 1;
		}
		std::cout << " " << far + 1;
		for (auto t : for_true) {
			std::cout << " " << t + 1;
		}
		if (true_count == 0) {
			std::cout << " 2";
		}
		std::cout << std::endl;
	}
	else {
		int far1 = 0, far2 = 0;
		for (auto i = 2; i < n; ++i) {
			if (area12[i]) {
				if (distances[far1] < distances[i]) {
					far1 = i;
				}
			}
			else {
				if (distances[far2] < distances[i]) {
					far2 = i;
				}
			}
		}
		for (auto i = 2; i < n; ++i) if (i != far1 && i != far2) {
			std::cout << "2 " << far2 + 1 << ' ' << far1 + 1 << ' ' << i + 1 << std::endl;
			int sign; std::cin >> sign;
			area_far[i] = sign == 1;
		}
		std::vector<int> for_true_false, for_true_true, for_false_true, for_false_false;
		for (auto i = 2; i < n; ++i) if (i != far1 && i != far2) {
			if (area12[i]) {
				if (area_far[i]) for_true_true.push_back(i);
				else for_true_false.push_back(i);
			}
			else {
				if (area_far[i]) for_false_true.push_back(i);
				else for_false_false.push_back(i);
			}
		}
		std::cout << "0 " << 1;
		for (auto ft : for_false_true) {
			std::cout << ' ' << ft + 1;
		}
		std::cout << ' ' << far2 + 1;
		for (auto ff : for_false_false) {
			std::cout << ' ' << ff + 1;
		}
		std::cout << " " << 2;
		for (auto tf : for_true_false) {
			std::cout << ' ' << tf + 1;
		}
		std::cout << ' ' << far1 + 1;
		for (auto tt : for_true_true) {
			std::cout << ' ' << tt + 1;
		}
		std::cout << std::endl;
	}
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <ctime>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
#define enable_ll
#ifdef enable_ll
    #define int long long
#endif
#ifdef DEBUG
    #define out(u) cout<<u<<" "
    #define outln(u) cout<<u<<endl
    #define see(u) cout<<#u<<"="<<u<<" "
    #define seeln(u) cout<<#u<<"="<<u<<endl
    #define line cout<<"---------------------\n"
#else
    #define out(u)
    #define outln(u)
    #define see(u)
    #define seeln(u)
    #define line
#endif
#define m_p make_pair
#define pii pair<int,int>
#define piii pair<pii,int>
#define sz(x) (int)x.size()
#define fastio ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
template <class T> void read(T &u)
{
    u=0; char c=getchar(); int flag=0;
    while (c<'0'||c>'9') flag|=(c=='-'),c=getchar();
    while (c>='0'&&c<='9') u=(u<<3)+(u<<1)+(c^48),c=getchar();
    if (flag) u=-u;
}
template <class T> void write(T u)
{
    if (u<0) printf("-"),u=-u;
    if (u<10) putchar(48+u);
    else write(u/10),putchar(48+u%10);
}
void write(char u){putchar(u);}
template <class T,class ... Arg> void read(T &u,Arg&... v) {read(u); read(v...);}
template <class T,class ... Arg> void write(T u,Arg... v) {write(u); write(v...);}
template <class T> bool checkmin(T &a,T b){return (b<a ? a=b,1 : 0);}
template <class T> bool checkmax(T &a,T b){return (b>a ? a=b,1 : 0);}
template <class T> T _min(T a,T b){return (a<b ? a : b);}
template <class T> T _max(T a,T b){return (a>b ? a : b);}
const int N=1005;
int n;
int a[2][N],tot[2],dis[N];
void init()
{
    read(n);
}

int ask(int typ,int x,int y,int z)
{
    printf("%lld %lld %lld %lld\n",typ,x,y,z);
    fflush(stdout);
    int p;
    scanf("%lld",&p);
    return p;
}

bool cmp(int a,int b)
{
    return dis[a]<dis[b];
}

bool cnp(int a,int b)
{
    return dis[a]>dis[b];
}

void solve()
{
    for (int i=3;i<=n;++i)
    {
        if (ask(2,1,2,i)==1) a[0][++tot[0]]=i;
        else a[1][++tot[1]]=i;
    }
    vector <int> v[2][2],p[2];
    for (int rnd=0;rnd<=1;++rnd)
    {
        if (tot[rnd]==0) continue;
        int pos=0,mx=0;
        for (int i=1;i<=tot[rnd];++i)
        {
            dis[a[rnd][i]]=ask(1,1,2,a[rnd][i]);
            if (checkmax(mx,dis[a[rnd][i]])) pos=i;
        }
        int state=ask(2,1,2,a[rnd][pos]);
        for (int i=1;i<=tot[rnd];++i)
        {
            if (i==pos) continue;
            if (ask(2,1,a[rnd][i],a[rnd][pos])==state)
            {
                v[rnd][1].push_back(a[rnd][i]);
            }
            else
            {
                v[rnd][0].push_back(a[rnd][i]);
            }
        }
        sort(v[rnd][0].begin(),v[rnd][0].end(),cmp);
        sort(v[rnd][1].begin(),v[rnd][1].end(),cnp);
        for (int i=0;i<sz(v[rnd][0]);++i)
        {
            p[rnd].push_back(v[rnd][0][i]);
        }
        p[rnd].push_back(a[rnd][pos]);
        for (int i=0;i<sz(v[rnd][1]);++i)
        {
            p[rnd].push_back(v[rnd][1][i]);
        }
    }
    reverse(p[1].begin(),p[1].end());
    vector <int> ans;
    ans.push_back(1);
    for (int i=0;i<sz(p[0]);++i)
    {
        ans.push_back(p[0][i]);
    }
    ans.push_back(2);
    for (int i=0;i<sz(p[1]);++i)
    {
        ans.push_back(p[1][i]);
    }
    if (ask(2,ans[1],ans[0],ans[2])==1)
    {
        for (int i=1,j=sz(ans)-1;i<j;++i,--j)
        {
            swap(ans[i],ans[j]);
        }
    }
    printf("0");
    for (int i=0;i<sz(ans);++i) printf(" %lld",ans[i]);
    printf("\n");
}

#undef int
int main()
{
    int T=1;
    //read(T);
    while (T--)
    {
        init();
        solve();
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <ctime>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
#define enable_ll
#ifdef enable_ll
    #define int long long
#endif
#ifdef DEBUG
    #define out(u) cout<<u<<" "
    #define outln(u) cout<<u<<endl
    #define see(u) cout<<#u<<"="<<u<<" "
    #define seeln(u) cout<<#u<<"="<<u<<endl
    #define line cout<<"---------------------\n"
#else
    #define out(u)
    #define outln(u)
    #define see(u)
    #define seeln(u)
    #define line
#endif
#define m_p make_pair
#define pii pair<int,int>
#define piii pair<pii,int>
#define sz(x) (int)x.size()
#define fastio ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
template <class T> void read(T &u)
{
    u=0; char c=getchar(); int flag=0;
    while (c<'0'||c>'9') flag|=(c=='-'),c=getchar();
    while (c>='0'&&c<='9') u=(u<<3)+(u<<1)+(c^48),c=getchar();
    if (flag) u=-u;
}
template <class T> void write(T u)
{
    if (u<0) printf("-"),u=-u;
    if (u<10) putchar(48+u);
    else write(u/10),putchar(48+u%10);
}
void write(char u){putchar(u);}
template <class T,class ... Arg> void read(T &u,Arg&... v) {read(u); read(v...);}
template <class T,class ... Arg> void write(T u,Arg... v) {write(u); write(v...);}
template <class T> bool checkmin(T &a,T b){return (b<a ? a=b,1 : 0);}
template <class T> bool checkmax(T &a,T b){return (b>a ? a=b,1 : 0);}
template <class T> T _min(T a,T b){return (a<b ? a : b);}
template <class T> T _max(T a,T b){return (a>b ? a : b);}
const int N=1005;
int n;
int a[2][N],tot[2],dis[N];
void init()
{
    read(n);
}

int ask(int typ,int x,int y,int z)
{
    printf("%lld %lld %lld %lld\n",typ,x,y,z);
    fflush(stdout);
    int p;
    scanf("%lld",&p);
    return p;
}

bool cmp(int a,int b)
{
    return dis[a]<dis[b];
}

bool cnp(int a,int b)
{
    return dis[a]>dis[b];
}

void solve()
{
    for (int i=3;i<=n;++i)
    {
        if (ask(2,1,2,i)==1) a[0][++tot[0]]=i;
        else a[1][++tot[1]]=i;
    }
    vector <int> v[2][2],p[2];
    for (int rnd=0;rnd<=1;++rnd)
    {
        int pos=0,mx=0;
        for (int i=1;i<=tot[rnd];++i)
        {
            dis[a[rnd][i]]=ask(1,1,2,a[rnd][i]);
            if (checkmax(mx,dis[a[rnd][i]])) pos=i;
        }
        int state=ask(2,1,2,a[rnd][pos]);
        for (int i=1;i<=tot[rnd];++i)
        {
            if (i==pos) continue;
            if (ask(2,1,a[rnd][i],a[rnd][pos])==state)
            {
                v[rnd][1].push_back(a[rnd][i]);
            }
            else
            {
                v[rnd][0].push_back(a[rnd][i]);
            }
        }
        sort(v[rnd][0].begin(),v[rnd][0].end(),cmp);
        sort(v[rnd][1].begin(),v[rnd][1].end(),cnp);
        for (int i=0;i<sz(v[rnd][0]);++i)
        {
            p[rnd].push_back(v[rnd][0][i]);
        }
        p[rnd].push_back(a[rnd][pos]);
        for (int i=0;i<sz(v[rnd][1]);++i)
        {
            p[rnd].push_back(v[rnd][1][i]);
        }
    }
    reverse(p[1].begin(),p[1].end());
    vector <int> ans;
    ans.push_back(1);
    for (int i=0;i<sz(p[0]);++i)
    {
        ans.push_back(p[0][i]);
    }
    ans.push_back(2);
    for (int i=0;i<sz(p[1]);++i)
    {
        ans.push_back(p[1][i]);
    }
    if (ask(2,ans[1],ans[0],ans[2])==1) reverse(ans.begin(),ans.end());
    for (int i=0;i<sz(ans);++i) printf("%lld%c",ans[i], " \n"[i==sz(ans)-1]);
}

#undef int
int main()
{
    int T=1;
    //read(T);
    while (T--)
    {
        init();
        solve();
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <ctime>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
#define enable_ll
#ifdef enable_ll
    #define int long long
#endif
#ifdef DEBUG
    #define out(u) cout<<u<<" "
    #define outln(u) cout<<u<<endl
    #define see(u) cout<<#u<<"="<<u<<" "
    #define seeln(u) cout<<#u<<"="<<u<<endl
    #define line cout<<"---------------------\n"
#else
    #define out(u)
    #define outln(u)
    #define see(u)
    #define seeln(u)
    #define line
#endif
#define m_p make_pair
#define pii pair<int,int>
#define piii pair<pii,int>
#define sz(x) (int)x.size()
#define fastio ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
template <class T> void read(T &u)
{
    u=0; char c=getchar(); int flag=0;
    while (c<'0'||c>'9') flag|=(c=='-'),c=getchar();
    while (c>='0'&&c<='9') u=(u<<3)+(u<<1)+(c^48),c=getchar();
    if (flag) u=-u;
}
template <class T> void write(T u)
{
    if (u<0) printf("-"),u=-u;
    if (u<10) putchar(48+u);
    else write(u/10),putchar(48+u%10);
}
void write(char u){putchar(u);}
template <class T,class ... Arg> void read(T &u,Arg&... v) {read(u); read(v...);}
template <class T,class ... Arg> void write(T u,Arg... v) {write(u); write(v...);}
template <class T> bool checkmin(T &a,T b){return (b<a ? a=b,1 : 0);}
template <class T> bool checkmax(T &a,T b){return (b>a ? a=b,1 : 0);}
template <class T> T _min(T a,T b){return (a<b ? a : b);}
template <class T> T _max(T a,T b){return (a>b ? a : b);}
const int N=1005;
int n;
int a[2][N],tot[2],dis[N];
void init()
{
    read(n);
}

int ask(int typ,int x,int y,int z)
{
    printf("%lld %lld %lld %lld\n",typ,x,y,z);
    fflush(stdout);
    int p;
    scanf("%lld",&p);
    return p;
}

bool cmp(int a,int b)
{
    return dis[a]<dis[b];
}

bool cnp(int a,int b)
{
    return dis[a]>dis[b];
}

void solve()
{
    for (int i=3;i<=n;++i)
    {
        if (ask(2,1,2,i)==1) a[0][++tot[0]]=i;
        else a[1][++tot[1]]=i;
    }
    vector <int> v[2][2],p[2];
    for (int rnd=0;rnd<=1;++rnd)
    {
        int pos=0,mx=0;
        for (int i=1;i<=tot[rnd];++i)
        {
            dis[a[rnd][i]]=ask(1,1,2,a[rnd][i]);
            if (checkmax(mx,dis[a[rnd][i]])) pos=i;
        }
        int state=ask(2,1,2,a[rnd][pos]);
        for (int i=1;i<=tot[rnd];++i)
        {
            if (i==pos) continue;
            if (ask(2,1,a[rnd][i],a[rnd][pos])==state)
            {
                v[rnd][1].push_back(a[rnd][i]);
            }
            else
            {
                v[rnd][0].push_back(a[rnd][i]);
            }
        }
        sort(v[rnd][0].begin(),v[rnd][0].end(),cmp);
        sort(v[rnd][1].begin(),v[rnd][1].end(),cnp);
        for (int i=0;i<sz(v[rnd][0]);++i)
        {
            p[rnd].push_back(v[rnd][0][i]);
        }
        p[rnd].push_back(a[rnd][pos]);
        for (int i=0;i<sz(v[rnd][1]);++i)
        {
            p[rnd].push_back(v[rnd][1][i]);
        }
    }
    reverse(p[1].begin(),p[1].end());
    vector <int> ans;
    ans.push_back(1);
    for (int i=0;i<sz(p[0]);++i)
    {
        ans.push_back(p[0][i]);
    }
    ans.push_back(2);
    for (int i=0;i<sz(p[1]);++i)
    {
        ans.push_back(p[1][i]);
    }
    if (ask(2,ans[1],ans[0],ans[2])==1) reverse(ans.begin(),ans.end());
    printf("0");
    for (int i=0;i<sz(ans);++i) printf(" %lld",ans[i]);
    printf("\n");
}

#undef int
int main()
{
    int T=1;
    //read(T);
    while (T--)
    {
        init();
        solve();
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <ctime>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
#define enable_ll
#ifdef enable_ll
    #define int long long
#endif
#ifdef DEBUG
    #define out(u) cout<<u<<" "
    #define outln(u) cout<<u<<endl
    #define see(u) cout<<#u<<"="<<u<<" "
    #define seeln(u) cout<<#u<<"="<<u<<endl
    #define line cout<<"---------------------\n"
#else
    #define out(u)
    #define outln(u)
    #define see(u)
    #define seeln(u)
    #define line
#endif
#define m_p make_pair
#define pii pair<int,int>
#define piii pair<pii,int>
#define sz(x) (int)x.size()
#define fastio ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
template <class T> void read(T &u)
{
    u=0; char c=getchar(); int flag=0;
    while (c<'0'||c>'9') flag|=(c=='-'),c=getchar();
    while (c>='0'&&c<='9') u=(u<<3)+(u<<1)+(c^48),c=getchar();
    if (flag) u=-u;
}
template <class T> void write(T u)
{
    if (u<0) printf("-"),u=-u;
    if (u<10) putchar(48+u);
    else write(u/10),putchar(48+u%10);
}
void write(char u){putchar(u);}
template <class T,class ... Arg> void read(T &u,Arg&... v) {read(u); read(v...);}
template <class T,class ... Arg> void write(T u,Arg... v) {write(u); write(v...);}
template <class T> bool checkmin(T &a,T b){return (b<a ? a=b,1 : 0);}
template <class T> bool checkmax(T &a,T b){return (b>a ? a=b,1 : 0);}
template <class T> T _min(T a,T b){return (a<b ? a : b);}
template <class T> T _max(T a,T b){return (a>b ? a : b);}
const int N=1005;
int n;
int a[2][N],tot[2],dis[N];
void init()
{
    read(n);
}

int ask(int typ,int x,int y,int z)
{
    printf("%lld %lld %lld %lld\n",typ,x,y,z);
    fflush(stdout);
    int p;
    scanf("%lld",&p);
    return p;
}

bool cmp(int a,int b)
{
    return dis[a]<dis[b];
}

bool cnp(int a,int b)
{
    return dis[a]>dis[b];
}

void solve()
{
    for (int i=3;i<=n;++i)
    {
        if (ask(2,1,2,i)==1) a[0][++tot[0]]=i;
        else a[1][++tot[1]]=i;
    }
    vector <int> v[2][2],p[2];
    for (int rnd=0;rnd<=1;++rnd)
    {
        int pos=0,mx=0;
        for (int i=1;i<=tot[rnd];++i)
        {
            dis[a[rnd][i]]=ask(1,1,2,a[rnd][i]);
            if (checkmax(mx,dis[a[rnd][i]])) pos=i;
        }
        int state=ask(2,1,2,a[rnd][pos]);
        for (int i=1;i<=tot[rnd];++i)
        {
            if (i==pos) continue;
            if (ask(2,1,a[rnd][i],a[rnd][pos])==state)
            {
                v[rnd][1].push_back(a[rnd][i]);
            }
            else
            {
                v[rnd][0].push_back(a[rnd][i]);
            }
        }
        sort(v[rnd][0].begin(),v[rnd][0].end(),cmp);
        sort(v[rnd][1].begin(),v[rnd][1].end(),cnp);
        for (int i=0;i<sz(v[rnd][0]);++i)
        {
            p[rnd].push_back(v[rnd][0][i]);
        }
        p[rnd].push_back(a[rnd][pos]);
        for (int i=0;i<sz(v[rnd][1]);++i)
        {
            p[rnd].push_back(v[rnd][1][i]);
        }
    }
    reverse(p[1].begin(),p[1].end());
    vector <int> ans;
    ans.push_back(1);
    for (int i=0;i<sz(p[0]);++i)
    {
        ans.push_back(p[0][i]);
    }
    ans.push_back(2);
    for (int i=0;i<sz(p[1]);++i)
    {
        ans.push_back(p[1][i]);
    }
    if (ask(2,ans[1],ans[0],ans[2])==1)
    {
        for (int i=1,j=sz(ans)-1;i<j;++i,--j)
        {
            swap(ans[i],ans[j]);
        }
    }
    printf("0");
    for (int i=0;i<sz(ans);++i) printf(" %lld",ans[i]);
    printf("\n");
}

#undef int
int main()
{
    int T=1;
    //read(T);
    while (T--)
    {
        init();
        solve();
    }
    return 0;
}


// C
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <new>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

const int N = 1e3 + 9;
using ll = long long;

void Dump(const std::vector<int>& vec) {
    for (int i = 0; i < (int)vec.size(); ++i) {
        // printf("[%d] %d\n", i, vec[i]);
        printf("%d\n", vec[i]);
    }
}

void Dump(const std::set<int>& set1) {
    for (auto v : set1) {
        printf("%d\n", v);
    }
}

// std::cout << N << std::endl;
int n;
std::vector<int> left, right;
ll area12[N];

ll GetArea(int i, int j, int k) {
    printf("1 %d %d %d\n", i, j, k);
    fflush(stdout);
    ll area;
    scanf("%lld", &area);
    return area;
}

int GetSign(int i, int j, int k) {
    printf("2 %d %d %d\n", i, j, k);
    fflush(stdout);
    int sign = 0;
    scanf("%d", &sign);
    assert(sign == 1 || sign == -1);
    return sign;
}

void Divide() {
    for (int i = 3; i <= n; ++i) {
        auto sign = GetSign(1, 2, i);
        if (sign > 0)
            left.push_back(i);
        else {
            right.push_back(i);
        }
    }
    area12[1] = 0;
    area12[2] = 0;
}

void Sort(std::vector<int>& vec) {
    int farest = 1;
    for (auto v : vec) {
        area12[v] = GetArea(1, 2, v);
        if (area12[v] > area12[farest]) {
            farest = v;
        }
    }

    // divide again by farest vertex
    std::vector<int> l, r;
    for (auto v : vec) {
        auto sign = GetSign(1, farest, v);
        if (sign > 0)
            l.push_back(v);
        else
            r.push_back(v);
    }

    std::sort(r.begin(), r.end(), [](int a, int b){
        return area12[a] < area12[b];
    });

    std::sort(l.begin(), l.end(), [](int a, int b){
        return area12[a] > area12[b];
    });

    vec.clear();
    for (auto v : r)
        vec.push_back(v);
    vec.push_back(farest);
    for (auto v : l)
        vec.push_back(v);
}

void DumpAns() {
    printf("0 1"); // leading with 0, and start with 1
    for (auto v : right)
        printf(" %d", v);
    printf(" 2");
    for (auto v : left)
        printf(" %d", v);
    printf("\n");
}

/*
任意找两个点将凸多边形分成左右两边,这里简化起见,两个点设置为1和2
向量叉积的符号oa x ob, 根据右手法则,正:b在o的顺时针,a在o的逆时针;负:a在o的顺时针,b在o的逆时针,这里顺时针简化为在o的左边,反之,在o的右边
根据第2条ask规则(即叉积)的方式可以将3-n这些顶点划分到edge1-2这条边的两侧, 需要n-2次ask
由于是凸多边形,那么在同一侧的这些顶点会形成肯定存在一个定位距离edge1-2最远,而且其两侧的顶点到edge1-2这条边分别是递增和递减
这样edge1-2的侧可以排列出来,同理另一侧可以也可以排列出来了
计算距离需要n-2次ask
计算最远点两侧总共需要n-4次ask
所以总的ask复杂度是3n-8
*/
int main() {
    // printf(">\n");
    scanf("%d", &n);
    assert(n >= 3);
    Divide();
    Sort(left);
    Sort(right);
    DumpAns();

    return 0;
}


// C
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <new>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

const int N = 1e3 + 9;
using ll = long long;

void Dump(const std::vector<int>& vec) {
    for (int i = 0; i < (int)vec.size(); ++i) {
        // printf("[%d] %d\n", i, vec[i]);
        printf("%d\n", vec[i]);
    }
}

void Dump(const std::set<int>& sset) {
    for (auto v : sset) {
        printf("%d\n", v);
    }
}

// std::cout << N << std::endl;
int n;
std::vector<int> left, right;
ll area12[N];

ll GetArea(int i, int j, int k) {
    printf("1 %d %d %d\n", i, j, k);
    fflush(stdout);
    ll area;
    scanf("%lld", &area);
    return area;
}

int GetSign(int i, int j, int k) {
    printf("2 %d %d %d", i, j, k);
    fflush(stdout);
    int sign = 0;
    scanf("%d", &sign);
    assert(sign == 1 || sign == -1);
    return sign;
}

void Divide() {
    for (int i = 3; i <= n; ++i) {
        auto sign = GetSign(1, 2, i);
        if (sign > 0)
            left.push_back(i);
        else {
            right.push_back(i);
        }
    }
    area12[1] = 0;
    area12[2] = 0;
}

void Sort(std::vector<int>& vec) {
    int farest = 1;
    for (auto v : vec) {
        area12[v] = GetArea(1, 2, v);
        if (area12[v] > area12[farest]) {
            farest = v;
        }
    }

    // divide again by farest vertex
    std::vector<int> l, r;
    for (auto v : vec) {
        auto sign = GetSign(1, farest, v);
        if (sign > 0)
            l.push_back(v);
        else
            r.push_back(v);
    }

    std::sort(r.begin(), r.end(), [](int a, int b){
        return area12[a] < area12[b];
    });

    std::sort(l.begin(), l.end(), [](int a, int b){
        return area12[a] > area12[b];
    });

    vec.clear();
    for (auto v : r)
        vec.push_back(v);
    vec.push_back(farest);
    for (auto v : l)
        vec.push_back(v);
}

void DumpAns() {
    printf("0 1"); // leading with 0, and start with 1
    for (auto v : right)
        printf(" %d", v);
    printf(" 2");
    for (auto v : left)
        printf(" %d", v);
    printf("\n");
}

/*
任意找两个点将凸多边形分成左右两边,这里简化起见,两个点设置为1和2
向量叉积的符号oa x ob, 根据右手法则,正:b在o的顺时针,a在o的逆时针;负:a在o的顺时针,b在o的逆时针,这里顺时针简化为在o的左边,反之,在o的右边
根据第2条ask规则(即叉积)的方式可以将3-n这些顶点划分到edge1-2这条边的两侧, 需要n-2次ask
由于是凸多边形,那么在同一侧的这些顶点会形成肯定存在一个定位距离edge1-2最远,而且其两侧的顶点到edge1-2这条边分别是递增和递减
这样edge1-2的侧可以排列出来,同理另一侧可以也可以排列出来了
计算距离需要n-2次ask
计算最远点两侧总共需要n-4次ask
所以总的ask复杂度是3n-8
*/
int main() {
    // printf(">\n");
    scanf("%d", &n);
    assert(n >= 3);
    Divide();
    Sort(left);
    Sort(right);
    DumpAns();

    return 0;
}


// C
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <new>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

const int N = 1e3 + 9;
using ll = long long;

void Dump(const std::vector<int>& vec) {
    for (int i = 0; i < (int)vec.size(); ++i) {
        // printf("[%d] %d\n", i, vec[i]);
        printf("%d\n", vec[i]);
    }
}

void Dump(const std::set<int>& set1) {
    for (auto v : set1) {
        printf("%d\n", v);
    }
}

// std::cout << N << std::endl;
int n;
std::vector<int> left, right;
ll area12[N];

ll GetArea(int i, int j, int k) {
    printf("1 %d %d %d\n", i, j, k);
    fflush(stdout);
    ll area;
    scanf("%lld", &area);
    return area;
}

int GetSign(int i, int j, int k) {
    printf("2 %d %d %d\n", i, j, k);
    fflush(stdout);
    int sign = 0;
    scanf("%d", &sign);
    // assert(sign == 1 || sign == -1);
    if (sign != 1 && sign != -1) {
        printf("sign = %d\n", sign);
        assert(0);
    }
    return sign;
}

void Divide() {
    for (int i = 3; i <= n; ++i) {
        auto sign = GetSign(1, 2, i);
        if (sign > 0)
            left.push_back(i);
        else {
            right.push_back(i);
        }
    }
    area12[1] = 0;
    area12[2] = 0;
}

void Sort(std::vector<int>& vec) {
    if (vec.empty())
        return;

    int farest = 1;
    for (auto v : vec) {
        area12[v] = GetArea(1, 2, v);
        if (area12[v] > area12[farest]) {
            farest = v;
        }
    }

    // divide again by farest vertex
    std::vector<int> l, r;
    for (auto v : vec) {
        if (v == farest)
            continue;
        auto sign = GetSign(1, farest, v);
        if (sign > 0)
            l.push_back(v);
        else
            r.push_back(v);
    }

    std::sort(r.begin(), r.end(), [](int a, int b){
        return area12[a] < area12[b];
    });

    std::sort(l.begin(), l.end(), [](int a, int b){
        return area12[a] > area12[b];
    });

    vec.clear();
    for (auto v : r)
        vec.push_back(v);
    vec.push_back(farest);
    for (auto v : l)
        vec.push_back(v);
}

void DumpAns() {
    printf("0 1"); // leading with 0, and start with 1
    for (auto v : right)
        printf(" %d", v);
    printf(" 2");
    for (auto v : left)
        printf(" %d", v);
    printf("\n");
}

/*
任意找两个点将凸多边形分成左右两边,这里简化起见,两个点设置为1和2
向量叉积的符号oa x ob, 根据右手法则,正:b在o的顺时针,a在o的逆时针;负:a在o的顺时针,b在o的逆时针,这里顺时针简化为在o的左边,反之,在o的右边
根据第2条ask规则(即叉积)的方式可以将3-n这些顶点划分到edge1-2这条边的两侧, 需要n-2次ask
由于是凸多边形,那么在同一侧的这些顶点会形成肯定存在一个定位距离edge1-2最远,而且其两侧的顶点到edge1-2这条边分别是递增和递减
这样edge1-2的侧可以排列出来,同理另一侧可以也可以排列出来了
计算距离需要n-2次ask
计算最远点两侧总共需要n-4次ask
所以总的ask复杂度是3n-8
*/
int main() {
    // printf(">\n");
    scanf("%d", &n);
    assert(n >= 3);
    Divide();
    Sort(left);
    Sort(right);
    DumpAns();

    return 0;
}

/*
case
6
-2 1
3 -1
-2 -1
1 -2
0 3
2 2

6
-1
-1
1
1
14
13
-1
10
9
1

4
1
1
2
2
-1

*/


// C
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <new>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

const int N = 1e3 + 9;
using ll = long long;

void Dump(const std::vector<int>& vec) {
    for (int i = 0; i < (int)vec.size(); ++i) {
        // printf("[%d] %d\n", i, vec[i]);
        printf("%d\n", vec[i]);
    }
}

void Dump(const std::set<int>& set1) {
    for (auto v : set1) {
        printf("%d\n", v);
    }
}

// std::cout << N << std::endl;
int n;
std::vector<int> left, right;
ll area12[N];

ll GetArea(int i, int j, int k) {
    printf("1 %d %d %d\n", i, j, k);
    fflush(stdout);
    ll area;
    scanf("%lld", &area);
    return area;
}

int GetSign(int i, int j, int k) {
    printf("2 %d %d %d\n", i, j, k);
    fflush(stdout);
    int sign = 0;
    scanf("%d", &sign);
    // assert(sign == 1 || sign == -1);
    if (sign != 1 && sign != -1) {
        printf("sign = %d\n", sign);
        assert(0);
    }
    return sign;
}

void Divide() {
    for (int i = 3; i <= n; ++i) {
        auto sign = GetSign(1, 2, i);
        if (sign > 0)
            left.push_back(i);
        else {
            right.push_back(i);
        }
    }
    area12[1] = 0;
    area12[2] = 0;
}

void Sort(std::vector<int>& vec) {
    int farest = 1;
    for (auto v : vec) {
        area12[v] = GetArea(1, 2, v);
        if (area12[v] > area12[farest]) {
            farest = v;
        }
    }

    // divide again by farest vertex
    std::vector<int> l, r;
    for (auto v : vec) {
        if (v == farest)
            continue;
        auto sign = GetSign(1, farest, v);
        if (sign > 0)
            l.push_back(v);
        else
            r.push_back(v);
    }

    std::sort(r.begin(), r.end(), [](int a, int b){
        return area12[a] < area12[b];
    });

    std::sort(l.begin(), l.end(), [](int a, int b){
        return area12[a] > area12[b];
    });

    vec.clear();
    for (auto v : r)
        vec.push_back(v);
    vec.push_back(farest);
    for (auto v : l)
        vec.push_back(v);
}

void DumpAns() {
    printf("0 1"); // leading with 0, and start with 1
    for (auto v : right)
        printf(" %d", v);
    printf(" 2");
    for (auto v : left)
        printf(" %d", v);
    printf("\n");
}

/*
任意找两个点将凸多边形分成左右两边,这里简化起见,两个点设置为1和2
向量叉积的符号oa x ob, 根据右手法则,正:b在o的顺时针,a在o的逆时针;负:a在o的顺时针,b在o的逆时针,这里顺时针简化为在o的左边,反之,在o的右边
根据第2条ask规则(即叉积)的方式可以将3-n这些顶点划分到edge1-2这条边的两侧, 需要n-2次ask
由于是凸多边形,那么在同一侧的这些顶点会形成肯定存在一个定位距离edge1-2最远,而且其两侧的顶点到edge1-2这条边分别是递增和递减
这样edge1-2的侧可以排列出来,同理另一侧可以也可以排列出来了
计算距离需要n-2次ask
计算最远点两侧总共需要n-4次ask
所以总的ask复杂度是3n-8
*/
int main() {
    // printf(">\n");
    scanf("%d", &n);
    assert(n >= 3);
    Divide();
    Sort(left);
    Sort(right);
    DumpAns();

    return 0;
}

/*
case
6
-2 1
3 -1
-2 -1
1 -2
0 3
2 2

6
-1
-1
1
1
14
13
-1
10
9
1

*/


#include <bits/stdc++.h>
#define VI vector<int>
#define pb push_back
#define LL long long
#define mp make_pair
#define pii pair<int,int>
using namespace std;
LL make_question(int t, int a, int b, int c){
	printf("%d %d %d %d\n", t, a, b, c); fflush(stdout);
	LL x;
	scanf("%lld", &x);
	return x;
}
int n;
VI solve(vector<pair<LL,LL> >& d){
	int m = d.size();
	if(m == 0) return VI();
	sort(d.begin(), d.end());
	int far = d[m-1].second;
	VI left, right;
	for(int i = 0; i < m - 1; i++){
		LL sgn = make_question(2, 1, far, d[i].second);
		if(sgn < 0) right.pb(d[i].second);
		else left.pb(d[i].second);
	}
	right.pb(far);
	reverse(left.begin(), left.end());
	VI ans = left;
	for(int i = 0; i < right.size(); i++) ans.pb(right[i]);
	return ans;
}
int main(){
	scanf("%d", &n);
	vector<pair<LL,LL> > left, right;
	for(int i = 3; i <= n; i++){
		LL sgn = make_question(2, 1, 2, i);
		LL area = make_question(1, 1, 2, i);
		if(sgn < 0) right.pb(mp(area,i));
		else left.pb(mp(area, i));
	}
	VI L = solve(left), R = solve(right);
	reverse(R.begin(), R.end());
	printf("0 1");
	for(int i = 0; i < R.size(); i++) printf(" %d", R[i]);
	printf(" 2");
	for(int i = 0; i < L.size(); i++) printf(" %d", L[i]);
	printf("\n"); fflush(stdout);
	return 0;
}


#include <bits/stdc++.h>
#define VI vector<int>
#define pb push_back
#define LL long long
#define mp make_pair
#define pii pair<int,int>
using namespace std;
LL make_question(int t, int a, int b, int c){
	printf("%d %d %d %d\n", t, a, b, c); fflush(stdout);
	LL x;
	scanf("%lld", &x);
	return x;
}
int n;
VI solve(vector<pair<LL,LL> >& d){
	int m = d.size();
	if(m <= 1) return VI();
	sort(d.begin(), d.end());
	int far = d[m-1].second;
	VI left, right;
	for(int i = 0; i < m - 1; i++){
		LL sgn = make_question(2, 1, far, d[i].second);
		if(sgn < 0) right.pb(d[i].second);
		else left.pb(d[i].second);
	}
	right.pb(far);
	reverse(left.begin(), left.end());
	VI ans = left;
	for(int i = 0; i < right.size(); i++) ans.pb(right[i]);
	return ans;
}
int main(){
	scanf("%d", &n);
	vector<pair<LL,LL> > left, right;
	for(int i = 3; i <= n; i++){
		LL sgn = make_question(2, 1, 2, i);
		LL area = make_question(1, 1, 2, i);
		if(sgn < 0) right.pb(mp(area,i));
		else left.pb(mp(area, i));
	}
	VI L = solve(left), R = solve(right);
	printf("0 1");
	for(int i = 0; i < R.size(); i++) printf(" %d", R[i]);
	printf(" 2");
	for(int i = 0; i < L.size(); i++) printf(" %d", L[i]);
	printf("\n"); fflush(stdout);
	return 0;
}


#include <bits/stdc++.h>
#define VI vector<int>
#define pb push_back
#define LL long long
#define mp make_pair
#define pii pair<int,int>
using namespace std;
LL make_question(int t, int a, int b, int c){
	printf("%d %d %d %d\n", t, a, b, c); fflush(stdout);
	LL x;
	scanf("%lld", &x);
	return x;
}
int n;
VI solve(vector<pair<LL,LL> >& d, int piv){
	int m = d.size();
	if(m == 0) return VI();
	sort(d.begin(), d.end());
	int far = d[m-1].second;
	VI left, right;
	for(int i = 0; i < m - 1; i++){
		LL sgn = make_question(2, piv, far, d[i].second);
		if(sgn < 0) right.pb(d[i].second);
		else left.pb(d[i].second);
	}
	right.pb(far);
	reverse(left.begin(), left.end());
	VI ans = right;
	for(int i = 0; i < left.size(); i++) ans.pb(left[i]);
	return ans;
}
int main(){
	scanf("%d", &n);
	vector<pair<LL,LL> > left, right;
	for(int i = 3; i <= n; i++){
		LL sgn = make_question(2, 1, 2, i);
		LL area = make_question(1, 1, 2, i);
		if(sgn < 0) right.pb(mp(area,i));
		else left.pb(mp(area, i));
	}
	VI L = solve(left, 2), R = solve(right, 1);
	printf("0 1");
	for(int i = 0; i < R.size(); i++) printf(" %d", R[i]);
	printf(" 2");
	for(int i = 0; i < L.size(); i++) printf(" %d", L[i]);
	printf("\n"); fflush(stdout);
	return 0;
}


#include <bits/stdc++.h>
#define VI vector<int>
#define pb push_back
#define LL long long
#define mp make_pair
#define pii pair<int,int>
using namespace std;
LL make_question(int t, int a, int b, int c){
	printf("%d %d %d %d\n", t, a, b, c); fflush(stdout);
	LL x;
	scanf("%lld", &x);
	return x;
}
int n;
VI solve(vector<pair<LL,LL> >& d){
	int m = d.size();
	if(m <= 1) return VI();
	sort(d.begin(), d.end());
	int far = d[m-1].second;
	VI left, right;
	for(int i = 0; i < m - 1; i++){
		LL sgn = make_question(2, 1, far, d[i].second);
		if(sgn < 0) right.pb(d[i].second);
		else left.pb(d[i].second);
	}
	right.pb(far);
	//reverse(left.begin(), left.end());
	VI ans = left;
	for(int i = 0; i < right.size(); i++) ans.pb(right[i]);
	return ans;
}
int main(){
	scanf("%d", &n);
	vector<pair<LL,LL> > left, right;
	for(int i = 3; i <= n; i++){
		LL sgn = make_question(2, 1, 2, i);
		LL area = make_question(1, 1, 2, i);
		if(sgn < 0) right.pb(mp(area,i));
		else left.pb(mp(area, i));
	}
	VI L = solve(left), R = solve(right);
	printf("0 1");
	for(int i = 0; i < R.size(); i++) printf(" %d", R[i]);
	printf(" 2");
	for(int i = 0; i < L.size(); i++) printf(" %d", L[i]);
	printf("\n"); fflush(stdout);
	return 0;
}


#include <bits/stdc++.h>
#define VI vector<int>
#define pb push_back
#define LL long long
#define mp make_pair
#define pii pair<int,int>
using namespace std;
LL make_question(int t, int a, int b, int c){
	printf("%d %d %d %d\n", t, a, b, c); fflush(stdout);
	LL x;
	scanf("%lld", &x);
	return x;
}
int n;
VI solve(vector<pair<LL,LL> >& d){
	int m = d.size();
	if(m <= 1) return VI();
	sort(d.begin(), d.end());
	int far = d[m-1].second;
	VI left, right;
	for(int i = 0; i < m - 1; i++){
		LL sgn = make_question(2, 1, far, d[i].second);
		if(sgn < 0) right.pb(d[i].second);
		else left.pb(d[i].second);
	}
	right.pb(far);
	reverse(left.begin(), left.end());
	VI ans = left;
	for(int i = 0; i < right.size(); i++) ans.pb(right[i]);
	return ans;
}
int main(){
	scanf("%d", &n);
	vector<pair<LL,LL> > left, right;
	for(int i = 3; i <= n; i++){
		LL sgn = make_question(2, 1, 2, i);
		LL area = make_question(1, 1, 2, i);
		if(sgn < 0) right.pb(mp(area,i));
		else left.pb(mp(area, i));
	}
	VI L = solve(left), R = solve(right);
	reverse(R.begin(), R.end());
	printf("0 1");
	for(int i = 0; i < R.size(); i++) printf(" %d", R[i]);
	printf(" 2");
	for(int i = 0; i < L.size(); i++) printf(" %d", L[i]);
	printf("\n"); fflush(stdout);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int,int> pii;

LL query(int t,int i,int j,int k) {
    printf("%d %d %d %d\n",t,i,j,k);
    fflush(stdout);
    LL ret;
    scanf("%lld",&ret);
    return ret;
}

LL s[1010];
vector<pair<LL,int>> sr,sl;

int main() {
    int N;
    scanf("%d",&N);
    int nb = 2;
    for (int i=3;i<=N;i++) {
        if (query(2,1,nb,i) == -1) {
            nb = i;
        }
    }
    LL mx = 0;
    int midx = -1;
    for (int i=2;i<=N;i++) {
        if (i != nb) {
            LL tmp = query(1,1,nb,i);
            s[i] = tmp;
            if (tmp > mx) {
                mx = tmp;
                midx = i;
            }
        }
    }
    for (int i=2;i<=N;i++) {
        if (i != nb && i != midx) {
            if (query(2,1,midx,i) > 0) {
                sr.push_back(pii(s[i], i));
            } else {
                sl.push_back(pii(s[i], i));
            }
        }
    }
    sort(sl.begin(),sl.end());
    sort(sr.begin(),sr.end());
    reverse(sr.begin(),sr.end());
    printf("0 1 %d",nb);
    if (N == 124) {
        printf("%d %lld\n",midx,mx);
        printf("%lld %lld\n",s[86],s[46]);
    }
    for (auto t:sl) {
        printf(" %d",t.second);
    }
    printf(" %d",midx);
    for (auto t:sr) {
        printf(" %d",t.second);
    }
    puts("");
    fflush(stdout);
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<LL,int> pli;

LL query(int t,int i,int j,int k) {
    printf("%d %d %d %d\n",t,i,j,k);
    fflush(stdout);
    LL ret;
    scanf("%lld",&ret);
    return ret;
}

LL s[1010];
vector<pair<LL,int>> sr,sl;

int main() {
    int N;
    scanf("%d",&N);
    int nb = 2;
    for (int i=3;i<=N;i++) {
        if (query(2,1,nb,i) == -1) {
            nb = i;
        }
    }
    LL mx = 0;
    int midx = -1;
    for (int i=2;i<=N;i++) {
        if (i != nb) {
            LL tmp = query(1,1,nb,i);
            s[i] = tmp;
            if (tmp > mx) {
                mx = tmp;
                midx = i;
            }
        }
    }
    for (int i=2;i<=N;i++) {
        if (i != nb && i != midx) {
            if (query(2,1,midx,i) > 0) {
                sr.push_back(pli(s[i], i));
            } else {
                sl.push_back(pli(s[i], i));
            }
        }
    }
    sort(sl.begin(),sl.end());
    sort(sr.begin(),sr.end());
    reverse(sr.begin(),sr.end());
    printf("0 1 %d",nb);
    for (auto t:sl) {
        printf(" %d",t.second);
    }
    printf(" %d",midx);
    for (auto t:sr) {
        printf(" %d",t.second);
    }
    puts("");
    fflush(stdout);
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int,int> pii;

LL query(int t,int i,int j,int k) {
    printf("%d %d %d %d\n",t,i,j,k);
    fflush(stdout);
    LL ret;
    scanf("%lld",&ret);
    return ret;
}

LL s[1010];
vector<pair<LL,int>> sr,sl;

int main() {
    int N;
    scanf("%d",&N);
    int nb = 2;
    for (int i=3;i<=N;i++) {
        if (query(2,1,nb,i) == -1) {
            nb = i;
        }
    }
    LL mx = 0;
    int midx = -1;
    for (int i=2;i<=N;i++) {
        if (i != nb) {
            LL tmp = query(1,1,nb,i);
            s[i] = tmp;
            if (tmp > mx) {
                mx = tmp;
                midx = i;
            }
        }
    }
    for (int i=2;i<=N;i++) {
        if (i != nb && i != midx) {
            if (query(2,1,midx,i) > 0) {
                sr.push_back(pii(s[i], i));
            } else {
                sl.push_back(pii(s[i], i));
            }
        }
    }
    sort(sl.begin(),sl.end());
    sort(sr.begin(),sr.end());
    reverse(sr.begin(),sr.end());
    printf("0 1 %d",nb);
    for (auto t:sl) {
        printf(" %d",t.second);
    }
    printf(" %d",midx);
    for (auto t:sr) {
        printf(" %d",t.second);
    }
    puts("");
    fflush(stdout);
}


#include<bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

int ask(int t, int a, int b, int c)
{
	printf("%d %d %d %d\n", t, a, b, c); fflush(stdout);
	int x; scanf("%d", &x);
	return x;
}

int main()
{
	// freopen("input.in", "r", stdin);

	int n; scanf("%d", &n);
	int X = 1, Y = 2;
	for(int i = 3; i <= n; i++)
	{
		if(ask(2, X, Y, i) == -1)
			Y = i;
	}
	vector<ii> vec;
	for(int i = 2; i <= n; i++)
	{
		if(i == Y) continue;
		vec.push_back({ask(1, X, Y, i), i});
	}
	sort(vec.begin(), vec.end());
	deque<int> deq = {X,Y};
	for(int i = 0; i+1 < vec.size(); i++)
	{
		if(ask(2, X, vec[i].se, vec[i+1].se) == 1)
			deq.push_back(vec[i].se);
		else
			deq.push_front(vec[i].se);
	}
	deq.push_back(vec.back().se);
	printf(" ");
	for(int i = 0; i < deq.size(); i++) printf("%d%c", deq[i], (i == n-1)? '\n' : ' ');
}


#include<bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define fi first
#define se second
#define long long long
typedef pair<long,int> ii;

long ask(int t, int a, int b, int c)
{
	printf("%d %d %d %d\n", t, a, b, c); fflush(stdout);
	long x; scanf("%lld", &x);
	return x;
}

int main()
{
	// freopen("input.in", "r", stdin);

	int n; scanf("%d", &n);
	int X = 1, Y = 2;
	for(int i = 3; i <= n; i++)
	{
		if(ask(2, X, Y, i) == -1)
			Y = i;
	}
	vector<ii> vec;
	for(int i = 2; i <= n; i++)
	{
		if(i == Y) continue;
		vec.push_back({ask(1, X, Y, i), i});
	}
	sort(vec.begin(), vec.end());
	deque<int> deq = {X,Y};
	for(int i = 0; i+1 < vec.size(); i++)
	{
		if(ask(2, X, vec[i].se, vec[i+1].se) == 1)
			deq.push_back(vec[i].se);
		else
			deq.push_front(vec[i].se);
	}
	deq.push_back(vec.back().se);
	while(deq[0] != 1) deq.push_back(deq.front()), deq.pop_front();
	printf("0 ");
	for(int i = 0; i < deq.size(); i++) printf("%d%c", deq[i], (i == n-1)? '\n' : ' ');
}


#include<bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

int ask(int t, int a, int b, int c)
{
	printf("%d %d %d %d\n", t, a, b, c); fflush(stdout);
	int x; scanf("%d", &x);
	return x;
}

int main()
{
	// freopen("input.in", "r", stdin);

	int n; scanf("%d", &n);
	int X = 1, Y = 2;
	for(int i = 3; i <= n; i++)
	{
		if(ask(2, X, Y, i) == -1)
			Y = i;
	}
	vector<ii> vec;
	for(int i = 2; i <= n; i++)
	{
		if(i == Y) continue;
		vec.push_back({ask(1, X, Y, i), i});
	}
	sort(vec.begin(), vec.end());
	deque<int> deq = {X,Y};
	for(int i = 0; i+1 < vec.size(); i++)
	{
		if(ask(2, X, vec[i].se, vec[i+1].se) == 1)
			deq.push_back(vec[i].se);
		else
			deq.push_front(vec[i].se);
	}
	deq.push_back(vec.back().se);
	printf("0 ");
	for(int i = 0; i < deq.size(); i++) printf("%d%c", deq[i], (i == n-1)? '\n' : ' ');
}


#include<bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

long ask(int t, int a, int b, int c)
{
	printf("%d %d %d %d\n", t, a, b, c); fflush(stdout);
	long x; scanf("%lld", &x);
	return x;
}

int main()
{
	// freopen("input.in", "r", stdin);

	int n; scanf("%d", &n);
	int X = 1, Y = 2;
	for(int i = 3; i <= n; i++)
	{
		if(ask(2, X, Y, i) == -1)
			Y = i;
	}
	vector<ii> vec;
	for(int i = 2; i <= n; i++)
	{
		if(i == Y) continue;
		vec.push_back({ask(1, X, Y, i), i});
	}
	sort(vec.begin(), vec.end());
	deque<int> deq = {X,Y};
	for(int i = 0; i+1 < vec.size(); i++)
	{
		if(ask(2, X, vec[i].se, vec[i+1].se) == 1)
			deq.push_back(vec[i].se);
		else
			deq.push_front(vec[i].se);
	}
	deq.push_back(vec.back().se);
	while(deq[0] != 1) deq.push_back(deq.front()), deq.pop_front();
	printf("0 ");
	for(int i = 0; i < deq.size(); i++) printf("%d%c", deq[i], (i == n-1)? '\n' : ' ');
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define eps 0.00000001

using namespace std;
typedef pair<double, double> pdd;

vector <pdd> s;

double dist(pdd a, pdd b){
  return sqrt((a.ff - b.ff)*(a.ff - b.ff) + (a.ss - b.ss)*(a.ss - b.ss));
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  double ax, ay, f, fa, fb, ans = 0;
  pdd a, b, t, pa, pb;
  cin >> ax >> ay;
  a = pdd(ax, ay);
  cin >> ax >> ay;
  b = pdd(ax, ay);
  cin >> ax >> ay;
  t = pdd(ax, ay);
  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> ax >> ay;
    s.push_back(pdd(ax, ay));
  }
  pa = s[0];
  pb = s[0];

  for(int i = 0; i < n; ++i){
    f = dist(a, pa) - dist(t, pa) + dist(b, pb) - dist(t, pb);
    fa = dist(a, s[i]) - dist(t, s[i]) + dist(b, pb) - dist(t, pb);
    fb = dist(a, pa) - dist(t, pa) + dist(b, s[i]) - dist(t, s[i]);
    if(f < fa + eps && f < fb + eps)  continue;
    if(fa <= fb){
      if(dist(b, pa) - dist(t, pa) < dist(b, pb) - dist(t, pb) + eps) pb = pa;
      pa = s[i];
    }
    else{
      if(dist(a, pb) - dist(t, pb) < dist(a, pa) - dist(t, pa) + eps) pa = pb;
      pb = s[i];
    }
  }
  for(int i = 0; i < n; ++i)  ans += 2*dist(t, s[i]);
  if(dist(a, pa) <= dist(t, pa) + eps) ans += dist(a, pa) - dist(t, pa);
  if(dist(b, pb) <= dist(t, pb) + eps) ans += dist(b, pb) - dist(t, pb);
  if(dist(a, pa) > dist(t, pa) + eps && dist(b, pb) > dist(t, pb) + eps){
    ans += min(dist(a, pa) - dist(t, pa), dist(b, pb) - dist(t, pb));
  }
  cout << fixed << setprecision(12) << ans << "\n";

  return 0;

}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define eps 0.00000001

using namespace std;
typedef pair<double, double> pdd;

vector <pdd> s;

double dist(pdd a, pdd b){
  return sqrt((a.ff - b.ff)*(a.ff - b.ff) + (a.ss - b.ss)*(a.ss - b.ss));
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  double  ax, ay, az, f, fa, fb, ans;
  pdd a, b, t, pa, pb;
  cin >> ax >> ay;
  a = pdd(ax, ay);
  cin >> ax >> ay;
  b = pdd(ax, ay);
  cin >> ax >> ay;
  t = pdd(ax, ay);
  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> ax >> ay;
    s.push_back(pdd(ax, ay));
  }
  pa = s[0];
  pb = s[0];

  for(int i = 0; i < n; ++i){
    ax = dist(a, s[i]);
    ay = dist(b, s[i]);
    az = dist(t, s[i]);
    f = dist(a, pa) - dist(t, pa) + dist(b, pb) - dist(t, pb);
    fa = dist(a, s[i]) - dist(t, s[i]) + dist(b, pb) - dist(t, pb);
    fb = dist(a, pa) - dist(t, pa) + dist(b, s[i]) - dist(t, s[i]);
    if(f < fa + eps && f < fb + eps)  continue;
    else if(fa <= fb){
      if(dist(b, pa) - dist(t, pa) < dist(b, pb) - dist(t, pb)) pb = pa;
      pa = s[i];
    }
    else{
      if(dist(a, pb) - dist(t, pb) < dist(a, pa) - dist(t, pa)) pa = pb;
      pb = s[i];
    }
  }
  for(int i = 0; i < n; ++i)  ans += 2*dist(t, s[i]);
  if(dist(a, pa) <= dist(t, pa)) ans += dist(a, pa) - dist(t, pa);
  if(dist(b, pb) <= dist(t, pb)) ans += dist(b, pb) - dist(t, pb);
  if(dist(a, pa) > dist(t, pa) && dist(b, pb) > dist(t, pb)){
    ans += min(dist(a, pa) - dist(t, pa), dist(b, pb) - dist(t, pb));
  }
  cout << fixed << setprecision(12) << ans << "\n";

  return 0;

}


#include <bits/stdc++.h>
#define ff first
#define ss second

using namespace std;
typedef pair<double, double> pdd;

pdd a, b, t;

double dist(pdd x, pdd y){
  return sqrt((x.ff - y.ff)*(x.ff - y.ff) + (x.ss - y.ss)*(x.ss - y.ss));
}

bool compa(pdd x, pdd y){
  double dx = dist(a, x) - dist(x, t);
  double dy = dist(a, y) - dist(y, t);
  return dx <= dy;
}

bool compb(pdd x, pdd y){
  double dx = dist(b, x) - dist(x, t);
  double dy = dist(b, y) - dist(y, t);
  return dx <= dy;
}

vector <pdd> va, vb;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  pdd pos;
  double ans = 0, sum;
  cin >> a.ff >> a.ss >> b.ff >> b.ss >> t.ff >> t.ss >> n;
  for(int i = 0; i < n; ++i){
    cin >> pos.ff >> pos.ss;
    va.push_back(pos);
    vb.push_back(pos);
    ans += 2*dist(pos, t);
  }
  sum = ans;

  sort(va.begin(), va.end(), compa);
  sort(vb.begin(), vb.end(), compb);
  if(va.size() == 0)
    ans = min(dist(va[0], t) + dist(a, va[0]), dist(vb[0], t) + dist(b, vb[0]));
  else{
    ans = min(sum + dist(va[0], a) - dist(va[0], t), sum + dist(vb[0], b) - dist(vb[0], t));
    if(va[0] != vb[0])  ans = min(ans, sum + dist(va[0], a) - dist(va[0], t) + dist(vb[0], b) - dist(vb[0], t));
    if(va[0] != vb[1])  ans = min(ans, sum + dist(va[0], a) - dist(va[0], t) + dist(vb[1], b) - dist(vb[1], t));
    if(va[1] != vb[0])  ans = min(ans, sum + dist(va[1], a) - dist(va[1], t) + dist(vb[0], b) - dist(vb[0], t));
  }
  cout << fixed << setprecision(12) << ans << "\n";
  return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define eps 0.00000001

using namespace std;
typedef pair<double, double> pdd;

pdd a, b, t;
vector <pdd> va, vb;

double dist(pdd a, pdd b){
  return sqrt((a.ff - b.ff)*(a.ff - b.ff) + (a.ss - b.ss)*(a.ss - b.ss));
}

bool compa(pdd x, pdd y){
  return dist(x, a) - dist(x, t) < dist(y, a) - dist(y, t);
}

bool compb(pdd x, pdd y){
  return dist(x, b) - dist(x, t) < dist(y, b) - dist(y, t);
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  double ax, ay, f, fa, fb, ans = 0, best = 0;
  pdd pa, pb;
  cin >> ax >> ay;
  a = pdd(ax, ay);
  cin >> ax >> ay;
  b = pdd(ax, ay);
  cin >> ax >> ay;
  t = pdd(ax, ay);
  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> ax >> ay;
    va.push_back(pdd(ax, ay));
    vb.push_back(va[i]);
  }

  sort(va.begin(), va.end(), compa);
  sort(vb.begin(), vb.end(), compb);

  if(va.size() == 1)  ans += min(dist(va[0], a), dist(vb[0], b)) + dist(t, va[0]);
  else{
    for(int i = 0; i < n; ++i)  ans += 2*dist(t, va[i]);
    best = dist(va[0], a) - dist(t, va[0]);
    best = min(best, dist(vb[0], b) - dist(t, vb[0]));
    best = min(best, dist(va[0], a) - dist(t, va[0]) + dist(vb[1], b) - dist(t, vb[1]));
    best = min(best, dist(va[1], a) - dist(t, va[1]) + dist(vb[0], b) - dist(t, vb[0]));
    if(va[0] != vb[0])
      best = min(best, dist(va[0], a) - dist(t, va[0]) + dist(vb[0], b) - dist(t, vb[0]));
  }

  //cout << pa.ff << " " << pa.ss << " " << pb.ff << " " << pb.ss << endl;
  cout << fixed << setprecision(12) << ans + best << "\n";

  return 0;

}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define eps 0.00000001

using namespace std;
typedef pair<double, double> pdd;

vector <pdd> s;

double dist(pdd a, pdd b){
  return sqrt((a.ff - b.ff)*(a.ff - b.ff) + (a.ss - b.ss)*(a.ss - b.ss));
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  double  ax, ay, az, f, fa, fb, ans;
  pdd a, b, t, pa, pb;
  cin >> ax >> ay;
  a = pdd(ax, ay);
  cin >> ax >> ay;
  b = pdd(ax, ay);
  cin >> ax >> ay;
  t = pdd(ax, ay);
  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> ax >> ay;
    s.push_back(pdd(ax, ay));
  }
  pa = s[0];
  pb = s[0];

  for(int i = 0; i < n; ++i){
    ax = dist(a, s[i]);
    ay = dist(b, s[i]);
    az = dist(t, s[i]);
    f = dist(a, pa) - dist(t, pa) + dist(b, pb) - dist(t, pb);
    fa = dist(a, s[i]) - dist(t, s[i]) + dist(b, pb) - dist(t, pb);
    fb = dist(a, pa) - dist(t, pa) + dist(b, s[i]) - dist(t, s[i]);
    if(f < fa + eps && f < fb + eps)  continue;
    else if(fa <= fb){
      if(dist(b, pa) - dist(t, pa) < dist(b, pb) - dist(t, pb)) pb = pa;
      pa = s[i];
    }
    else{
      if(dist(a, pb) - dist(t, pb) < dist(a, pa) - dist(t, pa)) pa = pb;
      pb = s[i];
    }
  }
  for(int i = 0; i < n; ++i)  ans += 2*dist(t, s[i]);
  if(dist(a, pa) < dist(t, pa)) ans += dist(a, pa) - dist(t, pa);
  if(dist(b, pb) < dist(t, pb)) ans += dist(b, pb) - dist(t, pb);
  cout << fixed << setprecision(12) << ans << "\n";

  return 0;

}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define eps 0.00000001

using namespace std;
typedef pair<double, double> pdd;

pdd a, b, t;
vector <pdd> va, vb;

double dist(pdd a, pdd b){
  return sqrt((a.ff - b.ff)*(a.ff - b.ff) + (a.ss - b.ss)*(a.ss - b.ss));
}

bool compa(pdd x, pdd y){
  return dist(x, a) - dist(x, t) < dist(y, a) - dist(y, t);
}

bool compb(pdd x, pdd y){
  return dist(x, b) - dist(x, t) < dist(y, b) - dist(y, t);
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  double ax, ay, f, fa, fb, ans = 0;
  pdd pa, pb;
  cin >> ax >> ay;
  a = pdd(ax, ay);
  cin >> ax >> ay;
  b = pdd(ax, ay);
  cin >> ax >> ay;
  t = pdd(ax, ay);
  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> ax >> ay;
    va.push_back(pdd(ax, ay));
    vb.push_back(va[i]);
  }

  sort(va.begin(), va.end(), compa);
  sort(vb.begin(), vb.end(), compb);

  if(va.size() == 1)  ans += min(dist(va[0], a), dist(vb[0], b)) + dist(t, va[0]);
  else{
    for(int i = 0; i < n; ++i)  ans += 2*dist(t, va[i]);
    if(va[0] == vb[0]){
      if(dist(va[1], a) - dist(va[1], t) + dist(vb[0], b) - dist(vb[0], t) < dist(va[0], a) - dist(va[0], t) + dist(vb[1], b) - dist(vb[1], t))
        va[0] = va[1];
      else
        vb[0] = vb[1];
    }
    if(dist(va[0], a) - dist(va[0], t) > 0 && dist(vb[0], b) - dist(vb[0], t) > 0)
      ans += min(dist(va[0], a) - dist(va[0], t), dist(vb[0], b) - dist(vb[0], t));
    else if(dist(va[0], a) - dist(va[0], t) > 0){
      ans += dist(vb[0], b) - dist(vb[0], t);
    }
    else if(dist(vb[0], b) - dist(vb[0], t) > 0)
      ans += dist(va[0], a) - dist(va[0], t);
    /*else if(va[0] == vb[0]){
      cout << ans << endl;
      cout << dist(va[1], a) - dist(va[1], t) + dist(vb[0], b) - dist(vb[0], t) << " " << dist(va[0], a) - dist(va[0], t) + dist(vb[1], b) - dist(vb[1], t) << endl;
      ans += min(dist(va[1], a) + dist(vb[0], b) - dist(va[1], t) - dist(vb[0], t), dist(va[0], a) + dist(vb[1], b) - dist(va[0], t) - dist(vb[1], t));
    }*/
    else  ans += dist(va[0], a) + dist(vb[0], b) - dist(va[0], t) - dist(vb[0], t);
  }

  //cout << pa.ff << " " << pa.ss << " " << pb.ff << " " << pb.ss << endl;
  cout << fixed << setprecision(12) << ans << "\n";

  return 0;

}


#include <bits/stdc++.h>
#define ff first
#define ss second

using namespace std;
typedef pair<double, double> pdd;

pdd a, b, t;

double dist(pdd x, pdd y){
  return sqrt((x.ff - y.ff)*(x.ff - y.ff) + (x.ss - y.ss)*(x.ss - y.ss));
}

bool compa(pdd x, pdd y){
  double dx = dist(a, x) - dist(x, t);
  double dy = dist(a, y) - dist(y, t);
  return dx <= dy;
}

bool compb(pdd x, pdd y){
  double dx = dist(b, x) - dist(x, t);
  double dy = dist(b, y) - dist(y, t);
  return dx <= dy;
}

vector <pdd> va, vb;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  pdd pos;
  double ans = 0, sum;
  cin >> a.ff >> a.ss >> b.ff >> b.ss >> t.ff >> t.ss >> n;
  for(int i = 0; i < n; ++i){
    cin >> pos.ff >> pos.ss;
    va.push_back(pos);
    vb.push_back(pos);
    ans += 2*dist(pos, t);
  }
  sum = ans;

  sort(va.begin(), va.end(), compa);
  sort(vb.begin(), vb.end(), compb);

  ans = min(sum + dist(va[0], a) - dist(va[0], t), sum + dist(vb[0], b) - dist(vb[0], t));
  if(va[0] != vb[0])  ans = min(ans, sum + dist(va[0], a) - dist(va[0], t) + dist(vb[0], b) - dist(vb[0], t));
  if(va[0] != vb[1])  ans = min(ans, sum + dist(va[0], a) - dist(va[0], t) + dist(vb[1], b) - dist(vb[1], t));
  if(va[1] != vb[0])  ans = min(ans, sum + dist(va[1], a) - dist(va[1], t) + dist(vb[0], b) - dist(vb[0], t));

  cout << fixed << setprecision(12) << ans << "\n";
  return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define eps 0.00000001

using namespace std;
typedef pair<double, double> pdd;

vector <pdd> s;

double dist(pdd a, pdd b){
  return sqrt((a.ff - b.ff)*(a.ff - b.ff) + (a.ss - b.ss)*(a.ss - b.ss));
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  double ax, ay, f, fa, fb, ans = 0;
  pdd a, b, t, pa, pb;
  cin >> ax >> ay;
  a = pdd(ax, ay);
  cin >> ax >> ay;
  b = pdd(ax, ay);
  cin >> ax >> ay;
  t = pdd(ax, ay);
  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> ax >> ay;
    s.push_back(pdd(ax, ay));
  }
  pa = pb = s[0];

  for(int i = 0; i < n; ++i)
    if(dist(a, s[i]) < dist(a, pa)) pa = s[i];
  for(int i = 0; i < n; ++i)
    if(dist(b, s[i]) < dist(b, pb)) pb = s[i];

  for(int i = 0; i < n; ++i){
    f = dist(a, pa) - dist(t, pa) + dist(b, pb) - dist(t, pb);
    fa = dist(a, s[i]) - dist(t, s[i]) + dist(b, pb) - dist(t, pb);
    fb = dist(a, pa) - dist(t, pa) + dist(b, s[i]) - dist(t, s[i]);
    if(f < fa && f < fb)  continue;
    if(fa < fb){
      if(dist(b, pa) - dist(t, pa) < dist(b, pb) - dist(t, pb) + eps || pb.ff < 0) pb = pa;
      pa = s[i];
    }
    else{
      if(dist(a, pb) - dist(t, pb) < dist(a, pa) - dist(t, pa) + eps || pa.ff < 0) pa = pb;
      pb = s[i];
    }
  }
  for(int i = 0; i < n; ++i)  ans += 2*dist(t, s[i]);
  if(dist(a, pa) <= dist(t, pa) + eps) ans += dist(a, pa) - dist(t, pa);
  if(dist(b, pb) <= dist(t, pb) + eps) ans += dist(b, pb) - dist(t, pb);
  if(dist(a, pa) > dist(t, pa) + eps && dist(b, pb) > dist(t, pb) + eps){
    ans += min(dist(a, pa) - dist(t, pa), dist(b, pb) - dist(t, pb));
  }
  //cout << pa.ff << " " << pa.ss << " " << pb.ff << " " << pb.ss << endl;
  cout << fixed << setprecision(12) << ans << "\n";

  return 0;

}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define eps 0.00000001

using namespace std;
typedef pair<double, double> pdd;

pdd a, b, t;
vector <pdd> va, vb;

double dist(pdd a, pdd b){
  return sqrt((a.ff - b.ff)*(a.ff - b.ff) + (a.ss - b.ss)*(a.ss - b.ss));
}

bool compa(pdd x, pdd y){
  return dist(x, a) - dist(x, t) < dist(y, a) - dist(y, t);
}

bool compb(pdd x, pdd y){
  return dist(x, b) - dist(x, t) < dist(y, b) - dist(y, t);
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  double ax, ay, f, fa, fb, ans = 0, best;
  pdd pa, pb;
  cin >> ax >> ay;
  a = pdd(ax, ay);
  cin >> ax >> ay;
  b = pdd(ax, ay);
  cin >> ax >> ay;
  t = pdd(ax, ay);
  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> ax >> ay;
    va.push_back(pdd(ax, ay));
    vb.push_back(va[i]);
  }

  sort(va.begin(), va.end(), compa);
  sort(vb.begin(), vb.end(), compb);

  if(va.size() == 1)  ans += min(dist(va[0], a), dist(vb[0], b)) + dist(t, va[0]);
  else{
    for(int i = 0; i < n; ++i)  ans += 2*dist(t, va[i]);
    best = dist(va[0], a) - dist(t, va[0]);
    best = min(best, dist(vb[0], b) - dist(t, vb[0]));
    best = min(best, dist(va[0], a) - dist(t, va[0]) + dist(vb[1], b) - dist(t, vb[1]));
    best = min(best, dist(va[1], a) - dist(t, va[1]) + dist(vb[0], b) - dist(t, vb[0]));
    if(va[0] != vb[0])
      best = min(best, dist(va[0], a) - dist(t, va[0]) + dist(vb[0], b) - dist(t, vb[0]));
  }

  //cout << pa.ff << " " << pa.ss << " " << pb.ff << " " << pb.ss << endl;
  cout << fixed << setprecision(12) << ans + best << "\n";

  return 0;

}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define eps 0.00000001

using namespace std;
typedef pair<double, double> pdd;

pdd a, b, t;
vector <pdd> va, vb;

double dist(pdd a, pdd b){
  return sqrt((a.ff - b.ff)*(a.ff - b.ff) + (a.ss - b.ss)*(a.ss - b.ss));
}

bool compa(pdd x, pdd y){
  return dist(x, a) - dist(x, t) < dist(y, a) - dist(y, t);
}

bool compb(pdd x, pdd y){
  return dist(x, b) - dist(x, t) < dist(y, b) - dist(y, t);
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  double ax, ay, f, fa, fb, ans = 0;
  pdd pa, pb;
  cin >> ax >> ay;
  a = pdd(ax, ay);
  cin >> ax >> ay;
  b = pdd(ax, ay);
  cin >> ax >> ay;
  t = pdd(ax, ay);
  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> ax >> ay;
    va.push_back(pdd(ax, ay));
    vb.push_back(va[i]);
  }

  sort(va.begin(), va.end(), compa);
  sort(vb.begin(), vb.end(), compb);

  if(va.size() == 1)  ans += min(dist(va[0], a), dist(vb[0], b)) - dist(t, va[0]);
  else{
    for(int i = 0; i < n; ++i)  ans += 2*dist(t, va[i]);
    if(dist(va[0], a) - dist(va[0], t) > 0 && dist(vb[0], b) - dist(vb[0], t) > 0)
      ans += min(dist(va[0], a) - dist(va[0], t), dist(vb[0], b) - dist(vb[0], t));
    else if(dist(va[0], a) - dist(va[0], t) > 0)
      ans += dist(vb[0], b) - dist(vb[0], t);
    else if(dist(vb[0], b) - dist(vb[0], t) > 0)
      ans += dist(va[0], a) - dist(va[0], t);
    else if(va[0] == vb[0])
      ans += min(dist(va[1], a) + dist(vb[0], b) - dist(va[1], t) - dist(vb[0], t), dist(va[0], a) + dist(vb[1], b) - dist(va[0], t) - dist(vb[1], t));
    else  ans += dist(va[0], a) + dist(vb[0], b) - dist(va[0], t) - dist(vb[0], t);
  }

  //cout << pa.ff << " " << pa.ss << " " << pb.ff << " " << pb.ss << endl;
  cout << fixed << setprecision(12) << ans << "\n";

  return 0;

}


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

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,(int)(n)-1,0)
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP(i,0,(int)(n)-1)
#define INF 100000000

typedef long long ll;

double dist(double a, double b, double c, double d) {
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
}

int main() {
    int i, ax, ay, bx, by, tx, ty, n;
    int x[100000], y[100000];
    scanf("%d%d%d%d%d%d",&ax, &ay, &bx, &by, &tx, &ty);
    scanf("%d",&n);
    rep (i,n)
        scanf("%d%d",x+i,y+i);

    double fa, sa, fb, sb;
    int ifa, isa, ifb, isb;
    double ans;
    fa = sa = fb = sb = ifa = isa = ifb = isb = -INF;
    rep (i,n) {
        double d = dist(tx,ty,x[i],y[i]) - dist(ax,ay,x[i],y[i]);
        if (d > fa) {
            sa = fa;
            isa = ifa;
            fa = d;
            ifa = i;
        }
        else if (d > sa) {
            sa = d;
            isa = i;
        }
        d = dist(tx,ty,x[i],y[i]) - dist(bx,by,x[i],y[i]);
        if (d > fb) {
            sb = fb;
            isb = ifb;
            fb = d;
            ifb = i;
        }
        else if (d > sb) {
            sb = d;
            isb = i;
        }
    }
    if (ifa == ifb) {
        if (fa + sb > sa + fb) {
            fb = sb;
            ifb = isb;
        }
        else {
            fa = sa;
            ifa = isa;
        }
    }
    ans = 0;
    rep (i,n) {
        ans += dist(x[i],y[i],tx,ty) * 2;
        if (i == ifa)
            ans -= fa;
        else if (i == ifb)
            ans -= fb;
    }

    printf("%.8f\n",ans);
    return 0;
}


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

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,(int)(n)-1,0)
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP(i,0,(int)(n)-1)
#define INF 100000000

typedef long long ll;

double dist(double a, double b, double c, double d) {
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
}

int main() {
    int i, ax, ay, bx, by, tx, ty, n;
    int x[100000], y[100000];
    scanf("%d%d%d%d%d%d",&ax, &ay, &bx, &by, &tx, &ty);
    scanf("%d",&n);
    rep (i,n)
        scanf("%d%d",x+i,y+i);

    double fa, sa, fb, sb;
    int ifa, isa, ifb, isb;
    double ans;
    fa = sa = fb = sb = ifa = isa = ifb = isb = -INF;
    rep (i,n) {
        double d = dist(tx,ty,x[i],y[i]) - dist(ax,ay,x[i],y[i]);
        if (d > fa) {
            sa = fa;
            isa = ifa;
            fa = d;
            ifa = i;
        }
        else if (d > sa) {
            sa = d;
            isa = i;
        }
        d = dist(tx,ty,x[i],y[i]) - dist(bx,by,x[i],y[i]);
        if (d > fb) {
            sb = fb;
            isb = ifb;
            fb = d;
            ifb = i;
        }
        else if (d > sb) {
            sb = d;
            isb = i;
        }
    }
    if (ifa == ifb) {
        if (fa + sb > sa + fb) {
            fb = sb;
            ifb = isb;
        }
        else {
            fa = sa;
            ifa = isa;
        }
    }
    if (fa < 0 || fb < 0) {
        if (fa > fb)
            ifb = -INF;
        else
            ifa = -INF;
    }
    ans = 0;
    rep (i,n) {
        ans += dist(x[i],y[i],tx,ty) * 2;
        if (i == ifa)
            ans -= fa;
        else if (i == ifb)
            ans -= fb;
    }

    printf("%.8f\n",ans);
    return 0;
}


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

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,(int)(n)-1,0)
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP(i,0,(int)(n)-1)
#define INF 1000000000

typedef long long ll;

double dist(double a, double b, double c, double d) {
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
}

int main() {
    int i, ax, ay, bx, by, tx, ty, n;
    int x[100000], y[100000];
    scanf("%d%d%d%d%d%d",&ax, &ay, &bx, &by, &tx, &ty);
    scanf("%d",&n);
    rep (i,n)
        scanf("%d%d",x+i,y+i);

    double fa, sa, fb, sb;
    int ifa, isa, ifb, isb;
    double ans;
    fa = sa = fb = sb = ifa = isa = ifb = isb = -INF;
    rep (i,n) {
        double d = dist(tx,ty,x[i],y[i]) - dist(ax,ay,x[i],y[i]);
        if (d > fa) {
            sa = fa;
            isa = ifa;
            fa = d;
            ifa = i;
        }
        else if (d > sa) {
            sa = d;
            isa = i;
        }
        d = dist(tx,ty,x[i],y[i]) - dist(bx,by,x[i],y[i]);
        if (d > fb) {
            sb = fb;
            isb = ifb;
            fb = d;
            ifb = i;
        }
        else if (d > sb) {
            sb = d;
            isb = i;
        }
    }
    if (ifa == ifb) {
        if (fa + sb > sa + fb) {
            fb = sb;
            ifb = isb;
        }
        else {
            fa = sa;
            ifa = isa;
        }
    }
    if (fa < 0 || fb < 0) {
        if (fa > fb)
            ifb = -INF;
        else
            ifa = -INF;
    }
    ans = 0;
    rep (i,n) {
        ans += dist(x[i],y[i],tx,ty) * 2;
        if (i == ifa)
            ans -= fa;
        else if (i == ifb)
            ans -= fb;
    }

    printf("%.8f\n",ans);
    return 0;
}


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

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,(int)(n)-1,0)
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP(i,0,(int)(n)-1)
#define INF 1e10

typedef long long ll;

double dist(double a, double b, double c, double d) {
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
}

int main() {
    int i, ax, ay, bx, by, tx, ty, n;
    int x[100000], y[100000];
    scanf("%d%d%d%d%d%d",&ax, &ay, &bx, &by, &tx, &ty);
    scanf("%d",&n);
    rep (i,n)
        scanf("%d%d",x+i,y+i);

    double fa, sa, fb, sb;
    int ifa, isa, ifb, isb;
    double ans;
    fa = sa = fb = sb = ifa = isa = ifb = isb = -INF;
    rep (i,n) {
        double d = dist(tx,ty,x[i],y[i]) - dist(ax,ay,x[i],y[i]);
        if (d > fa) {
            sa = fa;
            isa = ifa;
            fa = d;
            ifa = i;
        }
        else if (d > sa) {
            sa = d;
            isa = i;
        }
        d = dist(tx,ty,x[i],y[i]) - dist(bx,by,x[i],y[i]);
        if (d > fb) {
            sb = fb;
            isb = ifb;
            fb = d;
            ifb = i;
        }
        else if (d > sb) {
            sb = d;
            isb = i;
        }
    }
    if (ifa == ifb) {
        if (fa + sb > sa + fb) {
            fb = sb;
            ifb = isb;
        }
        else {
            fa = sa;
            ifa = isa;
        }
    }
    if (fa < 0 || fb < 0) {
        if (fa > fb)
            ifb = -INF;
        else
            ifa = -INF;
    }
    ans = 0;
    rep (i,n) {
        ans += dist(x[i],y[i],tx,ty) * 2;
        if (i == ifa)
            ans -= fa;
        else if (i == ifb)
            ans -= fb;
    }

    printf("%.8f\n",ans);
    return 0;
}


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

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,(int)(n)-1,0)
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP(i,0,(int)(n)-1)
#define INF 1e12

typedef long long ll;

double dist(double a, double b, double c, double d) {
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
}

int main() {
    int i, ax, ay, bx, by, tx, ty, n;
    int x[100000], y[100000];
    scanf("%d%d%d%d%d%d",&ax, &ay, &bx, &by, &tx, &ty);
    scanf("%d",&n);
    rep (i,n)
        scanf("%d%d",x+i,y+i);

    double fa, sa, fb, sb;
    int ifa, isa, ifb, isb;
    double ans;
    fa = sa = fb = sb = ifa = isa = ifb = isb = -INF;
    rep (i,n) {
        double d = dist(tx,ty,x[i],y[i]) - dist(ax,ay,x[i],y[i]);
        if (d > fa) {
            sa = fa;
            isa = ifa;
            fa = d;
            ifa = i;
        }
        else if (d > sa) {
            sa = d;
            isa = i;
        }
        d = dist(tx,ty,x[i],y[i]) - dist(bx,by,x[i],y[i]);
        if (d > fb) {
            sb = fb;
            isb = ifb;
            fb = d;
            ifb = i;
        }
        else if (d > sb) {
            sb = d;
            isb = i;
        }
    }
    if (ifa == ifb && fa >= 0 && fb >= 0) {
        if (fa + sb > sa + fb) {
            fb = sb;
            ifb = isb;
        }
        else {
            fa = sa;
            ifa = isa;
        }
    }
    if (fa < 0 || fb < 0) {
        if (fa > fb)
            ifb = -INF;
        else
            ifa = -INF;
    }
    ans = 0;
    rep (i,n) {
        ans += dist(x[i],y[i],tx,ty) * 2;
        if (i == ifa)
            ans -= fa;
        else if (i == ifb)
            ans -= fb;
    }

    printf("%.8f\n",ans);
    return 0;
}


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

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,(int)(n)-1,0)
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP(i,0,(int)(n)-1)
#define INF 2e9

typedef long long ll;

double dist(double a, double b, double c, double d) {
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
}

int main() {
    int i, ax, ay, bx, by, tx, ty, n;
    int x[100000], y[100000];
    scanf("%d%d%d%d%d%d",&ax, &ay, &bx, &by, &tx, &ty);
    scanf("%d",&n);
    rep (i,n)
        scanf("%d%d",x+i,y+i);

    double fa, sa, fb, sb;
    int ifa, isa, ifb, isb;
    double ans;
    fa = sa = fb = sb = ifa = isa = ifb = isb = -INF;
    rep (i,n) {
        double d = dist(tx,ty,x[i],y[i]) - dist(ax,ay,x[i],y[i]);
        if (d > fa) {
            sa = fa;
            isa = ifa;
            fa = d;
            ifa = i;
        }
        else if (d > sa) {
            sa = d;
            isa = i;
        }
        d = dist(tx,ty,x[i],y[i]) - dist(bx,by,x[i],y[i]);
        if (d > fb) {
            sb = fb;
            isb = ifb;
            fb = d;
            ifb = i;
        }
        else if (d > sb) {
            sb = d;
            isb = i;
        }
    }
    if (ifa == ifb && fa >= 0 && fb >= 0) {
        if (fa > fb && sb < 0)
            ifb = -INF;
        else if (fa <= fb && sa < 0)
            ifa = -INF;
        else if (fa + sb > sa + fb) {
            if (sb >= 0) {
                fb = sb;
                ifb = isb;
            }
            else
                ifb = -INF;
        }
        else {
            if (sa >= 0) {
                fa = sa;
                ifa = isa;
            }
            else
                ifa = -INF;
        }
    }
    if (fa < 0 || fb < 0) {
        if (fa > fb)
            ifb = -INF;
        else
            ifa = -INF;
    }
    ans = 0;
    rep (i,n) {
        ans += dist(x[i],y[i],tx,ty) * 2;
        if (i == ifa)
            ans -= fa;
        else if (i == ifb)
            ans -= fb;
    }

    printf("%.8f\n",ans);
    return 0;
}


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

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,(int)(n)-1,0)
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP(i,0,(int)(n)-1)
#define INF 1e12

typedef long long ll;

double dist(double a, double b, double c, double d) {
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
}

int main() {
    int i, ax, ay, bx, by, tx, ty, n;
    int x[100000], y[100000];
    scanf("%d%d%d%d%d%d",&ax, &ay, &bx, &by, &tx, &ty);
    scanf("%d",&n);
    rep (i,n)
        scanf("%d%d",x+i,y+i);

    double fa, sa, fb, sb;
    int ifa, isa, ifb, isb;
    double ans;
    fa = sa = fb = sb = ifa = isa = ifb = isb = -INF;
    rep (i,n) {
        double d = dist(tx,ty,x[i],y[i]) - dist(ax,ay,x[i],y[i]);
        if (d > fa) {
            sa = fa;
            isa = ifa;
            fa = d;
            ifa = i;
        }
        else if (d > sa) {
            sa = d;
            isa = i;
        }
        d = dist(tx,ty,x[i],y[i]) - dist(bx,by,x[i],y[i]);
        if (d > fb) {
            sb = fb;
            isb = ifb;
            fb = d;
            ifb = i;
        }
        else if (d > sb) {
            sb = d;
            isb = i;
        }
    }
    if (ifa == ifb) {
        if (fa + sb > sa + fb) {
            fb = sb;
            ifb = isb;
        }
        else {
            fa = sa;
            ifa = isa;
        }
    }
    if (fa < 0 || fb < 0) {
        if (fa > fb)
            ifb = -INF;
        else
            ifa = -INF;
    }
    ans = 0;
    rep (i,n) {
        ans += dist(x[i],y[i],tx,ty) * 2;
        if (i == ifa)
            ans -= fa;
        else if (i == ifb)
            ans -= fb;
    }

    printf("%.8f\n",ans);
    return 0;
}


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

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,(int)(n)-1,0)
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP(i,0,(int)(n)-1)
#define INF 2000000000

typedef long long ll;

double dist(double a, double b, double c, double d) {
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
}

int main() {
    int i, ax, ay, bx, by, tx, ty, n;
    int x[100000], y[100000];
    scanf("%d%d%d%d%d%d",&ax, &ay, &bx, &by, &tx, &ty);
    scanf("%d",&n);
    rep (i,n)
        scanf("%d%d",x+i,y+i);

    double fa, sa, fb, sb;
    int ifa, isa, ifb, isb;
    double ans;
    fa = sa = fb = sb = ifa = isa = ifb = isb = -INF;
    rep (i,n) {
        double d = dist(tx,ty,x[i],y[i]) - dist(ax,ay,x[i],y[i]);
        if (d > fa) {
            sa = fa;
            isa = ifa;
            fa = d;
            ifa = i;
        }
        else if (d > sa) {
            sa = d;
            isa = i;
        }
        d = dist(tx,ty,x[i],y[i]) - dist(bx,by,x[i],y[i]);
        if (d > fb) {
            sb = fb;
            isb = ifb;
            fb = d;
            ifb = i;
        }
        else if (d > sb) {
            sb = d;
            isb = i;
        }
    }
    if (ifa == ifb) {
        if (fa + sb > sa + fb) {
            fb = sb;
            ifb = isb;
        }
        else {
            fa = sa;
            ifa = isa;
        }
    }
    if (fa < 0 || fb < 0) {
        if (fa > fb)
            ifb = -INF;
        else
            ifa = -INF;
    }
    ans = 0;
    rep (i,n) {
        ans += dist(x[i],y[i],tx,ty) * 2;
        if (i == ifa)
            ans -= fa;
        else if (i == ifb)
            ans -= fb;
    }

    printf("%.8f\n",ans);
    return 0;
}


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

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,(int)(n)-1,0)
#define REP(i,s,e) for (i = s; i <= e; i++)
#define rep(i,n) REP(i,0,(int)(n)-1)
#define INF 1e12

typedef long long ll;

double dist(double a, double b, double c, double d) {
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
}

int main() {
    int i, ax, ay, bx, by, tx, ty, n;
    int x[100000], y[100000];
    scanf("%d%d%d%d%d%d",&ax, &ay, &bx, &by, &tx, &ty);
    scanf("%d",&n);
    rep (i,n)
        scanf("%d%d",x+i,y+i);

    double fa, sa, fb, sb;
    int ifa, isa, ifb, isb;
    double ans;
    fa = sa = fb = sb = ifa = isa = ifb = isb = -INF;
    rep (i,n) {
        double d = dist(tx,ty,x[i],y[i]) - dist(ax,ay,x[i],y[i]);
        if (d > fa) {
            sa = fa;
            isa = ifa;
            fa = d;
            ifa = i;
        }
        else if (d > sa) {
            sa = d;
            isa = i;
        }
        d = dist(tx,ty,x[i],y[i]) - dist(bx,by,x[i],y[i]);
        if (d > fb) {
            sb = fb;
            isb = ifb;
            fb = d;
            ifb = i;
        }
        else if (d > sb) {
            sb = d;
            isb = i;
        }
    }
    if (ifa == ifb) {
        if (ax == 564394833)
            cout << fa << " " << fb << endl;
        if (fa + sb > sa + fb) {
            fb = sb;
            ifb = isb;
        }
        else {
            fa = sa;
            ifa = isa;
        }
        if (ax == 564394833)
            cout << fa << " " << fb << endl;
    }
    if (fa < 0 || fb < 0) {
        if (fa > fb)
            ifb = -INF;
        else
            ifa = -INF;
    }
    ans = 0;
    rep (i,n) {
        ans += dist(x[i],y[i],tx,ty) * 2;
        if (i == ifa)
            ans -= fa;
        else if (i == ifb)
            ans -= fb;
    }

    printf("%.8f\n",ans);
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
const int N=1e5+5;
struct point
{
    double z;
    int pos;
}a[N],b[N];;
//p[N],q[N]
double ax,ay,bx,by,tx,ty;
double dis(double x0,double y0,double x1,double y1)
{
    return  sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
}
double abs(double x)
{
    return x>=0?x:-x;
}
double cmp(point aa,point bb)
{
    return aa.z<bb.z;
}
int main()
{
    int n;
    double px,py;
    while(scanf("%lf%lf",&ax,&ay)!=EOF)
    {
        scanf("%lf%lf%lf%lf",&bx,&by,&tx,&ty);
        scanf("%d",&n);
        double sum=0;
        for(int i=0; i<n ;i++)
        {
            scanf("%lf%lf",&px,&py);
            double v = dis(px,py,tx,ty);
            a[i].z=dis(ax,ay,px,py)- v;
            b[i].z=dis(bx,by,px,py)- v;
            a[i].pos=i;
            b[i].pos=i;
            sum += 2*v;
        }
        sort(a,a+n,cmp);
        sort(b,b+n,cmp);
        if(n==1)
        {
            sum=sum+min(a[0].z,b[0].z);
        }
        else if(a[0].pos!=b[0].pos)
        {
//            cout<<"---\n";
//            cout<<a[0].pos<<" "<<b[0].pos<<endl;
            sum+=min(min(a[0].z+b[0].z,a[0].z),b[0].z);
        }
        else
        {
//            cout<<"~~~~\n";
            sum+=min(a[0].z+min(b[1].z,0.0),b[0].z+min(a[1].z,0.0));
        }
        printf("%.12lf\n",sum);
    }
    return 0;
}
/*
1 0 0 1 0 0
1
1 1

100 0 0 100 0 0
2
0 1
1 0

*/


#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
#define db double
#define inf 1e19
const int N=1e5+5;
db ax,ay,bx,by,tx,ty;
db dis(db x0,db y0,db x1,db y1)
{
    return  sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
}
db a[N],b[N],c[N];
int main()
{
    int n;
    db px,py;
    while(scanf("%lf%lf",&ax,&ay)!=EOF)
    {
        scanf("%lf%lf%lf%lf",&bx,&by,&tx,&ty);
        scanf("%d",&n);
        db sum=0,ans=0;
        for(int i=1; i<=n ;i++)
        {
            scanf("%lf%lf",&px,&py);
            db v = dis(px,py,tx,ty);
            a[i]=dis(ax,ay,px,py)-v;
            b[i]=dis(bx,by,px,py)-v;
            c[i]=a[i];
            ans += 2*v;
        }
        sum=c[1]+ans;
        a[0]=inf;
        c[n+1]=inf;
        for(int i=1; i<=n ;i++)
            a[i]=min(a[i],a[i-1]);
        for(int i=n; i>=1 ;i--)
        {
            c[i]=min(c[i+1],c[i]);
        }
        for(int i=1; i<=n ;i++)
            sum=min(sum,ans+b[i]+min(0.0,min(a[i-1],c[i+1])));
        printf("%lf\n",sum);
    }
    return 0;
}
/*
1 0 0 1 0 0
1
1 1

*/


#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
#define db double
#define inf 1e18+5
#define ll long long
const int N=1e6+5;
int ax,ay,bx,by,tx,ty,px,py;
db dis(db x0,db y0,db x1,db y1)
{
    return  sqrt((ll)(x0-x1)*(x0-x1)+(ll)(y0-y1)*(y0-y1));
}
db a[N],b[N],c[N];
int main()
{
    int n;
    scanf("%d%d",&ax,&ay);
    scanf("%d%d%d%d",&bx,&by,&tx,&ty);
    scanf("%d",&n);
    db sum=0,ans=0;
    for(int i=1; i<=n ; i++)
    {
        scanf("%d%d",&px,&py);
        db v = dis(px,py,tx,ty);
        a[i]=dis(bx,by,px,py)-v;
        b[i]=dis(ax,ay,px,py)-v;
        c[i]=a[i];
        ans += 2*v;
    }
    sum=c[1]+ans;
    a[0]=inf;
    c[n+1]=inf;
    for(int i=1; i<=n ; i++)
        a[i]=min(a[i],a[i-1]);
    for(int i=n; i>=1 ; i--)
    {
        c[i]=min(c[i+1],c[i]);
    }
    for(int i=1; i<=n ; i++)
        sum = min(sum, ans + min(0.0, min(a[i-1], c[i+1])) + b[i]);
    printf("%.12lf\n",sum);

    return 0;
}
/*
1 0 0 1 0 0
1
1 1

*/


#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
const int N=1e5+5;
struct point
{
    double x,y;
    int pos;
}p[N],q[N];
double ax,ay,bx,by,tx,ty;
int cmpA(point A,point B)
{
    double a1=sqrt((A.x-tx)*(A.x-tx)+(A.y-ty)*(A.y-ty));
    double b1=sqrt((A.x-ax)*(A.x-ax)+(A.y-ay)*(A.y-ay));
    double a2=sqrt((B.x-tx)*(B.x-tx)+(B.y-ty)*(B.y-ty));
    double b2=sqrt((B.x-ax)*(B.x-ax)+(B.y-ay)*(B.y-ay));
    return a1-b1>a2-b2;
}
int cmpB(point A,point B)
{
    double a1=sqrt((A.x-tx)*(A.x-tx)+(A.y-ty)*(A.y-ty));
    double b1=sqrt((A.x-bx)*(A.x-bx)+(A.y-by)*(A.y-by));
    double a2=sqrt((B.x-tx)*(B.x-tx)+(B.y-ty)*(B.y-ty));
    double b2=sqrt((B.x-bx)*(B.x-bx)+(B.y-by)*(B.y-by));
    return a1-b1>a2-b2;
}
double dis(double x0,double y0,double x1,double y1)
{
    return  sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
}
int main()
{

    int n;
    while(scanf("%lf%lf",&ax,&ay)!=EOF)
    {
        scanf("%lf%lf%lf%lf",&bx,&by,&tx,&ty);
        scanf("%d",&n);
        for(int i=0; i<n ;i++)
        {
            scanf("%lf%lf",&p[i].x,&p[i].y);
            p[i].pos=i;
            q[i]=p[i];
        }
        sort(p,p+n,cmpA);
        sort(q,q+n,cmpB);
//        cout<<p[0].pos<<" "<<q[0].pos<<endl;
        double sum=0;
        if(p[0].pos!=q[0].pos)
        {
            sum+=dis(ax,ay,p[0].x,p[0].y)+dis(p[0].x,p[0].y,tx,ty);
            sum+=dis(bx,by,q[0].x,q[0].y)+dis(q[0].x,q[0].y,tx,ty);
            for(int i=0; i<n ;i++)
            {
                if(p[i].pos == q[0].pos||p[i].pos==p[0].pos) continue;
                sum += 2 * dis(p[i].x,p[i].y,tx,ty);
            }
        }
        else
        {
            double x1=0,x2=0;
            x1+=dis(ax,ay,p[0].x,p[0].y)+dis(p[0].x,p[0].y,tx,ty);
//            cout<<"----"<<x1<<endl;
            x1+=dis(bx,by,q[1].x,q[1].y)+dis(q[1].x,q[1].y,tx,ty);
            for(int i=0; i<n ;i++)
            {
                if(p[i].pos == q[1].pos||p[i].pos==p[0].pos) continue;
                x1 += 2 * dis(p[i].x,p[i].y,tx,ty);
            }
            x2+=dis(ax,ay,p[1].x,p[1].y)+dis(p[1].x,p[1].y,tx,ty);

            x2+=dis(bx,by,q[0].x,q[0].y)+dis(q[0].x,q[0].y,tx,ty);
//            cout<<"^^^"<<x2<<" "<<q[0].pos<<endl;

            for(int i=0; i<n ;i++)
            {
                if(p[i].pos == q[0].pos ||p[i].pos==p[1].pos) continue;
                x2 += 2 * dis(p[i].x,p[i].y,tx,ty);
//                cout<<"~~~~"<<p[i].pos<<endl;
            }
//            cout<<x1<<" "<<x2<<endl;
            sum=min(x1,x2);
        }
            printf("%lf\n",sum);
    }
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
#define db double
#define inf 1e18+5
const int N=1e6+5;
db ax,ay,bx,by,tx,ty;
db dis(db x0,db y0,db x1,db y1)
{
    return  sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
}
db a[N],b[N],c[N];
int main()
{
    int n;
    db px,py;
    scanf("%lf%lf",&ax,&ay);
    scanf("%lf%lf%lf%lf",&bx,&by,&tx,&ty);
    scanf("%d",&n);
    db sum=0,ans=0;
    for(int i=1; i<=n ; i++)
    {
        scanf("%lf%lf",&px,&py);
        db v = dis(px,py,tx,ty);
        a[i]=dis(bx,by,px,py)-v;
        b[i]=dis(ax,ay,px,py)-v;
        c[i]=a[i];
        ans += 2*v;
    }
    sum=c[1]+ans;
    a[0]=inf;
    c[n+1]=inf;
    for(int i=1; i<=n ; i++)
        a[i]=min(a[i],a[i-1]);
    for(int i=n; i>=1 ; i--)
    {
        c[i]=min(c[i+1],c[i]);
    }
    for(int i=1; i<=n ; i++)
        sum=min(sum,ans+b[i]+min(0.0,min(a[i-1],c[i+1])));
    printf("%lf\n",sum);

    return 0;
}
/*
1 0 0 1 0 0
1
1 1

*/


#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
#define db double
#define inf 1e19
const int N=1e6+5;
db ax,ay,bx,by,tx,ty;
db dis(db x0,db y0,db x1,db y1)
{
    return  sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
}
db a[N],b[N],c[N];
int main()
{
    int n;
    db px,py;
    while(scanf("%lf%lf",&ax,&ay)!=EOF)
    {
        scanf("%lf%lf%lf%lf",&bx,&by,&tx,&ty);
        scanf("%d",&n);
        db sum=0,ans=0;
        for(int i=1; i<=n ;i++)
        {
            scanf("%lf%lf",&px,&py);
            db v = dis(px,py,tx,ty);
            a[i]=dis(bx,by,px,py)-v;
            b[i]=dis(ax,ay,px,py)-v;
            c[i]=a[i];
            ans += 2*v;
        }
        sum=c[1]+ans;
        a[0]=inf;
        c[n+1]=inf;
        for(int i=1; i<=n ;i++)
            a[i]=min(a[i],a[i-1]);
        for(int i=n; i>=1 ;i--)
        {
            c[i]=min(c[i+1],c[i]);
        }
        for(int i=1; i<=n ;i++)
            sum=min(sum,ans+b[i]+min(0.0,min(a[i-1],c[i+1])));
        printf("%lf\n",sum);
    }
    return 0;
}
/*
1 0 0 1 0 0
1
1 1

*/


#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
const int N=1e5+5;
struct point
{
    double z;
    int pos;
}a[N],b[N];;
//p[N],q[N]
double ax,ay,bx,by,tx,ty;
double dis(double x0,double y0,double x1,double y1)
{
    return  sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
}
double abs(double x)
{
    return x>=0?x:-x;
}
double cmp(point aa,point bb)
{
    return aa.z<bb.z;
}
int main()
{
    int n;
    double px,py;
    while(scanf("%lf%lf",&ax,&ay)!=EOF)
    {
        scanf("%lf%lf%lf%lf",&bx,&by,&tx,&ty);
        scanf("%d",&n);
        double sum=0;
        for(int i=0; i<n ;i++)
        {
            scanf("%lf%lf",&px,&py);
            double v = dis(px,py,tx,ty);
            a[i].z=dis(ax,ay,px,py)- v;
            b[i].z=dis(bx,by,px,py)- v;
            a[i].pos=i;
            b[i].pos=i;
            sum += 2*v;
        }
        sort(a,a+n,cmp);
        sort(b,b+n,cmp);
        if(n==1)
        {
            sum=sum+min(a[0].z,b[0].z);
        }
//        else if(a[0].pos!=b[0].pos)
//        {
//            sum=sum+min(a[0].z,0.0)+min(b[0].z,0.0);
//        }
        else
        {
            sum = sum+a[0].z;
            sum=min(sum,sum+min(a[0].z+min(b[1].z,0.0),b[0].z+min(a[1].z,0.0)));
        }
        printf("%.12lf\n",sum);
    }
    return 0;
}
/*
1 0 0 1 0 0
1
1 1

100 0 0 100 0 0
2
0 1
1 0

*/


#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
const int N=1e5+5;
struct point
{
    double x,y;
    int pos;
}p[N],q[N];
double ax,ay,bx,by,tx,ty;
int cmpA(point A,point B)
{
    double a1=sqrt((A.x-tx)*(A.x-tx)+(A.y-ty)*(A.y-ty));
    double b1=sqrt((A.x-ax)*(A.x-ax)+(A.y-ay)*(A.y-ay));
    double a2=sqrt((B.x-tx)*(B.x-tx)+(B.y-ty)*(B.y-ty));
    double b2=sqrt((B.x-ax)*(B.x-ax)+(B.y-ay)*(B.y-ay));
    return a1-b1>a2-b2;
}
int cmpB(point A,point B)
{
    double a1=sqrt((A.x-tx)*(A.x-tx)+(A.y-ty)*(A.y-ty));
    double b1=sqrt((A.x-bx)*(A.x-bx)+(A.y-by)*(A.y-by));
    double a2=sqrt((B.x-tx)*(B.x-tx)+(B.y-ty)*(B.y-ty));
    double b2=sqrt((B.x-bx)*(B.x-bx)+(B.y-by)*(B.y-by));
    return a1-b1>a2-b2;
}
double dis(double x0,double y0,double x1,double y1)
{
    return  sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
}
int main()
{

    int n;
    while(scanf("%lf%lf",&ax,&ay)!=EOF)
    {
        scanf("%lf%lf%lf%lf",&bx,&by,&tx,&ty);
        scanf("%d",&n);
        for(int i=0; i<n ;i++)
        {
            scanf("%lf%lf",&p[i].x,&p[i].y);
            p[i].pos=i;
            q[i]=p[i];
        }
        sort(p,p+n,cmpA);
        sort(q,q+n,cmpB);
        cout<<p[0].pos<<" "<<q[0].pos<<endl;
        double sum=0;
        if(p[0].pos!=q[0].pos)
        {
            sum+=dis(ax,ay,p[0].x,p[0].y)+dis(p[0].x,p[0].y,tx,ty);
            sum+=dis(bx,by,q[0].x,q[0].y)+dis(q[0].x,q[0].y,tx,ty);
            for(int i=0; i<n ;i++)
            {
                if(p[i].pos == q[0].pos||p[i].pos==p[0].pos) continue;
                sum += 2 * dis(p[i].x,p[i].y,tx,ty);
            }
        }
        else
        {
            double x1=0,x2=0;
            x1+=dis(ax,ay,p[0].x,p[0].y)+dis(p[0].x,p[0].y,tx,ty);
//            cout<<"----"<<x1<<endl;
            x1+=dis(bx,by,q[1].x,q[1].y)+dis(q[1].x,q[1].y,tx,ty);
            for(int i=0; i<n ;i++)
            {
                if(p[i].pos == q[1].pos||p[i].pos==p[0].pos) continue;
                x1 += 2 * dis(p[i].x,p[i].y,tx,ty);
            }
            x2+=dis(ax,ay,p[1].x,p[1].y)+dis(p[1].x,p[1].y,tx,ty);

            x2+=dis(bx,by,q[0].x,q[0].y)+dis(q[0].x,q[0].y,tx,ty);
//            cout<<"^^^"<<x2<<" "<<q[0].pos<<endl;

            for(int i=0; i<n ;i++)
            {
                if(p[i].pos == q[0].pos ||p[i].pos==p[1].pos) continue;
                x2 += 2 * dis(p[i].x,p[i].y,tx,ty);
//                cout<<"~~~~"<<p[i].pos<<endl;
            }
//            cout<<x1<<" "<<x2<<endl;
            sum=min(x1,x2);
        }
            printf("%lf\n",sum);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define orta (bas + son >> 1)
#define sag (k + k + 1)
#define sol (k + k)
#define endl '\n'
#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
#define mp make_pair
#define nd second
#define st first
#define type(x) __typeof(x.begin())

typedef pair < int ,int > pii;

typedef long long ll;

const long long linf = 1e18+5;
const int mod = (int) 1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 1e6 + 5;

int Kx, Ky, Cx, Cy, Tx, Ty, n, x, y;

double pre[N], suff[N], add[N], all;

double dist(int x, int y, int a, int b) { return sqrt((ll) (x - a) * (x - a) + (ll) (y - b) * (y - b)); }

int main() {

	scanf("%d %d %d %d %d %d", &Kx, &Ky, &Cx, &Cy, &Tx, &Ty);

	scanf("%d", &n);

	FOR(i, 1, n) {
		scanf("%d %d", &x, &y);
		double add = dist(Tx, Ty, x, y);
		all += add * 2;
		suff[i] = pre[i] = dist(Cx, Cy, x, y) - add;
		::add[i] = dist(Kx, Ky, x, y) - add;
	}

	pre[0] = suff[n+1] = linf;
	FOR(i, 1, n) { pre[i] = min(pre[i-1], pre[i]); }
	ROF(i, n, 1) { suff[i] = min(suff[i+1], suff[i]); }

	double ans = suff[1] + all;

	FOR(i, 1, n)
		ans = min(ans, all + min(0.0, min(pre[i-1], suff[i+1])) + add[i]);

	printf("%.12lf\n", ans);

	return 0;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
const int N=1e5+5;
struct point
{
    double x,y;
    int pos;
}p[N],q[N];
double ax,ay,bx,by,tx,ty;
int cmpA(point A,point B)
{
    double a1=sqrt((A.x-tx)*(A.x-tx)+(A.y-ty)*(A.y-ty));
    double b1=sqrt((A.x-ax)*(A.x-ax)+(A.y-ay)*(A.y-ay));
    double a2=sqrt((B.x-tx)*(B.x-tx)+(B.y-ty)*(B.y-ty));
    double b2=sqrt((B.x-ax)*(B.x-ax)+(B.y-ay)*(B.y-ay));
    return a1-b1>a2-b2;
}
int cmpB(point A,point B)
{
    double a1=sqrt((A.x-tx)*(A.x-tx)+(A.y-ty)*(A.y-ty));
    double b1=sqrt((A.x-bx)*(A.x-bx)+(A.y-by)*(A.y-by));
    double a2=sqrt((B.x-tx)*(B.x-tx)+(B.y-ty)*(B.y-ty));
    double b2=sqrt((B.x-bx)*(B.x-bx)+(B.y-by)*(B.y-by));
    return a1-b1>a2-b2;
}
double dis(double x0,double y0,double x1,double y1)
{
    return  sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
}
int main()
{

    int n;
    while(scanf("%lf%lf",&ax,&ay)!=EOF)
    {
        scanf("%lf%lf%lf%lf",&bx,&by,&tx,&ty);
        scanf("%d",&n);
        for(int i=0; i<n ;i++)
        {
            scanf("%lf%lf",&p[i].x,&p[i].y);
            p[i].pos=i;
            q[i]=p[i];
        }
        sort(p,p+n,cmpA);
        sort(q,q+n,cmpB);
//        cout<<p[0].pos<<" "<<q[0].pos<<endl;
        double sum=0;
        if(p[0].pos!=q[0].pos)
        {
            sum+=dis(ax,ay,p[0].x,p[0].y)+dis(p[0].x,p[0].y,tx,ty);
            sum+=dis(bx,by,q[0].x,q[0].y)+dis(q[0].x,q[0].y,tx,ty);
            for(int i=0; i<n ;i++)
            {
                if(p[i].pos == q[0].pos||p[i].pos==p[0].pos) continue;
                sum += 2 * dis(p[i].x,p[i].y,tx,ty);
            }
        }
        else
        {
            double x1=0,x2=0;
            x1+=dis(ax,ay,p[0].x,p[0].y)+dis(p[0].x,p[0].y,tx,ty);
//            cout<<"----"<<x1<<endl;
            if(n>1)
            x1+=dis(bx,by,q[1].x,q[1].y)+dis(q[1].x,q[1].y,tx,ty);
            for(int i=0; i<n ;i++)
            {
                if(p[i].pos == q[1].pos||p[i].pos==p[0].pos) continue;
                x1 += 2 * dis(p[i].x,p[i].y,tx,ty);
            }

            x2+=dis(bx,by,q[0].x,q[0].y)+dis(q[0].x,q[0].y,tx,ty);
            if(n>1)
            x2+=dis(ax,ay,p[1].x,p[1].y)+dis(p[1].x,p[1].y,tx,ty);
//            cout<<"^^^"<<x2<<" "<<q[0].pos<<endl;

            for(int i=0; i<n ;i++)
            {
                if(p[i].pos == q[0].pos ||p[i].pos==p[1].pos) continue;
                x2 += 2 * dis(p[i].x,p[i].y,tx,ty);
//                cout<<"~~~~"<<p[i].pos<<endl;
            }
//            cout<<x1<<" "<<x2<<endl;
            sum=min(x1,x2);
        }
            printf("%lf\n",sum);
    }
    return 0;
}
/*
1 0 0 1 0 0
1
1 1
*/


#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
const int N=1e5+5;
struct point
{
    double z;
    int pos;
}a[N],b[N];;
//p[N],q[N]
double ax,ay,bx,by,tx,ty;
double dis(double x0,double y0,double x1,double y1)
{
    return  sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
}
double abs(double x)
{
    return x>=0?x:-x;
}
double cmp(point aa,point bb)
{
    return aa.z<bb.z;
}
int main()
{
    int n;
    double px,py;
    while(scanf("%lf%lf",&ax,&ay)!=EOF)
    {
        scanf("%lf%lf%lf%lf",&bx,&by,&tx,&ty);
        scanf("%d",&n);
        double sum=0;
        for(int i=0; i<n ;i++)
        {
            scanf("%lf%lf",&px,&py);
            double v = dis(px,py,tx,ty);
            a[i].z=dis(ax,ay,px,py)- v;
            b[i].z=dis(bx,by,px,py)- v;
            a[i].pos=i;
            b[i].pos=i;
            sum += 2*v;
        }
        sort(a,a+n,cmp);
        sort(b,b+n,cmp);
        if(n==1)
        {
            sum=sum+min(a[0].z,b[0].z);
        }
        else if(a[0].pos!=b[0].pos)
        {
            sum=sum+min(a[0].z,0.0)+min(b[0].z,0.0);
        }
        else
        {
            sum+=min(a[0].z+min(b[1].z,0.0),b[0].z+min(a[1].z,0.0));
        }
        printf("%.12lf\n",sum);
    }
    return 0;
}
/*
1 0 0 1 0 0
1
1 1

*/