codeparrot/codecomplex huggingface dataset:
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.awt.Point;
import java.util.Arrays;
import java.util.Scanner;

public class B {
    static int[][] dist;
    static int[] dist1;
    static int [] dp;
    static int [] path;
    static int end,x,y;
    static Point[] a;
    public static int doit(int mask) {
        if(mask==end) return 0;
        if(dp[mask]!=-1) return dp[mask];
        int min=Integer.MAX_VALUE;
        int t;
        int i;
        for(i=0;i<dist.length;i++) 
            if(((1<<i)|mask)!=mask) break;
            t=2*dist1[i]+doit(mask|(1<<i));
            if(t<min) {
                min=t;
                path[mask]=(1<<i);
            }
            
            for(int j=i+1;j<dist.length;j++) {
                if(((1<<j)|mask)==mask) continue;
                t=dist[i][j]+doit(mask|(1<<i)|(1<<j));
                if(t<min) {
                    min=t;
                    path[mask]=(1<<i)|(1<<j);
                }
            }
        
        return dp[mask]=min;
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
         x=sc.nextInt();y=sc.nextInt();
         a=new Point[sc.nextInt()];
        for(int i=0;i<a.length;i++) {
            a[i]=new Point(sc.nextInt(), sc.nextInt());
        }
        end=(1<<a.length)-1;
        dp=new int[1<<a.length];
        Arrays.fill(dp, -1);
        dist=new int[a.length][a.length];
        dist1=new int[a.length];
        for(int i=0;i<a.length;i++) {
            dist1[i]=(a[i].x-x)*(a[i].x-x)+(a[i].y-y)*(a[i].y-y);
            for(int j=i+1;j<a.length;j++) {
                
                dist[i][j]=dist1[i]+
                (a[j].x-a[i].x)*(a[j].x-a[i].x)+(a[j].y-a[i].y)*(a[j].y-a[i].y)+
                (a[j].x-x)*(a[j].x-x)+(a[j].y-y)*(a[j].y-y);
                //System.out.println(dist[i][j]);
            }
        }
        path=new int[dp.length];
        System.out.println(doit(0));
        int e=0;
        int cur=path[e];
        StringBuffer bf=new StringBuffer();
        bf.append(0+" ");
        int count=0;
        for(int i=0;count<a.length;i++) {
            //System.out.println(Integer.toBinaryString(cur)+" "+cur);
            for(int j=0;j<a.length;j++) {
                if(((1<<j)|cur)==cur) {
                    bf.append((j+1)+" "); count++;
                }
            }
            e|=cur;
            cur=path[e];
            bf.append(0+" ");
        }
        System.out.println(bf);
    }
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.io.*;
import java.util.*;
 

public class Main {
		
	public static void main(String[] args) throws java.lang.Exception {
		BufferedReader kek = new BufferedReader(new InputStreamReader(System.in));
		//Scanner skek = new Scanner(System.in);
		PrintWriter outkek = new PrintWriter(System.out);

		String[] input = kek.readLine().split(" ");
		int X0 = Integer.parseInt(input[0]), Y0 = Integer.parseInt(input[1]), N = Integer.parseInt(kek.readLine());
		
		int[] xCoords = new int[N + 1];
		int[] yCoords = new int[N + 1];
		int[][] distances = new int[N + 1][N + 1]; 
		xCoords[N] = X0;
		yCoords[N] = Y0;
		
		for(int i = 0; i < N; i++){
			input = kek.readLine().split(" ");
			xCoords[i] = Integer.parseInt(input[0]);
			yCoords[i] = Integer.parseInt(input[1]);
		}
		
		for(int i = 0; i <= N; i++){
			for(int j = i + 1; j <= N; j++){
				int temp = xCoords[i] - xCoords[j];
				int temp2 = yCoords[i] - yCoords[j];
				distances[i][j] = (temp * temp) + (temp2 * temp2);
			}
		}
		
		int[] aa = new int[1 << N];
		int[] bb = new int[1 << N];
		
		for(int i = 1; i < 1 << N; i++){
			int a = -1;
			for(int j = 0; j < N; j++){
				if((i & 1 << j) > 0){
					a = j;
					break;
				}
			}
			
			int l = i ^ 1 << a;
			int dist = distances[a][N] + distances[a][N];
			aa[i] = aa[l] + dist;
			bb[i] = l;
			
			for(int k = a + 1; k < N; k++){
				if((i & 1 << k) > 0) {
					l = i ^ 1 << a ^ 1 << k;
					dist = distances[a][N] + distances[k][N] + distances[a][k];
					if(aa[l] + dist < aa[i]){
						aa[i] = aa[l] + dist;
						bb[i] = l;
					}
				}
			}
		}
		
		int fin = (1 << N) - 1;
		outkek.println(aa[fin]);
		outkek.print('0');
		while (fin != 0){
			int temp1 = bb[fin];
			int temp2 = fin ^ temp1;
			for(int i = 0; i < N; i++){
				if((temp2 & 1 << i) > 0){
					outkek.print(" " + (i + 1));
				}
			}
			outkek.print(" 0");
			fin = temp1;
		}
		kek.close();
		outkek.close();
	}	
	
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.io.*;
import java.util.*;

import com.sun.swing.internal.plaf.basic.resources.basic;

public class Main {

	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
	
	private void solution() throws IOException {
		int sx = in.nextInt();
		int sy = in.nextInt();
		int n = in.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		for (int i = 0; i < n; ++i) {
			x[i] = in.nextInt();
			y[i] = in.nextInt();
		}
		int[] dp = new int[1 << n];
		int[] prev = new int[1 << n];
		Arrays.fill(dp, Integer.MAX_VALUE / 2);
		dp[0] = 0;
		prev[0] = -1;
		for (int mask = 0; mask < (1 << n); ++mask) {
			if (dp[mask] != Integer.MAX_VALUE / 2) {
				for (int next = 0; next < n; ++next) {
					if (((mask >> next) & 1) == 0) {
						int nmask = mask | (1 << next);
						int val = dp[mask] + 2 * getDist(sx, sy, x[next], y[next]);
						if (dp[nmask] > val) {
							dp[nmask] = val;
							prev[nmask] = mask;
						}
						for (int next2 = next + 1; next2 < n; ++next2) {
							if (((nmask >> next2) & 1) == 0) {
								int nnmask = nmask | (1 << next2);
								int nval = dp[mask] + getDist(sx, sy, x[next], y[next]) 
													+ getDist(x[next], y[next], x[next2], y[next2])
													+ getDist(x[next2], y[next2], sx, sy);
								if (dp[nnmask] > nval) {
									dp[nnmask] = nval;
									prev[nnmask] = mask;
								}
							}
						}
						break;
					}
				}
			}
		}
		List<Integer> res = new ArrayList<Integer>();
		res.add(0);
		int mask = (1 << n) - 1;
		while (mask > 0) {
			for (int i = 0; i < n; ++i) {
				if (((prev[mask] >> i) & 1) == 0 && ((mask >> i) & 1) == 1) {
					res.add(i + 1);
				}
			}
			res.add(0);
			mask = prev[mask];
		}
		Collections.reverse(res);
		out.println(dp[(1 << n) - 1]);
		for (int i = 0; i < res.size(); ++i) {
			if (i != 0) {
				out.print(" ");
			}
			out.print(res.get(i));
		}
		out.println();
		out.flush();
	}

	private int getDist(int x1, int y1, int x2, int y2) {
		return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
	}

	private class Scanner {

		private StringTokenizer tokenizer;
		private BufferedReader reader;

		public Scanner(Reader in) {
			reader = new BufferedReader(in);
			tokenizer = new StringTokenizer("");
		}

		public boolean hasNext() throws IOException {
			while (!tokenizer.hasMoreTokens()) {
				String tmp = reader.readLine();
				if (tmp == null)
					return false;
				tokenizer = new StringTokenizer(tmp);
			}
			return true;
		}

		public String next() throws IOException {
			hasNext();
			return tokenizer.nextToken();
		}

		public String nextLine() throws IOException {
			tokenizer = new StringTokenizer("");
			return reader.readLine();
		}

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

	public static void main(String[] args) throws IOException {
		new Main().solution();
	}
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.io.*;
import java.util.*;

public class Main {
	private void run() throws IOException {
		int cx = in.nextInt();
		int cy = in.nextInt();
		int n = in.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		for (int i = 0; i < n; ++i) {
			x[i] = in.nextInt() - cx;
			y[i] = in.nextInt() - cy;
		}
		int[] dp = new int[1 << n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;
		int[] prev = new int[1 << n];
		for (int mask = 0; mask < (1 << n); ++mask) {
			if (dp[mask] == Integer.MAX_VALUE) {
				continue;
			}
			for (int i = 0; i < n; ++i) {
				if (((mask >> i) & 1) == 0) {
					if (dp[mask | (1 << i)] > dp[mask] + dist(x[i], y[i])) {
						dp[mask | (1 << i)] = dp[mask] + dist(x[i], y[i]);
						prev[mask | (1 << i)] = mask;
					}
					for (int j = i + 1; j < n; ++j) {
						if (((mask >> j) & 1) == 0) {
							if (dp[mask | (1 << i) | (1 << j)] > dp[mask] + dist(x[i], y[i], x[j], y[j])) {
								dp[mask | (1 << i) | (1 << j)] = dp[mask] + dist(x[i], y[i], x[j], y[j]);
								prev[mask | (1 << i) | (1 << j)] = mask;
							}
						}
					}
					break;
				}
			}
		}
		out.println(dp[(1 << n) - 1]);
		int mask = (1 << n) - 1;
		out.print(0);
		while (mask != 0) {
			int p = prev[mask];
			int cur = p ^ mask;
			List<Integer> who = new ArrayList<Integer>();
			for (int i = 0; i < n; ++i) {
				if (((cur >> i) & 1) != 0) {
					who.add(i + 1);
				}
			}
			for (int t : who) {
				out.print(" " + t);
			}
			out.print(" " + 0);
			mask = p;
		}
		out.flush();
	}

	private int dist(int x, int y, int x2, int y2) {
		return x * x + y * y + x2 * x2 + y2 * y2 + (x2 - x) * (x2 - x) + (y2 - y) * (y2 - y);
	}

	private int dist(int x, int y) {
		return 2 * (x * x + y * y);
	}

	private class Scanner {
		private StringTokenizer tokenizer;
		private BufferedReader reader;

		public Scanner(Reader in) {
			reader = new BufferedReader(in);
			tokenizer = new StringTokenizer("");
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public boolean hasNext() throws IOException {
			while (!tokenizer.hasMoreTokens()) {
				String next = reader.readLine();
				if (next == null)
					return false;
				tokenizer = new StringTokenizer(next);
			}
			return true;
		}

		public String next() throws IOException {
			hasNext();
			return tokenizer.nextToken();
		}

		public String nextLine() throws IOException {
			tokenizer = new StringTokenizer("");
			return reader.readLine();
		}

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

	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	Scanner in = new Scanner(new InputStreamReader(System.in));
	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;


public class C {

	public static void main(String[] args) {
		//long t = System.currentTimeMillis();
		new C().run();
		//System.out.println(System.currentTimeMillis() - t);
	}

	private void run() {
		Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int n = sc.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt(); 
		}
		sc.close();
		int[] w = new int[n * n];
		int[] pMask = new int[n * n];
		for (int i = 0; i < n; i++) {
			for (int j = i; j < n; j++) {
				int ind = i * n + j;
				if (i == j) {
					w[ind] = 2 * dist(sx, sy, x[i], y[i]);
					pMask[ind] = 1 << i;
				} else {
					w[ind] = dist(sx, sy, x[i], y[i]) + dist(x[i], y[i], x[j], y[j]) + dist(x[j], y[j], sx, sy);
					pMask[ind] = 1 << i | 1 << j;
				}
			}
		}
		int max = 1 << n;
		int[] p = new int[max];
		int[] dist = new int[max];
		Arrays.fill(dist, Integer.MAX_VALUE / 2);
		dist[0] = 0;
		int[] available = new int[n * n];
		for (int mask = 0; mask < max; mask++) {
			int ac = 0;
			for (int i = 0; i < n; i++) {
				if (((mask >> i) & 1) == 0) {
					available[ac++] = i;
				}
			}
			int s = 0;
			//for (int i = 0; i < ac; i++) {
				for (int j = s; j < ac; j++) {
					int a = available[s];
					int b = available[j];
					int ind = a * n + b;
					int nextMask = mask | pMask[ind];
					int newD = dist[mask] + w[ind];
					if (newD < dist[nextMask]) {
						dist[nextMask] = newD;
						//p[nextMask] = a * n + b;
						p[nextMask] = ind;
					}
				}
			//}
		}
		System.out.println(dist[max - 1]);
		ArrayList<Integer> steps = new ArrayList<Integer>();
		int mask = max - 1;
		while (mask > 0) {
			int msk = p[mask];
			steps.add(msk);
			int a = msk / n;
			int b = msk % n;
			if (a == b) {
				mask ^= 1 << a;
			} else {
				mask ^= 1 << a;
				mask ^= 1 << b;
			}
		}
		System.out.print(0);
		for (int i = steps.size() - 1; i >= 0; i--) {
			int msk = steps.get(i);
			int a = msk / n;
			int b = msk % n;
			if (a == b) {
				System.out.printf(" %d 0", a + 1);
			} else {
				System.out.printf(" %d %d 0", a + 1, b + 1);
			}
		}
		System.out.println();
	}

	private int dist(int x1, int y1, int x2, int y2) {
		return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
	}

}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.util.*;
public class c8 {
    static int n;
    static int[] ds;
    static int[][] g;
public static void main(String[] args)
{
    Scanner input = new Scanner(System.in);
    int x = input.nextInt(), y = input.nextInt();
    n = input.nextInt();
    int[] xs = new int[n], ys = new int[n];
    for(int i = 0; i<n; i++)
    {
        xs[i] = input.nextInt();
        ys[i] = input.nextInt();
    }
    ds = new int[n];
    g = new int[n][n];
    for(int i = 0; i<n; i++)
    {
        ds[i] = (x - xs[i])  *  (x - xs[i]) + (y - ys[i]) * (y - ys[i]);
        for(int j = 0; j<n; j++)
        {
            g[i][j] = (xs[i] - xs[j]) * (xs[i] - xs[j]) + (ys[i] - ys[j]) * (ys[i] - ys[j]);
        }
    }
    int[] dp = new int[1<<n];
    Arrays.fill(dp, 987654321);
    dp[0] = 0;
    for(int i = 0; i<(1<<n); i++)
    {
        if(dp[i] == 987654321) continue;
        for(int a = 0; a<n; a++)
        {
            if((i & (1<<a)) > 0) continue;
            dp[i | (1<<a)] = Math.min(dp[i | (1<<a)], dp[i] + 2*ds[a]);
            for(int b = a+1; b<n; b++)
            {
                if((i & (1<<b)) > 0) continue;
                dp[i | (1<<a) | (1<<b)] = Math.min(dp[i | (1<<a) | (1<<b)], dp[i] + ds[a] + ds[b] + g[a][b]);
            }
            break;
        }
    }
    Stack<Integer> stk = new Stack<Integer>();
    stk.add(0);
    int i = (1<<n) - 1;
    //System.out.println(Arrays.toString(dp));

    trace:
    while(i > 0)
    {
        //System.out.println(i);
        for(int a = 0; a<n; a++)
        {
            if((i & (1<<a)) == 0) continue;
            if( dp[i] == dp[i - (1<<a)] + 2*ds[a])
            {
                stk.add(a+1);
                stk.add(0);
                i -= (1<<a);
                continue trace;
            }
            for(int b = a+1; b<n; b++)
            {
                if((i & (1<<b)) == 0) continue;
                if(dp[i] == dp[i - (1<<a) - (1<<b)] + ds[a] + ds[b] + g[a][b])
                {
                    stk.add(a+1);
                    stk.add(b+1);
                    stk.add(0);
                    i -= (1<<a) + (1<<b);
                    continue trace;
                }
            }
            //break;
        }
    }
    System.out.println(dp[(1<<n) - 1]);
    while(!stk.isEmpty()) System.out.print(stk.pop()+" ");
}
}
// Problem: 8_C. Looking for Order
// Time complexity: np

import static java.util.Arrays.*;
import static java.lang.Math.*;
import java.util.*;
import java.io.*;

public class Main implements Runnable
{
	public static void main(String [] args) throws IOException
	{
		new Thread(null, new Main(), "", 1 << 20).start();
	}
	
	String file = "input";
	BufferedReader input;
	PrintWriter out;
	
	public void run() 
	{
		try
		{
			//input = new BufferedReader(new FileReader(file + ".in"));
			input = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new BufferedOutputStream(System.out));
			solve();
			input.close();
			out.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
			System.exit(1);
		}
	}
	int[] x = new int[25];
	int[] y = new int[25];
	int[][] dist = new int[25][25];
	int[] single = new int[25];
	int[] c = new int[25];
	int INF = 1 << 30;
	void solve() throws IOException
	{
		StringTokenizer st = tokens();
		x[0] = nextInt(st);
		y[0] = nextInt(st);
		int n = nextInt();
		for(int i = 1; i <= n; i++)
		{
			st = tokens();
			x[i] = nextInt(st);
			y[i] = nextInt(st);
		}
		for(int i = 1; i <= n; i++)
			single[i] = 2 * ((x[i] - x[0]) * (x[i] - x[0]) + (y[i] - y[0]) * (y[i] - y[0])); 
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= n; j++)
				dist[i][j] = single[i] / 2 + single[j] / 2 + (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
		int[] dp = new int[1 << n];
		int[] prev = new int[1 << n];
		fill(dp, INF);
		dp[0] = 0;
		for(int i = 1; i < 1 << n; i++)
		{
			for(int j = 0; j < n; j++)
			{
				if((i >> j & 1) != 0)
				{
					if(dp[i] > dp[i ^ (1 << j)] + single[j + 1])
					{
						dp[i] = dp[i ^ (1 << j)] + single[j + 1];
						prev[i] = j + 1;
					}
			
					for(int k = j + 1; k < n; k++)
						if((i >> k & 1) != 0)
						{
							if(dp[i] > dp[i ^ (1 << j) ^ (1 << k)] + dist[j + 1][k + 1])
							{
								dp[i] = dp[i ^ (1 << j) ^ (1 << k)] + dist[j + 1][k + 1];
								prev[i] = (j + 1) * 100 + (k + 1);
							}
						}
					break;
				}
			}
		}
		out.println(dp[(1 << n) - 1]);
		out.print("0 ");
		int mask = (1 << n) - 1;
		while(mask > 0)
		{
			int s = prev[mask];
			int x = s / 100;
			int y = s % 100;
			if(x == 0)
			{
				out.print(y + " " + 0 + " ");
				mask -= 1 << (y - 1);
			}
			else
			{
				out.print(x + " " + y + " " + 0 + " ");
				mask -= 1 << (y - 1);
				mask -= 1 << (x - 1);
			}
		}
	}

	StringTokenizer tokens() throws IOException
	{
		return new StringTokenizer(input.readLine());
	}
	
	String next(StringTokenizer st)
	{
		return st.nextToken();
	}
	
	int nextInt() throws IOException
	{
		return Integer.parseInt(input.readLine());
	}
	
	int nextInt(StringTokenizer st)
	{
		return Integer.parseInt(st.nextToken());
	}
	
	double nextDouble() throws IOException
	{
		return Double.parseDouble(input.readLine());
	}
	
	double nextDouble(StringTokenizer st)
	{
		return Double.parseDouble(st.nextToken());
	}
	
	void print(Object... o)
	{
		out.println(deepToString(o));
	}
}
// Problem: 8_C. Looking for Order
// Time complexity: np

import java.io.*;
import java.util.*;

public class LookingForOrder
{
	public Scanner in = new Scanner(System.in);
	public PrintStream out = System.out;

	public int[] go;
	public int[][] cost;
	
	public int [] sol;
	public Pair[] how;
	public int n, lim;
	
	public Pair bag;
	public Pair[] obj;
	
	public void main()
	{		
		bag = new Pair(in.nextInt(), in.nextInt());
		
		n = in.nextInt();
		obj = new Pair[n];
		for(int i=0;i<n;++i) obj[i] = new Pair(in.nextInt(), in.nextInt());
		
		go = new int[n];
		cost = new int[n][n];
		for(int i=0;i<n;++i)
		{
			go[i] = squDist(bag, obj[i]);
			for(int j=0;j<n;++j) cost[i][j] = squDist(obj[i], obj[j]);
		}
		
		lim = (1<<n);
		
		sol = new int[lim];
		Arrays.fill(sol, -1);
		how = new Pair[lim];
		
		out.println(solve(lim-1));
		
		Pair T;
		int set = lim-1;
		
		out.print("0");
		while(set > 0)
		{
			solve(set);
			T = how[set];
			out.print(" "+(T.x+1));
			set = off(T.x, set);
			if(T.y >= 0) 
			{
				out.print(" " + (T.y+1));
				set = off(T.y, set);
			}
			out.print(" 0");
		}
		out.println();
	}//end public void main()

	public int oo = 987654321;
	
	public boolean in(int x, int set) { return ((1<<x) & set) != 0; }
	//Turn on bit x
	public int on(int x, int set) { return (set | (1<<x)); }
	//Turn off bit x
	public int off(int x, int set) { return (set ^ (set & (1<<x)) ); }
    
	
	public int solve(int set)
	{
		if(sol[set] >= 0) return sol[set];
		
		int ret;
		if(set == 0) ret = 0;
		else
		{
			ret = oo;
			
			int x, y, sub, c;
			for(x=0;x<n;++x) if(in(x, set)) break;
			
			sub = off(x, set);
			c =  go[x]+go[x]+solve(sub);
			
			if(c < ret)
			{
				how[set] = new Pair(x, -1);
				ret = c;
			}
			
			for(y=x+1;y<n;++y) if(in(y, set))
			{
				c = go[x]+cost[x][y]+go[y] + solve(off(y, sub));
				if(c < ret)
				{
					ret = c;
					how[set] = new Pair(x, y);
				}
			}
		}
		
		return sol[set] = ret;
	}
	
	public int squDist(int ax, int ay, int bx, int by)
	{
		int dx, dy;
		dx = ax - bx; 
		dy = ay - by;
		return dx*dx + dy*dy;
	}
	
	public int squDist(Pair p, Pair q)
	{
		return squDist(p.x, p.y, q.x, q.y);
	}
	
	//int pair
	private class Pair implements Comparable<Pair>
	{
		public int x, y;
		public Pair(int xx, int yy) { x = xx; y = yy; }

		public int compareTo(Pair u)
		{
			if(x!=u.x) return x-u.x;
			return y-u.y;
		}

		public String toString() { return "(" + x + "," + y + ")"; }
	}	
	
	public static void main(String[] args)
	{
		(new LookingForOrder()).main();
	}
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class LookingForOrder {
	static int[][] pos;
	static int[] dp;
	static int[] nextstate;
	static int[][] dist;
	static int r;
	static int v;

	static void print(int mask) {
		if (mask < v) {
			int c = 0;
			int x = mask ^ nextstate[mask];
			for (int i = 0; i < dist.length - 1; i++) {
				if((x & (1<<i))>0) {
					System.out.print(i+1 + " ");
					c++;
				}
			}
			System.out.print("0 ");
			print(nextstate[mask]);
		}
	}

	static int distace(int x1, int x2, int y1, int y2) {
		return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
	}

	static int solve(int mask) {
		if (mask == v) {
			nextstate[mask] = r;

			return 0;
		}
		if (nextstate[mask] != 0) {
			return dp[mask];
		}

		dp[mask] = (int) 1e9;
		for (int i = 1; i < pos.length; i++) {
			int u = (1 << (i - 1));
			int z = mask | u;
			if ((mask & u) == 0) {
				int x = 2 * dist[i][0] + solve(z);
				if (dp[mask] > x) {
					dp[mask] = x;
					nextstate[mask] = z;
				}

				for (int j = 1; j < pos.length; j++) {
					int m = (1 << j - 1);
					int y = z | m;
					if ((z & m) == 0) {
						x = dist[i][0] + solve(y) + dist[i][j] + dist[j][0];

						if (dp[mask] > x) {
							dp[mask] = x;
							nextstate[mask]= y;
						}

					}
				}
				break;
			}
		}
		return dp[mask];
	}

	public static void main(String[] args) {
		InputReader0 in = new InputReader0(System.in);
		int x = in.nextInt(), y = in.nextInt();
		int n = in.nextInt();
		r = 1 << n;
		v = r - 1;
		dp = new int[r];
		nextstate = new int[r];
		pos = new int[n + 1][2];
		pos[0][0] = x;
		pos[0][1] = y;
		for (int i = 1; i < pos.length; i++) {
			pos[i][0] = in.nextInt();
			pos[i][1] = in.nextInt();
		}
		dist = new int[n + 1][n + 1];
		for (int i = 0; i < dist.length; i++) {
			for (int j = i + 1; j < dist.length; j++) {
				dist[i][j] = dist[j][i] = distace(pos[i][0], pos[j][0], pos[i][1], pos[j][1]);
			}
		}

		System.out.println(solve(0));
		System.out.print("0 ");
		print(0);
	}

}

class InputReader0 {
	BufferedReader reader;
	StringTokenizer tokenizer;

	public InputReader0(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream));
		tokenizer = null;
	}

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

	public long nextLong() {
		return Long.parseLong(next());
	}

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

}