codeparrot/codecomplex huggingface dataset:
// Problem: 8_C. Looking for Order
// Time complexity: np

import java.util.*;


public class C
{
   public static void main(String[] args)
   {
      new C(new Scanner(System.in));
   }

   vect[] vs;
   int N;
   int oo = 987654321;

   ArrayList<choice> cs;
   choice[][] cg;

   int MF;

   int[] memo;
   int[] next;

   int go(int m)
   {
      if (m == MF)
         return 0;
      if (memo[m] != -1)
         return memo[m];

      // Try a new place
      int res = oo;
      int nxt = -1;

      int i=0;
      for (i=0; i<N; i++)
      {
         if (((1<<i)&m) == 0)
            break;
      }

      for (int j=0; j<N; j++)
      {
         choice cc = cg[i][j];
         if ((m&cc.m) > 0)
            continue;

         int r2 = cc.cost+go(m|cc.m);
         if (r2 < res)
         {
            res = r2;
            nxt = cc.index;
         }
      }

      memo[m] = res;
      next[m] = nxt;
      return res;
   }

   public C(Scanner in)
   {
      vect vt = new vect(in.nextInt(), in.nextInt());
      N = in.nextInt();
      vs = new vect[N+1];
      vs[N] = vt;
      for (int i=0; i<N; i++)
         vs[i] = new vect(in.nextInt(), in.nextInt());
  
      // Precompute all choices and masks
      cs = new ArrayList<choice>();
      cg = new choice[N][N];
      for (int i=0; i<N; i++)
      {
         choice cc = new choice(cs.size(), 2*vs[i].dist(vt), 1<<i);
         cc.add(i);
         cs.add(cc);
         cg[i][i] = cc;
      }

      for (int i=0; i<N; i++)
      {
         for (int j=i+1; j<N; j++)
         {
            int dist = vs[i].dist(vt);
            dist += vs[i].dist(vs[j]);
            dist += vs[j].dist(vt);
            choice cc = new choice(cs.size(), dist, (1<<i)|(1<<j));
            cc.add(i); cc.add(j);
            cs.add(cc);
            cg[i][j] = cc;
            cg[j][i] = cc;
         }
      }

      MF = (1<<N)-1;
      next = new int[MF+1];
      memo = new int[MF+1];

      Arrays.fill(next, -1);
      Arrays.fill(memo, -1);

      int res = go(0);
      System.out.println(res);

      int m = 0;
      StringBuilder sb = new StringBuilder();
      while (m != -1)
      {
         //System.out.println(Integer.toBinaryString(m));
         sb.append(0);
         sb.append(' ');
         int i = next[m];
         if (i == -1)
            break;
         choice cc = cs.get(i);
         for (int j : cc.iv)
         {
            sb.append(f(j));
            sb.append(' ');
         }
         m = m|cc.m;
      }
      System.out.println(sb.toString().trim());
   }

   int f(int i)
   {
      if (i == N)
         return 0;
      return i+1;
   }
}


class choice
{
   int cost;
   int m;
   int index;
   ArrayList<Integer> iv;

   public choice(int ii, int c, int mm)
   {
      index = ii;
      cost = c;
      m = mm;
      iv = new ArrayList<Integer>(2);
   }

   void add(int i)
   {
      iv.add(i);
   }
}


class vect
{
   int x, y;

   public vect(int i, int j)
   {
      x=i; y=j;
   }

   int dist(vect rhs)
   {
      int xx = x-rhs.x;
      int yy = y-rhs.y;
      return xx*xx+yy*yy;
   }
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.io.*;

public class CF8C {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		int si = s.indexOf(' ', 0);
		int x = Integer.parseInt(s.substring(0, si));
		int y = Integer.parseInt(s.substring(si + 1));
		int n = Integer.parseInt(br.readLine());
		int[] xx = new int[n + 1];
		int[] yy = new int[n + 1];
		for (int i = 0; i < n; i++) {
			s = br.readLine();
			si = s.indexOf(' ', 0);
			xx[i] = Integer.parseInt(s.substring(0, si));
			yy[i] = Integer.parseInt(s.substring(si + 1));
		}
		xx[n] = x;
		yy[n] = y;
		int[][] dd = new int[n + 1][n + 1];
		for (int i = 0; i <= n; i++)
			for (int j = i + 1; j <= n; j++) {
				int dx = xx[i] - xx[j];
				int dy = yy[i] - yy[j];
				dd[i][j] = dx * dx + dy * dy;
			}
		int[] aa = new int[1 << n];
		int[] bb = new int[1 << n];
		for (int k = 1; k < 1 << n; k++) {
			int a = -1;
			for (int b = 0; b < n; b++)
				if ((k & 1 << b) > 0) {
					a = b;
					break;
				}
			int l = k ^ 1 << a;
			int d = dd[a][n] + dd[a][n];
			aa[k] = aa[l] + d;
			bb[k] = l;
			for (int b = a + 1; b < n; b++)
				if ((k & 1 << b) > 0) {
					l = k ^ 1 << a ^ 1 << b;
					d = dd[a][n] + dd[b][n] + dd[a][b];
					if (aa[l] + d < aa[k]) {
						aa[k] = aa[l] + d;
						bb[k] = l;
					}
				}
		}
		int k = (1 << n) - 1;
		System.out.println(aa[k]);
		StringBuilder sb = new StringBuilder();
		sb.append(0);
		while (k != 0) {
			int l = bb[k];
			int m = k ^ l;
			for (int b = 0; b < n; b++)
				if ((m & 1 << b) > 0)
					sb.append(' ').append(b + 1);
			sb.append(' ').append(0);
			k = l;
		}
		System.out.println(sb);
	}
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.util.Scanner;

public class Problem_8C {
  private static int dis(int x1, int y1, int x2, int y2) {
    return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int ox = sc.nextInt();
    int oy = sc.nextInt();
    int n = sc.nextInt();
    int[] ix = new int[n];
    int[] iy = new int[n];
    int[] single = new int[n];
    int[][] pair = new int[n][n];
    for (int i = 0; i < n; i++) {
      ix[i] = sc.nextInt();
      iy[i] = sc.nextInt();
      single[i] = dis(ox, oy, ix[i], iy[i]) * 2;
      for (int j = 0; j < i; j++) {
        pair[i][j] = pair[j][i] = dis(ix[i], iy[i], ix[j], iy[j]) + (single[i] + single[j]) / 2;
      }
    }
    int[] min = new int[1 << n];
    int[] pre = new int[1 << n];
    for (int set = 1; set < 1 << n; set++) {
      int i;
      for (i = 0; i < n; i++) {
        if ((set & (1 << i)) != 0) {
          break;
        }
      }
      min[set] = min[set ^ (1 << i)] + single[i];
      pre[set] = set ^ (1 << i);
      for (int j = 0; j < n; j++) {
        if ((set & (1 << j)) == 0) {
          continue;
        }
        if (min[set] > min[set ^ (1 << i) ^ (1 << j)] + pair[i][j]) {
          min[set] = min[set ^ (1 << i) ^ (1 << j)] + pair[i][j];
          pre[set] = set ^ (1 << i) ^ (1 << j);
        }
      }
    }
    System.out.println(min[(1 << n) - 1]);
    for (int set = (1 << n) - 1; set != 0; set = pre[set]) {
      System.out.print("0 ");
      for (int i = 0; i < n; i++) {
        if (((set ^ pre[set]) & (1 << i)) != 0) {
          System.out.print((i + 1) + " ");
        }
      }
    }
    System.out.println("0");
    sc.close();
  }
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class LookingForOrder {

	static int[] dp = new int[(int) (1 << 24)];
	static int[][] points;
	static int[] sol = new int[1<<24];
	static int sx = 0, sy = 0;

	public static void main(String[] args) {

		sx = in.nextInt();
		sy = in.nextInt();
		Arrays.fill(dp, -2);

		int n = in.nextInt();
		points = new int[n][3];

		for (int i = 0; i < n; i++) {
			points[i][0] = in.nextInt();
			points[i][1] = in.nextInt();
			points[i][2] = (sx - points[i][0]) * (sx - points[i][0]) + (sy - points[i][1]) * (sy - points[i][1]);
		}

		//System.out.println("ANS");
		System.out.println(solve(0));
		
		int mask=0;
		while(true){
			System.out.print(0+" ");
			if (mask==(1<<n)-1) break;
			int x = sol[mask];
			int count=0;
			for(int i=0; i<n; i++){
				if ((x&(1<<i))!=0) {
					count++;
					System.out.print((i+1)+" ");
					mask|=(1<<i);
				}
				if (count==2) break;
				
			}
		}
		System.out.println();

	}

	public static int solve(int mask) {
		
		if (dp[mask]!=-2) return dp[mask];
		
		int n = points.length;
		if (mask == ((1 << n)-1)) {
			return dp[mask]=0;
		}

		int here = -1;
		for (int i = 0; i < n; i++) {
			if ((mask & (1<<i)) == 0) {
				here = i;
				break;
			}
		}
		

		int ans = 2*points[here][2]+solve(mask | (1 << here));
		sol[mask] = 1<<here;

		int x1 = points[here][0];
		int y1 = points[here][1];

		for (int i = here + 1; i < n; i++) {
			if ((mask & (1 << i)) == 0) {
				int x2 = points[i][0];
				int y2 = points[i][1];
				int p = mask|(1<<here);
				p = p|(1<<i);
				if (ans>points[here][2] + points[i][2] + (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)
						+ solve(p)){
					ans=points[here][2] + points[i][2] + (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)
							+ solve(p);
					sol[mask]=(1<<here)|(1<<i);
				}
			}
		}

		return dp[mask]=ans;
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}

	static MyScanner in = new MyScanner();

}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.util.Scanner;

public class C {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int xs = sc.nextInt();
		int ys = sc.nextInt();
		int n = sc.nextInt();
		int[]x = new int[n], y = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
		int[]single = new int[n];
		int[][]pair = new int[n][n];
		for (int i = 0; i < n; i++) {
			single[i] = 2*((x[i]-xs)*(x[i]-xs)+(y[i]-ys)*(y[i]-ys));
		}
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				pair[i][j] = (x[i]-xs)*(x[i]-xs)+(y[i]-ys)*(y[i]-ys)+(x[j]-xs)*(x[j]-xs)+(y[j]-ys)*(y[j]-ys)+(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
			}
		}
		int[]best = new int[1 << n], prev = new int[1 << n];
		for (int mask = 1; mask < (1 << n); mask++) {
			int i = 0;
			while ((mask & (1 << i))==0)
				i++;
			best[mask] = best[mask ^ (1 << i)]+single[i];
			prev[mask] = i+1;
			for (int j = i+1; j < n; j++) {
				if ((mask & (1 << j)) != 0) {
					int temp = best[mask ^ (1 << i) ^ (1 << j)]+pair[i][j];
					if (temp < best[mask]) {
						best[mask] = temp;
						prev[mask] = (i+1)*100+(j+1);
					}
				}
			}
		}
		System.out.println(best[(1 << n) - 1]);
		System.out.print("0 ");
		int cur = (1 << n) - 1;
		while (cur > 0) {
			int a = prev[cur]  % 100;
			int b = prev[cur] / 100;
			if (a > 0) {
				System.out.print(a+" ");
				cur ^= 1 << (a-1);
			}
			if (b > 0) {
				System.out.print(b+" ");
				cur ^= 1 << (b-1);
			}
			System.out.print(0+" ");
		}
	}
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.util.*;
import static java.lang.Math.*;

public class Main {
	
	static int hx, hy;
	static int[] X, Y;
	static int N;
	static int[] DP;
	
	static int pw(int a) {
		return a * a;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		hx = sc.nextInt();
		hy = sc.nextInt();
		N = sc.nextInt();
		X = new int[N];
		Y = new int[N];
		for (int i = 0; i < N; ++i) {
			X[i] = sc.nextInt();
			Y[i] = sc.nextInt();
		}
		DP = new int[1 << N];
		Arrays.fill(DP, -1);
		int ans = recur(0);
		ArrayList<Integer> aa = new ArrayList<Integer>();
		int U = 0;
		aa.add(0);
		int test = 0;
		while (U != (1 << N) - 1) {
			int a = 0;
			for (int i = 0; i < N; ++i) {
				if (((1 << i) & U) == 0) {
					a = i;
					break;
				}
			}
			int ans2 = recur(U | (1 << a)) + 2 * (pw(X[a] - hx) + pw(Y[a] - hy));
			int temp = 2 * (pw(X[a] - hx) + pw(Y[a] - hy));
			int best = -1;
			for (int i = a + 1; i < N; ++i) {
				if (((1 << i) & U) == 0) {
					int ans3 = recur(U|(1<<a)|(1<<i)) + pw(X[a]-X[i])+pw(Y[a]-Y[i]) + pw(X[a]-hx)+pw(Y[a]-hy) + pw(X[i]-hx)+pw(Y[i]-hy);
					if (ans3 < ans2) {
						ans2 = ans3;
						ans2 = ans3;
						best = i;
						temp = pw(X[a]-X[i])+pw(Y[a]-Y[i]) + pw(X[a]-hx)+pw(Y[a]-hy) + pw(X[i]-hx)+pw(Y[i]-hy);
					}
				}
			}
			if (best == -1) {
				aa.add(a + 1);
				aa.add(0);
				U |= (1 << a);
			} else {
				aa.add(a + 1);
				aa.add(best + 1);
				aa.add(0);
				U |= (1 << a) | (1 << best);
			}
		}
		System.out.println(ans);
		for (int i = 0; i < aa.size(); ++i) {
			System.out.print(aa.get(i) + " ");
		}
	}
	
	private static int recur(int U) {
		if (DP[U] != -1) {
			return DP[U];
		}
		if (U == (1 << N) - 1) {
			return 0;
		}
		int a = 0;
		for (int i = 0; i < N; ++i) {
			if (((1 << i) & U) == 0) {
				a = i;
				break;
			}
		}
		int ans = recur(U | (1 << a)) + 2 * (pw(X[a] - hx) + pw(Y[a] - hy));
		for (int i = a + 1; i < N; ++i) {
			if (((1 << i) & U) == 0) {
				ans = min(ans, recur(U|(1<<a)|(1<<i)) + pw(X[a]-X[i])+pw(Y[a]-Y[i]) + pw(X[a]-hx)+pw(Y[a]-hy) + pw(X[i]-hx)+pw(Y[i]-hy));
			}
		}
		DP[U] = ans;
		return ans;
	}
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;


public class cf8c {
  static int n;
  static int[] bb;
  static int[] memo;
  static int[][] cost;
  static FastIO in = new FastIO(), out = in;
  public static void main(String[] args) {
    vec2 cen = new vec2(in.nextInt(),in.nextInt());
    n = in.nextInt();
    cost = new int[n][n];
    vec2[] v = new vec2[n];
    for(int i=0; i<n; i++)
      v[i] = new vec2(in.nextInt(),in.nextInt());
    for(int i=0; i<n; i++)
      for(int j=0; j<n; j++)
        cost[i][j] = v[i].dist(cen) + v[i].dist(v[j]) + v[j].dist(cen);
    memo = new int[1<<n];
    bb = new int[1<<n];
    Arrays.fill(memo,-1);
    out.println(go(0));
    build(0);
    out.close();
  }
  static void build(int mask) {
    if(mask == (1<<n)-1) {
      out.println(0);
      return;
    }
    int first = 0;
    while((mask & (1<<first)) != 0) first++;
    int second = bb[mask];
    out.print("0 " + (first+1) + " ");
    if(second != first)
      out.print((second+1)+" ");
    build(mask|(1<<first)|(1<<second));
  }
  static int go(int mask) {
    if(mask == (1<<n)-1) return 0;
    if(memo[mask] != -1) return memo[mask];
    int first = 0;
    int ans = Integer.MAX_VALUE;
    while((mask & (1<<first)) != 0) first++;
    for(int second = first; second < n; second++) {
      if((mask & (1<<second)) != 0) continue;
      int tans = cost[first][second] + go(mask|(1<<first)|(1<<second));
      if(tans < ans) {
        ans = tans;
        bb[mask] = second;
      }
    }
    return memo[mask] = ans;
  }
  static class vec2 {
    int x, y;
    vec2(int a, int b) {
      x = a; y = b;
    }
    vec2 sub(vec2 v) {
      return new vec2(x-v.x,y-v.y);
    }
    int dist(vec2 v) {
      return sub(v).mag2();
    }
    int mag2() {
      return x*x+y*y;
    }
  }
  static class FastIO extends PrintWriter {
    BufferedReader br;
    StringTokenizer st;
    
    public FastIO() {
      this(System.in,System.out);
    }
    public FastIO(InputStream in, OutputStream out) {
      super(new BufferedWriter(new OutputStreamWriter(out)));
      br = new BufferedReader(new InputStreamReader(in));
      scanLine();
    }
    public void scanLine() {
      try {
        st = new StringTokenizer(br.readLine().trim());
      } catch(Exception e) {
        throw new RuntimeException(e.getMessage());
      }
    }
    public int numTokens() {
      if(!st.hasMoreTokens()) {
        scanLine();
        return numTokens();
      }
      return st.countTokens();
    }
    public String next() {
      if(!st.hasMoreTokens()) {
        scanLine();
        return next();
      }
      return st.nextToken();
    }
    public double nextDouble() {
      return Double.parseDouble(next());
    }
    public long nextLong() {
      return Long.parseLong(next());
    }
    public int nextInt() {
      return Integer.parseInt(next());
    }
  }
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class LookingOrder {
    public static void main(String[] args) throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] line=in.readLine().split("\\s+");
        int xs= Integer.parseInt(line[0]);
        int ys= Integer.parseInt(line[1]);
        int n=Integer.parseInt(in.readLine());
        int []x=new int[n];
        int []y=new int[n];
        for(int i=0;i<n;++i){
            line=in.readLine().split("\\s+");
            x[i]= Integer.parseInt(line[0]);
            y[i]= Integer.parseInt(line[1]);
        }
        int maxBitmap=1<<n;
        long[] dis=new long[maxBitmap];
        int[] last=new int[maxBitmap];
        dis[0]=0;
        int ci=0;
        int[][] dismap=new int[n][n];
        
        for(int i=0;i<n;++i){
            for(int j=0;j<=i;++j){
                int delx,dely;
                if(i==j){
                    delx=x[i]-xs;
                    dely=y[i]-ys;
                }else{
                    delx=x[i]-x[j];
                    dely=y[i]-y[j];
                }
                dismap[i][j]=delx*delx+dely*dely;
            }
        }
        
        for(int i=1;i<maxBitmap;++i){
            if((i&(1<<ci))==0)
                ++ci;
            int i2=i-(1<<ci);
            
            long min=dis[i2]+2*dismap[ci][ci];
            last[i]=ci;
            for(int j=0;j<ci;++j){
                if((i&(1<<j))!=0){
                    long m=dis[i2-(1<<j)]+dismap[ci][ci]+dismap[j][j]+dismap[ci][j];
                    if(m<min){
                        min=m;
                        last[i]=j;
                    }
                }
            }
            dis[i]=min;
        }
        
        out.write(""+dis[maxBitmap-1]);
        out.newLine();
        out.write("0");
        
        int bmap=maxBitmap-1;
        ci=n-1; 
        while(bmap!=0){
            while((bmap&(1<<ci))==0&&ci>=0)--ci;
            int ci2=last[bmap];
            if(ci2!=ci){
                out.write(" "+(ci+1)+" "+(ci2+1)+ " 0");
                bmap-=(1<<ci)+(1<<ci2);
            }else{
                out.write(" "+(ci+1)+" 0");
                bmap-=1<<ci;
            }
        }
        out.close();
    }
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.util.Scanner;


public class Round8_C {

	/**
	 * @param args
	 */
	
	int n ;
	int[] X, Y ;
	
	public Round8_C() {
		info_in() ;
		process() ;
	}
	
	void info_in()
	{
		Scanner input = new Scanner(System.in) ;
		int dx = input.nextInt() ;
		int dy = input.nextInt() ;
		
		n = input.nextInt() ;
		X = new int[n] ;
		Y = new int[n] ;
		
		for( int i=0;i<n;i++) {
			X[i] = input.nextInt() - dx ;
			Y[i] = input.nextInt() - dy ;
		}
	}
	
	int[] d  ;
	int[] trace ;
	
	public static int distance( int x1, int y1, int x2, int y2 )
	{
		return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ;
	}
	
	void process()
	{
		int gh = 1<<n ;
		d = new int[gh] ;
		trace = new int[gh] ;
		
		d[0] = 0 ;
		for( int i=1;i<gh;i++) {
			d[i] = Integer.MAX_VALUE ;
			for( int j=0;j<n;j++)
				if ( (i & (1<<j)) > 0 ) {
					int val = d[i^(1<<j)] + ( distance( X[j], Y[j], 0, 0 ) << 1 ) ;
					if ( val < d[i] ) {
						d[i] = val ;
						trace[i] = j+1 ;
					}
					
					int state = i ^ (1<<j) ;
					for( int p=j+1;p<n;p++)
						if ( (i & (1<<p)) > 0) {
							val = d[state^(1<<p)] + distance( X[j], Y[j], 0, 0 ) + distance( X[j], Y[j], X[p], Y[p] ) + distance( X[p], Y[p], 0, 0 ) ;
							if ( val < d[i] ) {
								d[i] = val ;
								trace[i] = (j+1) * 100 + (p+1) ; 
							}
						}
					break ;
				}
		}
		
		System.out.println( d[gh-1] ) ;
		gh-- ;
		while ( gh > 0 ) {
			int v1 = trace[gh] / 100 - 1 ;
			int v2 = trace[gh] % 100 - 1 ;
			System.out.print(0 + " ") ;
			if ( v1 != -1 ) {
				System.out.print((v1+1) + " " ) ;
				gh -= 1 << v1 ;
			}
			System.out.print( (v2+1) + " " ) ;
			gh -= 1 << v2 ;
		}
		System.out.println(0) ;
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Round8_C() ;
	}

}
// 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.Arrays;
import java.util.StringTokenizer;

public class LookingForOrder {
static int n;
static int []x,y,memo;
static StringBuilder sb;
static int distance(int i,int j)
{
	int dx=x[i]-x[j];
	int dy=y[i]-y[j];
	return dx*dx+dy*dy;
}
public static int dp(int msk)
{
	if(msk==(1<<(n+1))-2)
		return 0;
	if(memo[msk]!=-1)
		return memo[msk];
	int ans=10000000;
	boolean found=false;
	for(int i=1;i<=n && !found;i++)
		
		for(int j=i;j<=n && (msk&1<<i)==0;j++)
			if((msk&1<<j)==0)
			{	
				
				found=true;
				int newM=msk|1<<i;
				newM|=1<<j;
				ans=Math.min(ans, dp(newM)+Math.min(distance(0,i)+distance(i,j)+distance(j,0), distance(0,j)+distance(j,i)+distance(i,0)));
			}
	return memo[msk]=ans;
			
}
public static void print(int msk)
{
	if(msk==(1<<(n+1))-2)
		return ;
	
	for(int i=1;i<=n;i++)
		
		for(int j=i;j<=n && (msk&1<<i)==0;j++)
			if((msk&1<<j)==0)
			{	
				
				int newM=msk|1<<i;
				newM|=1<<j;
				int d1=distance(0,i)+distance(i,j)+distance(j,0);
				int d2=distance(0,j)+distance(j,i)+distance(i,0);
				if(dp(msk)== dp(newM)+Math.min(d1,d2))
				{
					
					if(i==j)
					
						sb.append("0 "+i+" ");
					
					else if(d1<d2)
						sb.append("0 "+i+" "+j+" ");
					else
						sb.append("0 "+j+" "+i+" ");
						
					
					print(newM);
					return ;
				}
			}
	
			
}
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
		int xS=sc.nextInt(),yS=sc.nextInt();
		n=sc.nextInt();
		x=new int [n+1];
		y=new int [n+1];
		x[0]=xS;y[0]=yS;
		for(int i=1;i<=n;i++)
		{	
			x[i]=sc.nextInt();
			y[i]=sc.nextInt();
		
		}	
		memo=new int [1<<(n+1)];
		Arrays.fill(memo,-1);
		sb=new StringBuilder();

		sb.append(dp(0)+"\n");
		print(0);
		sb.append("0");
		System.out.println(sb);
	}
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;
		public Scanner(InputStream s)
		{
			br=new BufferedReader(new InputStreamReader(s));
		}
		public String nextLine() throws IOException
		{
			return br.readLine();
		}
		public String next() throws IOException
		{
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
			
		}
		public double nextDouble() throws IOException
		{
			return Double.parseDouble(next());
		}
		public boolean ready() throws IOException
		{
			return br.ready();
		}
		public long nextLong() throws IOException
		{
			return Long.parseLong(next());
		}
	}
}