codeparrot/codecomplex huggingface dataset:
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.util.*;
import static java.lang.Math.*;

public class C {
	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 = 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)+recur(U|(1<<a)|(1<<i));
					if(ans3 < ans2){
						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);
			}
			test += temp;
		}
//		System.out.println(test);
		if(test != ans)
			throw new RuntimeException();
		System.out.println(ans);
		for(int i = 0; i < aa.size();i++)
			System.out.print(aa.get(i)+(i == aa.size()-1?"":" "));
		System.out.println();
	}
	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,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)+recur(U|(1<<a)|(1<<i)));
			}
		}
		DP[U] = ans;
		return ans;
	}
	static int pw(int a){
		return a*a;
	}
	static int hx,hy;
	static int[] X,Y;
	static int N;
	static int[] DP;
}
// 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 IOException {
        new Main().run();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st = new StringTokenizer("");
    
    int INF = Integer.MAX_VALUE >> 1;
    
    void run() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        
        /* Input */
        int x0 = nextInt();
        int y0 = nextInt();
        int N = nextInt();
        int FULL_MASK = (1 << N) - 1;
        int[] xs = new int [N];
        int[] ys = new int [N];
        for (int i = 0; i < N; i++) {
            xs[i] = nextInt();
            ys[i] = nextInt();
        }
        
        /* Precalc */
        int[][] dist = new int [N][N];
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                dist[i][j] = dist(x0, y0, xs[i], ys[i]) + dist(xs[i], ys[i], xs[j], ys[j]) + dist(xs[j], ys[j], x0, y0);
        
        /* DP */
        int[] dp = new int [1 << N];
        int[] pr = new int [1 << N];
        Arrays.fill(dp, INF);
        dp[0] = 0;
        for (int mask = 0; mask < FULL_MASK; mask++) {
            int i = Integer.numberOfTrailingZeros(~mask); // hack: use first non-zero bit
            int imask = mask | (1 << i);
            for (int j = i; j < N; j++) {
                int jmask = mask | (1 << j);
                if (jmask == mask) continue;
                int ijmask = imask | jmask;
                int nval = dp[mask] + dist[i][j];
                if (dp[ijmask] > nval) {
                    dp[ijmask] = nval;
                    pr[ijmask] = mask;
                }
            }
        }
        
        /* Output */
        out.println(dp[FULL_MASK]);
        out.print("0");
        for (int mask = FULL_MASK; mask != 0; mask = pr[mask]) {
            int diff = mask ^ pr[mask];
            int i = Integer.numberOfTrailingZeros(diff);
            diff &= ~(1 << i);
            int j = Integer.numberOfTrailingZeros(diff);
            if (i != 32) out.print(" " + (i + 1));
            if (j != 32) out.print(" " + (j + 1));
            out.print(" 0");
        }
        out.println();
        out.close();
    }
    
    /*************************************************************** 
     * Utility
     **************************************************************/
    int dist(int x1, int y1, int x2, int y2) {
        return sqr(x2 - x1) + sqr(y2 - y1);
    }

    int sqr(int x) {
        return x * x;
    }

    /*************************************************************** 
     * Input 
     **************************************************************/
    String nextToken() throws IOException {
        while (!st.hasMoreTokens())
            st = new StringTokenizer(in.readLine());
        return st.nextToken();
    }
    
    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
}
// Problem: 8_C. Looking for Order
// Time complexity: np

import java.util.*;
import java.lang.Math.*;

public class Main {
	static Scanner in = new Scanner(System.in);
	static Coor[] p;
	static Coor ori;
	static int n;
	static int dp[];
	static Coor pre[];
	public static void main(String[] args) {
		ori = new Coor(in.nextInt(),in.nextInt());
		n = in.nextInt();
		p = new Coor[n];
		dp = new int[1<<n];
		pre = new Coor[1<<n];
		for (int i = 0;i < n;i++) {
			p[i] = new Coor(in.nextInt(),in.nextInt());
		}
		Arrays.fill(dp,-1);
		dp[0] = 0;
		System.out.println( getdp((1<<n)-1));
		//System.out.printf("%d",0);
		System.out.printf("%d",0);
		trace((1<<n)-1);
		System.out.println();
	}
	static void trace(int mask) {
		if (mask == 0) return;
		if (pre[mask].y == -1) {
			System.out.printf(" %d %d",pre[mask].x+1,0);
			trace( mask - ( 1<< pre[mask].x ) );
		} else {
			System.out.printf(" %d %d %d",pre[mask].x+1,pre[mask].y+1,0);
			trace( mask - ( 1<< pre[mask].x ) - (1<<pre[mask].y));
		}
	}
	static int getdp(int mask) {
		if (dp[mask] != -1) 
			return dp[mask];
		int fr = 0;
		for (int i = 0;i < n;i++) 
			if ( (mask & (1 << i)) != 0 ) {
				fr = i;
				break;
			}
		dp[mask] = getdp( mask - (1 << fr) ) + 2 * p[fr].dist(ori);
		pre[mask] = new Coor(fr,-1);
		for (int i = fr+1;i < n;i++) {
			int to = i;
			if ( (mask & (1 << i)) != 0) {
				int tmp = getdp( mask - (1<<fr) - (1<<i) ) + p[fr].dist(ori) + p[to].dist(ori) + p[fr].dist(p[to]);
				if (tmp < dp[mask]) {
					dp[mask] = tmp;
					pre[mask].y = i;
				}
			}
		}
		return dp[mask];
	}
}

class Coor {
	int x,y;
	Coor(int _x,int _y) {
		x = _x;y = _y;
	}
	int dist(Coor o) {
		return ( (x-o.x) * (x-o.x) + (y-o.y) * (y-o.y) );
	}
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.io.*;
import java.util.*;
public class AMain {
	static int n;
	static int[] best;
	static int[][] dist;
	static int[] home;
	static LinkedList<Integer> ret;
	public static void main(String[] args) throws IOException	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		State curr = new State(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));
		n = Integer.parseInt(br.readLine());
		State[] list = new State[n];
		for(int i = 0; i < n; i++)	{
			st = new StringTokenizer(br.readLine());
			list[i] = new State(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));
		}
		dist = new int[n][n];
		home = new int[n];
		for(int i = 0; i < n; i++)	{
			home[i] = dist(curr, list[i]);
		}
		for(int i = 0; i < n; i++)	{
			dist[i][i] = 2 * home[i];
			for(int j = i+1; j < n; j++)		{
				dist[i][j] = dist(list[i], list[j]) + home[i] + home[j];
			}
		}
		best = new int[1 << (n)];
		Arrays.fill(best, -1);
		best[0] = 0;
		System.out.println(solve(-1 + (1<<n)));
		ret = new LinkedList<Integer>();
		resolve(-1 + (1<<n));
		for(int x: ret)
			System.out.print(x + " ");
	}
	public static int dist(State a, State b)	{
		int x = a.x-b.x;
		int y = a.y-b.y;
		return x*x+y*y;
	}
	public static void resolve(int curr)	{
		ret.addLast(0);
		for(int i = 0; i < n; i++)	{
			if((curr & (1<<i)) == 0)
				continue;
			for(int j = i+1; j < n; j++)	{
				if((curr & (1 << j)) == 0)		{
					continue;
				}
				if(dist[i][j] + solve(curr ^ (1<<i) ^ (1 << j)) == best[curr])	{
					ret.addLast(i+1);
					ret.addLast(j+1);
					resolve(curr - (1<<i) - (1<<j));
					return;
				}
			}
			if(best[curr] == dist[i][i] + solve(curr ^ (1<<i)))	{
				ret.addLast(i+1);
				resolve(curr - (1<<i));
				return;
			}
		}
	}
	public static int solve(int curr)	{
		if(best[curr] != -1)
			return best[curr];
		int ret = Integer.MAX_VALUE;
		for(int i = 0; i < n; i++)	{
			if((curr & (1<<i)) == 0)
				continue;
			for(int j = i+1; j < n; j++)	{
				if((curr & (1 << j)) == 0)		{
					continue;
				}
				ret = Math.min(ret, dist[i][j] + solve(curr ^ (1<<i) ^ (1 << j)));
			}
			ret = Math.min(ret, dist[i][i] + solve(curr ^ (1<<i)));
			break;
		}
		best[curr] = ret;
		return ret;
	}
	static class State	{
		public int x,y;
		public State(int a, int b)	{
			x=a;
			y=b;
		}
	}
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.util.*;

import static java.lang.System.out;

public final class LookingForOrder {
    private static Map<Integer, Integer> es = new HashMap<Integer, Integer>();
    private static void init() { for (int i = 0; i <= 24; i++) es.put(1 << i, i); }
    private static int x, y;
    private static int[] xs, ys;
    private static int sqr(int i) { return i * i; }
    private static int dist(int i, int j) {
        return sqr(x - xs[i]) + sqr(y - ys[i]) + 
            sqr(xs[i] - xs[j]) + sqr(ys[i] - ys[j]) +
            sqr(x - xs[j]) + sqr(y - ys[j]);
    }

    private static int n;
    private static int[] tb, prevs;

    private static int recur(int j) {
        if (j == 0 || es.get(j) != null || tb[j] != 0) return tb[j];

        int bl = j & -j;
        int b = j ^ bl;
        tb[j] = recur(bl) + recur(b);
        prevs[j] = bl;

        for (int i = es.get(bl) + 1; i <25; i++) {
            if (((1 << i) & b) == 0) continue;

            int k = bl | 1 << i;
            int v = dist(es.get(bl), es.get(1 << i)) + recur(j ^ k);
            if (v >= tb[j]) continue;

            tb[j] = v;
            prevs[j] = k;
        }
        return tb[j];
    }

    public static void main(String[] args) {
        init();
        Scanner s = new Scanner(System.in);
        x = s.nextInt(); y = s.nextInt();
        n = s.nextInt();
        xs = new int[n]; ys = new int[n];
        tb = new int[1 << n]; prevs = new int[1 << n];

        for (int i = 0; i < n; i++) {
            xs[i] = s.nextInt(); ys[i] = s.nextInt();
            tb[1 << i] = sqr(x - xs[i]) + sqr(y - ys[i]) << 1;
        }

        int all = (1 << n) - 1;
        out.println(recur(all));
        StringBuilder sb = new StringBuilder();
        int p = prevs[all];
        int c = all;
        while(p != 0 && p != c) {
            if ((p ^ (p & -p)) == 0) sb.append("0 " + (es.get(p & -p) + 1) + " ");
            else sb.append("0 " + (es.get(p & -p) + 1) + " " + (es.get(p ^ (p & -p)) + 1) + " ");
            c = c ^ p;
            p = prevs[c];
        }

        if ((c ^ (c & -c)) == 0) sb.append("0 " + (es.get(c & -c) + 1) + " 0");
        else sb.append("0 " + (es.get(c & -c) + 1) + " " + (es.get(c ^ (c & -c)) + 1) + " 0");
        out.println(sb);
    }
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class LookingForOrder {

	static int[] x, y;
	static int[] dp;
	static int n;

	static int dist(int i, int j) {
		return ((x[i] - x[j]) * (x[i] - x[j]))
				+ ((y[i] - y[j]) * (y[i] - y[j]));
	}

	static int solve(int mask) {
		if (mask == (1 << n) - 1)
			return 0;
		if (dp[mask] != -1)
			return dp[mask];
		int ans = Integer.MAX_VALUE;
		int j = 0;
		for (int i = 1; i < n; i++)
			if ((mask & (1 << i)) == 0) {
				if (j == 0) {
					ans = Math
							.min(ans, 2 * dist(0, i) + solve(mask | (1 << i)));
					j = i;
				} else
					ans = Math.min(ans, dist(0, i) + dist(i, j) + dist(j, 0)
							+ solve(mask | (1 << i) | (1 << j)));
			}
		return dp[mask] = ans;
	}

	static void prnt(int mask) {
		if (mask == (1 << n) - 1)
			return;
		int j = 0;
		for (int i = 1; i < n; i++)
			if ((mask & (1 << i)) == 0) {
				if (j == 0) {
					j = i;
					if (dp[mask] == 2 * dist(0, i) + solve(mask | (1 << i))) {
						out.print(" " + i + " 0");
						prnt(mask | (1 << i));
						return;
					}
				} else if (dp[mask] == dist(0, i) + dist(i, j) + dist(j, 0)
						+ solve(mask | (1 << i) | (1 << j))) {
					out.print(" " + i + " " + j + " 0");
					prnt(mask | (1 << i) | (1 << j));
					return;
				}
			}
	}

	public static void main(String[] args) throws IOException {
		sc = new StringTokenizer(br.readLine());
		int a = nxtInt();
		int b = nxtInt();
		n = nxtInt() + 1;
		x = new int[n];
		y = new int[n];
		dp = new int[1 << n];
		Arrays.fill(dp, -1);
		x[0] = a;
		y[0] = b;
		for (int i = 1; i < n; i++) {
			x[i] = nxtInt();
			y[i] = nxtInt();
		}
		out.println(solve(1 << 0));
		out.print(0);
		prnt(1 << 0);
		out.println();
		br.close();
		out.close();
	}

	static BufferedReader br = new BufferedReader(new InputStreamReader(
			System.in));
	static PrintWriter out = new PrintWriter(System.out);

	static StringTokenizer sc;

	static String nxtTok() throws IOException {
		while (!sc.hasMoreTokens())
			sc = new StringTokenizer(br.readLine());
		return sc.nextToken();
	}

	static int nxtInt() throws IOException {
		return Integer.parseInt(nxtTok());
	}

	static long nxtLng() throws IOException {
		return Long.parseLong(nxtTok());
	}
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.util.Arrays;
import java.util.Scanner;

public class LookingForOrder {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int bx = in.nextInt();
        int by = in.nextInt();
        in.nextLine();
        int n = in.nextInt();
        int[][] objects = new int[n][2];
        for (int i = 0; i < n; i++) {
            objects[i][0] = in.nextInt();
            objects[i][1] = in.nextInt();
        }

        int[] cs = new int[n];
        for (int i = 0; i < n; i++) {
            cs[i] = 2 * time(objects[i], new int[] { bx, by });
        }

        int[][] cd = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                cd[j][i] = cd[i][j] = time(objects[i], new int[] { bx, by }) + time(objects[j], new int[] { bx, by }) + time(objects[i], objects[j]);
            }
        }

        int maxMask = 1 << n;
        int[] dp = new int[maxMask];
        int[] path = new int[maxMask];
        Arrays.fill(dp, -1);
        dp[0] = 0;

        for (int g = 1; g < maxMask; g++) {
            int min = Integer.MAX_VALUE;
            int minPath = 0;
            int h = 31;
            while ((g & (1 << h)) == 0)
                h--;
            h++;
            int l = 0;
            while ((g & (1 << l)) == 0)
                l++;
            if ((g & 1 << l) > 0) {
                int oneleft = g ^ (1 << l);
                int t = cs[l] + dp[oneleft];
                if (t < min) {
                    min = t;
                    minPath = oneleft;
                }
                for (int j = l + 1; j < h; j++) {
                    if ((oneleft & 1 << j) > 0) {
                        int twoleft = oneleft ^ (1 << j);
                        t = cd[l][j] + dp[twoleft];
                        if (t < min) {
                            min = t;
                            minPath = twoleft;
                        }
                    }
                }
            }
            dp[g] = min;
            path[g] = minPath;
        }

        System.out.println(dp[maxMask - 1]);

        int previous = maxMask - 1;
        int pathElt = path[previous];
        System.out.print("0 ");
        while (previous > 0) {
            int bits = previous - pathElt;
            int h = 31;
            while ((bits & (1 << h)) == 0)
                h--;
            int l = 0;
            while ((bits & (1 << l)) == 0)
                l++;
            String el = h == l ? "" + (h + 1) : (h + 1) + " " + (l + 1);
            System.out.print(el + " " + 0 + " ");
            previous = pathElt;
            pathElt = path[pathElt];
        }
        System.out.println();

    }

    static int time(int[] a, int[] b) {
        int x = b[0] - a[0];
        int y = b[1] - a[1];
        return x * x + y * y;
    }
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.util.*;
import java.awt.Polygon;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.*;
import java.util.Collection;

public class Solution {

	/**
	 * @param args
	 * @throws IOException 
	 */
	static StringTokenizer st;
	static BufferedReader reader;
	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		int xs = NextInt();
		int ys = NextInt();
		int n = NextInt();
	
		int x[] = new int[n];
		int y[] = new int[n];
		int single[] = new int[n];
		int pair[][] = new int[n][n];
		for (int i = 0; i < n; ++i) {
			x[i] = NextInt();
			y[i] = NextInt();
		}
		for (int i = 0; i < n; ++i) 
			single[i] = 2 * dist(xs, ys, x[i], y[i]);
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				pair[i][j] = dist(xs, ys, x[i], y[i]) + 
							 dist(x[i], y[i], x[j], y[j]) +
							 dist(x[j], y[j], xs, ys);
		int dp[] = new int[1 << n];
		int prev[] = new int[1 << n];
		for (int mask = 0; mask < (1 << n); ++mask) {
			int p = -1;
			for (int i = 0; i < n; ++i)
				if (((mask >> i) & 1) != 0) {
					p = i;
					break;
				}
			if (p == -1) continue;
			dp[mask] = dp[mask ^ (1 << p)] + single[p];
			prev[mask] = p;
			for (int j = p + 1; j < n; ++j) {
				if (((mask >> j) & 1) != 0) {
					int res = pair[p][j] + dp[mask ^ (1 << p) ^ (1 << j)];
					if (res < dp[mask]) {
						dp[mask] = res;
						prev[mask] = p + 100 * j;
					}
				}
			}
		}
		int cur = (1 << n) - 1;
		System.out.printf("%d\n0 ", dp[cur]);
		while(cur != 0) {
			if (prev[cur] < 100) {
				System.out.printf("%d %d ", prev[cur] + 1, 0);
				cur ^= (1 << prev[cur]);
			} else {
				int i = prev[cur] / 100;
				int j = prev[cur] % 100;
				System.out.printf("%d %d %d ", i + 1, j + 1, 0);
				cur = cur ^ (1 << i) ^ (1 << j);
			}
		}
	}
	static int dist(int x0, int y0, int x1, int y1) {
		return (x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1); 
	}
	static int NextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(NextToken());
	}
	static String NextToken() throws IOException {
		while(st == null || !st.hasMoreTokens()) {
			st = new StringTokenizer(reader.readLine());
		}
		return st.nextToken();
	}

}
// Problem: 8_C. Looking for Order
// Time complexity: np

import java.util.*;

public class Main {

    static Scanner cin = new Scanner(System.in);
    private int xs, ys, n;
    private int[] x, y;

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    class Item implements Comparable<Item> {

        int w, h, idx;

        Item(int w, int h, int idx) {
            this.w = w;
            this.h = h;
            this.idx = idx;
        }

        @Override
        public int compareTo(Item o) {
            if (this.w == o.w) {
                return this.h - o.h;
            }
            return this.w - o.w;
        }
    }

    private void run() throws Exception {
        xs = cin.nextInt();
        ys = cin.nextInt();
        n = cin.nextInt();
        x = new int[n + 1];
        y = new int[n + 1];
        for (int i = 0; i < n; i++) {
            x[i] = cin.nextInt();
            y[i] = cin.nextInt();
        }
        int[] res = new int[1 << n];
        Arrays.fill(res, Integer.MAX_VALUE);
        int[] ds = new int[n];
        for (int i = 0; i < n; i++) {
            ds[i] = (x[i] - xs) * (x[i] - xs) + (y[i] - ys) * (y[i] - ys);
        }
        int[][] d = new int[n + 1][n + 1];
        int[] tr = new int[1 << n];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                d[i][j] = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
            }
        }
        //----------------------
        res[0] = 0;
        for (int i = 1; i < (1 << n); i++) {
            for (int j = 0; j < n; j++) {
                if (((i >> j) & 1) != 0) {
                    if (res[i - (1 << j)] + 2 * ds[j] < res[i]) {
                        res[i] = res[i - (1 << j)] + 2 * ds[j];
                        tr[i] = i - (1 << j);
                    }
                    for (int k = j + 1; k < n; k++) {
                        if (((i >> k) & 1) != 0) {
                            if (res[i - (1 << j) - (1 << k)] + ds[k] + ds[j] + d[k][j] < res[i]) {
                                res[i] = res[i - (1 << j) - (1 << k)] + ds[k] + ds[j] + d[k][j];
                                tr[i] = i - (1 << j) - (1 << k);
                            }
                        }
                    }
                    break;
                }
            }
        }
        System.out.println(res[(1 << n) - 1]);
        int now = (1 << n) - 1;
        while (now != 0) {
            System.out.print("0 ");
            int dif = now - tr[now];
            for (int i = 0; i < n && dif != 0; i++) {
                if (((dif >> i) & 1) != 0) {
                    System.out.print((i + 1) + " ");
                    dif -= (1 << i);
                }
            }
            now=tr[now];
        }
        System.out.print("0");
    }
}
// Problem: 16_E. Fish
// Time complexity: np
import java.util.*;

public class cf16e {
	static int n;
	static double[][] prob;
	static double[] memo;
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		prob = new double[n][n];
		memo = new double[1<<n];
		for(int i=0; i<n; i++)
			for(int j=0; j<n; j++)
				prob[i][j] = in.nextDouble();
		memo[(1<<n)-1] = 1;
		for(int k=(1<<n)-1; k>0; k--) {
			int numWays = Integer.bitCount(k);
			numWays = (numWays*(numWays-1))/2;
			for(int first = 0; first < n; first++) {
				if(!isSet(k,first)) continue;
				for(int second = first+1; second < n; second++) {
					if(!isSet(k,second)) continue;
					memo[reset(k,first)] += prob[second][first]*memo[k]/numWays;
					memo[reset(k,second)] += prob[first][second]*memo[k]/numWays;
				}
			}
		}
		for(int i=0; i<n; i++)
			System.out.printf("%.6f ", memo[set(0,i)]);
		System.out.println();
	}
	static boolean isSet(int x, int p) {
		return (x&(1<<p)) != 0;
	}
	static int set(int x, int p) {
		return x|(1<<p);
	}
	static int reset(int x, int p) {
		return x&~(1<<p);
	}
	static boolean isDone(int x) {
		return Integer.bitCount(x)==n-1;
	}
}