codeparrot/codecomplex huggingface dataset:
// Problem: 1185_G1. Playlist for Polycarp (easy version)
// Time complexity: np
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        G1PleilistDlyaPolikarpaUproshennayaVersiya solver = new G1PleilistDlyaPolikarpaUproshennayaVersiya();
        solver.solve(1, in, out);
        out.close();
    }

    static class G1PleilistDlyaPolikarpaUproshennayaVersiya {

        static final int MOD = (int) 1e9 + 7;
        int n;
        int t;
        int[][] a = new int[15][2];
        long[][] mem = new long[1 << 15][4];

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            for (int i = 0; i < (1 << 15); i++) {
                for (int h = 0; h < 4; h++) {
                    mem[i][h] = -1;
                }
            }
            n = in.nextInt();
            t = in.nextInt();
            for (int i = 0; i < n; i++) {
                a[i][0] = in.nextInt();
                a[i][1] = in.nextInt();
            }
            out.println(doit(0, 0, 0));
        }

        private long doit(int mask, int genre, int sum) {
            if (mem[mask][genre] != -1) {
                return mem[mask][genre];
            }
            if (sum > t) {
                mem[mask][genre] = 0;
                return mem[mask][genre];
            }
            if (sum == t) {
                mem[mask][genre] = 1;
                return mem[mask][genre];
            }
            long ct = 0;
            for (int i = 0; i < n; i++) {
                if ((mask & (1 << i)) > 0 || genre == a[i][1]) {
                    continue;
                }
                ct = (ct + doit(mask | (1 << i), a[i][1], sum + a[i][0])) % MOD;
            }

            mem[mask][genre] = ct;
            return mem[mask][genre];
        }
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}
// Problem: 1185_G1. Playlist for Polycarp (easy version)
// Time complexity: np
import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;
public class G1 {
	public static void main(String[] args) throws Exception {
		new G1().run();
    }
    int MOD = 1_000_000_007;
	public void run() throws Exception {
		FastScanner f = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = f.nextInt(), t = f.nextInt();
        int[][] dp = new int[1 << n][3];
        int[] tarr = new int[n];
        int[] garr = new int[n];
        for(int i = 0; i < n; i++) {
            tarr[i] = f.nextInt();
            garr[i] = f.nextInt()-1;
            if(tarr[i] <= t) dp[1 << i][garr[i]] = 1;
        }
        int[] time = new int[1 << n];
        for(int i = 0; i < dp.length; i++) {
            for(int bi = 0; bi < n; bi++)
                if((i & 1 << bi) != 0) time[i] += tarr[bi];
        }
        for(int i = 0; i < dp.length; i++) {
            int j = time[i];
                for(int k = 0; k < 3; k++) {
                    if(dp[i][k] == 0) continue;
                    for(int bi = 0; bi < n; bi++)
                        if(tarr[bi] + j <= t && (i & 1 << bi) == 0 && garr[bi] != k) {
                                    dp[i | 1 << bi][garr[bi]] = 
                                        (dp[i | 1 << bi][garr[bi]] + dp[i][k]) % MOD;
                        }
                }
        }
        long ans = 0;
        for(int i = 0; i < dp.length; i++)
            for(int j = 0; j < 3; j++)
            if(time[i] == t) ans = (ans + dp[i][j]) % MOD;
        out.println(ans);
        out.flush();
	}
    static class FastScanner {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public FastScanner() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
        public String nextLine() {
        	try {
        		return reader.readLine();
        	} catch(IOException e) {
        		throw new RuntimeException(e);
        	}
        }
    }
}
// Problem: 1185_G1. Playlist for Polycarp (easy version)
// Time complexity: np
//package cf568d2;
import java.util.*;
public class G {
    static int n,t;
    static int[]a;
    static int[]g;
    static long[][][]dp;
    static final long MOD=1000000007;
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        t=sc.nextInt();
        a=new int[n];
        g=new int[n];
        for(int i=0;i<n;i++) {
            a[i] = sc.nextInt();
            g[i] = sc.nextInt();
        }
        dp=new long[4][1<<(n-1)+1][t+1];
        for(int i=0;i<4;i++)
            for(int j=0;j<1<<(n-1)+1;j++)
                for(int k=0;k<=t;k++)
                    dp[i][j][k]=-1;
        System.out.println(dp(0,0,t));
    }
    private static long dp(int genre,int mask,int time){
        if(time<0)
            return 0;
        if(dp[genre][mask][time]!=-1)
            return dp[genre][mask][time];
        if(time==0)
            return 1;
        dp[genre][mask][time]=0;
        for(int i=0;i<n;i++) {
            if (g[i] != genre && ((1 << i) & mask) == 0)
                dp[genre][mask][time] = (dp[genre][mask][time]+dp(g[i], mask | (1 << i), time - a[i]))%MOD;
        }
        return dp[genre][mask][time];
    }
}
// Problem: 1185_G1. Playlist for Polycarp (easy version)
// Time complexity: np
import java.util.*;
import java.io.*;
import java.math.*;
public class Solution{
    public static long mod = 1000000007;
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int t = Integer.parseInt(st.nextToken());
        int[] d = new int[n];
        int[] g = new int[n];
        for(int i=0;i<n;i++){
            st = new StringTokenizer(br.readLine());
            d[i] = Integer.parseInt(st.nextToken());
            g[i] = Integer.parseInt(st.nextToken())-1;
        }
        long[][] dp = new long[(1<<n)][3];
        for(int i=0;i<n;i++){
            dp[(1<<i)][g[i]] = 1;
        }
        long res = 0;
        for(int i=1;i<(1<<n);i++){
            int k = i;
            int sum = 0;
            for(int j=n-1;j>=0;j--){
                if(k>=(1<<j)){
                    k-=(1<<j);
                    sum += d[j];
                }
                else{
                    for(int r=0;r<3;r++) if(r!=g[j]) dp[i+(1<<j)][g[j]] += dp[i][r];
                    dp[i+(1<<j)][g[j]] %= mod;
                }
            }
            if(sum==t){
                res += dp[i][0] +dp[i][1] +dp[i][2];
                res %= mod;
            }
        }
        out.println(res);
        out.flush(); 
    }
}
// Problem: 1185_G1. Playlist for Polycarp (easy version)
// Time complexity: np
import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class codeforces {

    public static long cnt = 0;

    public static void f(int g1, int g2, int g3, int last) {
        if (g1 == 0 && g2 == 0 && g3 == 0) cnt++;
        if (g1 > 0 && last != 1) f(g1 - 1, g2, g3, 1);
        if (g2 > 0 && last != 2) f(g1, g2 - 1, g3, 2);
        if (g3 > 0 && last != 3) f(g1, g2, g3 - 1, 3);
    }

    public static void main(String[] args) throws IOException {
        BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(scan.readLine());
        int n = Integer.parseInt(st.nextToken());
        int t = Integer.parseInt(st.nextToken());
        int T[] = new int[n];
        int G[] = new int[n];
        for (int i = 0; i < n; i++) {
            st = new StringTokenizer(scan.readLine());
            T[i] = Integer.parseInt(st.nextToken());
            G[i] = Integer.parseInt(st.nextToken());
        }
        long ans = 0;
        for (int mask = 1; mask < (1 << n); mask++) {
            int sum = 0;
            int g1 = 0;
            int g2 = 0;
            int g3 = 0;

            for (int i = 0; i < n; i++) {
                if (((1 << i) & mask) > 0) {
                    sum += T[i];
                    if (G[i] == 1) g1++;
                    if (G[i] == 2) g2++;
                    if (G[i] == 3) g3++;
                }
            }
            cnt = 0;
            if (sum == t) f(g1, g2, g3, -1);
            for (long i = 1; i <= g1; i++) cnt *= i;
            for (long i = 1; i <= g2; i++) cnt *= i;
            for (long i = 1; i <= g3; i++) cnt *= i;
            ans += cnt;
        }
        System.out.println(ans % 1000000007);
    }
}
// Problem: 1185_G1. Playlist for Polycarp (easy version)
// 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 G_PlaylistForPolycarp {

	static final int mod = 1000000007;

	static int dp[][];

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

		String[] dat = br.readLine().split(" ");

		int n = Integer.parseInt(dat[0]);
		int T = Integer.parseInt(dat[1]);

		int[] st = new int[n];
		byte[] sg = new byte[n];

		dp = new int[1 << (n + 1)][4];

		for (int j = 0; j < 1 << (n + 1); j++) {
			for (int k = 0; k < 4; k++) {
				dp[j][k] = -1;
			}
		}

		for (int i = 0; i < n; i++) {
			dat = br.readLine().split(" ");
			st[i] = Integer.parseInt(dat[0]);
			sg[i] = Byte.parseByte(dat[1]);
		}

		short visited = 0;

		int count = recur(0, visited, st, sg, T, 0);

		bw.write(count + "\n");

		bw.close();

	}

	private static int recur(int time, short visited, int[] st, byte[] sg, int T, int last) {

		int count = 0;

		if (dp[visited][last] != -1) {
			return dp[visited][last];
		}

		for (int i = 0; i < st.length; i++) {

			if ((visited & (1 << i)) == 0 && sg[i] != last) {

				if (time + st[i] == T) {
					count += 1;
				} else if (time + st[i] < T) {
					short visitedc = (short) (visited | (1 << i));
					count += recur(time + st[i], visitedc, st, sg, T, sg[i]);
					if (count > mod) {
						count = count % mod;
					}
				}

			}

		}

		return dp[visited][last] = count % mod;
	}

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

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by 11815 on 2017/7/1.
 */
public class Main {
    private static int[] x = new int[26], y = new int[26], dp = new int[1<<24], pre = new int[1<<24];
    private static int dis(int i, int j) {
        return (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x0 = in.nextInt(), y0 = in.nextInt(), n = in.nextInt();
        for (int i = 0; i < n; i++) {
            x[i] = in.nextInt();
            y[i] = in.nextInt();
        }
        x[n] = x0;
        y[n] = y0;
        int[][] gra = new int[26][26];
        for (int i = 0; i < n + 1; i++) {
            for (int j = i+1; j < n+1; j++) {
                gra[i][j] = gra[j][i] = dis(i,j);
            }
        }
        Arrays.fill(dp, -1);
        dp[0] = 0;
        for (int i = 0; i < 1 << n; i++) {
            if (dp[i] != -1) {
                for (int j = 0; j < n; j++) {
                    if (((1<<j)&i) == 0) {
                        int t = i | (1<<j), tmp = dp[i] + 2*gra[j][n];
                        if (dp[t] == -1 || dp[t] > tmp) {
                            dp[t] = tmp;
                            pre[t] = i;
                        }
                        for (int k = 0; k < n; k++) {
                            if ((t&(1<<k)) == 0) {
                                int t2 = t | (1<<k), tmp2 = dp[i] + gra[n][j] + gra[j][k] + gra[k][n];
                                if (dp[t2] == -1 || dp[t2] > tmp2) {
                                    dp[t2] = tmp2;
                                    pre[t2] = i;
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
        int end = (1<<n)-1, cnt = 0;
        int[] ans = new int[60];
        System.out.println(dp[end]);
        while (end != 0) {
            int pr = pre[end];
            int tem = pr^end;
            int a = 0, b = 0;
            for (int i = 0; i < n; i++) {
                if (((1<<i)&tem)!=0) {
                    b=a;
                    a=i+1;
                }
            }
            ans[cnt++] = 0;
            ans[cnt++] = a;
            if (b>0) {
                ans[cnt++] = b;
            }
            end = pr;
        }
        ans[cnt++] = 0;
        for (int i = cnt-1; i >= 0; i--) {
            System.out.print(ans[i] + " ");
        }
        System.out.print("\n");
    }
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.io.*;         
import java.util.*;         
import java.math.*;         
 
public class Main  implements Runnable {
//public static final String FileName = "test";
StreamTokenizer ST;      
PrintWriter out;      
BufferedReader br;   
Scanner in;
static final int inf = 1000000000+10;
 
int nextInt() throws IOException{      
    ST.nextToken();      
    return (int)ST.nval;      
}
long nextLong() throws IOException{      
    ST.nextToken();      
    return (long)ST.nval;      
}      
String next() throws IOException{      
    ST.nextToken();      
    return ST.sval;      
}      
double nextD() throws IOException{      
    ST.nextToken();      
    return ST.nval;      
}      
public static void main(String[] args) throws IOException {       
   new Thread(new Main()).start();
//	new Main().run();
}
 
public void run()  {      
    try {
    	br = new BufferedReader(new InputStreamReader(System.in));
    	out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));    	
    	//br = new BufferedReader(new FileReader(new File(FileName+".in")));
    	//out = new PrintWriter(new BufferedWriter(new FileWriter(FileName+".out")));
    	//in = new Scanner(br);
        ST = new StreamTokenizer(br);      
        solve();      
        out.close();
        //in.close();
        br.close();   
    }         
    catch (IOException e) {       
    	e.printStackTrace();
    	throw new IllegalStateException(e);  
    }      
}


public void solve() throws IOException {
	int[] x = new int[32];
	int[] y = new int[32];
	x[0] = nextInt();
	y[0] = nextInt();	
	int n = nextInt();
	for (int i=1; i<=n; i++) {
		x[i] = nextInt();
		y[i] = nextInt();
	}
	n++;
	int[][] a = new int[n][n];
	int[][] b = new int[n-1][n-1];
	for (int i=0; i<n; i++)
		for (int j=0; j<n; j++)
			a[i][j] = (x[i]-x[j])*(x[i]-x[j])+ (y[i]-y[j])*(y[i]-y[j]);
	for (int i=1; i<n; i++)
		for (int j=1; j<n; j++)
			if (i!=j) b[i-1][j-1] = a[0][i]+a[i][j]+a[j][0]; else b[i-1][j-1] = 2*a[0][i];
	n--;
	
	int sz = 1<<n;
	int[] d = new int[sz];
	int[] p = new int[sz];
	d[1] = 0;
	for (int msk=1; msk<sz; msk++) {
		int j = 0;
		while ((msk&(1<<j))==0) j++;
		int t = inf;		
		for (int i=0; i<n; i++)
			if ((msk&(1<<i))>0)
			if (t>d[msk^((1<<i)|(1<<j))]+b[i][j]) {
				t = d[msk^((1<<i)|(1<<j))]+b[i][j];
				p[msk] = i*n+j;
			}	
		d[msk] = t;
		
	}
	out.println(d[sz-1]);
	out.print("0 ");
	int t = sz-1;
	while (t>0) {
		int hz = p[t];
		int i = hz/n;
		int j = hz%n;
		if (i!=j) out.print((i+1)+" "+(j+1)+" 0 ");else out.print((i+1)+" 0 ");
		t ^= (1<<i)|(1<<j);
	}
	
}
  
}
// Problem: 8_C. Looking for Order
// Time complexity: np
import java.util.*;
import java.io.*;

public class Main{

    BufferedReader in;
    StringTokenizer str = null;
    PrintWriter out;

    private String next() throws Exception{
    	if (str == null || !str.hasMoreElements())
    	    str = new StringTokenizer(in.readLine());
    	return str.nextToken();
    }
    
    private int nextInt() throws Exception{
	   return Integer.parseInt(next());
    }

    int []x,y;
    int n;
    int []dp, prev;
    
    public void run() throws Exception{
    	in = new BufferedReader(new InputStreamReader(System.in));
    	out = new PrintWriter(System.out);

    	int xs = nextInt();
    	int ys = nextInt();
    	n = nextInt();
    	x = new int[n];
    	y = new int[n];
    	for(int i=0;i<n;i++){
    		x[i] = nextInt();
    		y[i] = nextInt();
    	}

    	int one[] = new int[n];
    	for(int i=0;i<n;i++){
    		one[i] = dist(xs, ys, x[i], y[i]);
    	}

    	int two[][] = new int[n][n];
    	for(int i=0;i<n;i++){
    		for(int j=i+1;j<n;j++){
    			two[i][j] = two[j][i] = dist(xs, ys, x[i], y[i]) + dist(x[i], y[i], x[j], y[j]) + dist(xs, ys, x[j], y[j]);
    		}
    	}

    	dp = new int[1<<n];
    	Arrays.fill(dp, Integer.MAX_VALUE/2);
    	dp[0] = 0;
    	prev = new int[1<<n];
    	Arrays.fill(prev, -1);

    	for(int mask=1;mask<(1<<n);mask++){
    		int i = 0;
    		while((mask & (1<<i)) == 0) i++;
    		dp[mask] = dp[mask ^ (1<<i)] + 2*one[i];
    		prev[mask] = i+1;
    		for(int j=i+1;j<n;j++){
    			if ((mask & (1<<j)) > 0) {
    				if (dp[mask] > dp[mask ^ (1<<i) ^ (1<<j)] + two[i][j]) {
    					dp[mask] = dp[mask ^ (1<<i) ^ (1<<j)] + two[i][j];
    					prev[mask] = 100 * (i+1) + (j+1);
    				}
    			}
    		}
    	}

    	out.println(dp[(1<<n)-1]);
    	out.print(0 + " ");
    	int cur = (1<<n)-1;
    	int i = 0, j = 0;
    	while(cur > 0) {
    		i = prev[cur]/100;
    		j = prev[cur]%100;
    		
    		if (i > 0) {
    			cur^=1<<(i-1);
    			out.print(i + " ");
    		}

    		if (j > 0) {
    			cur^=1<<(j-1);
    			out.print(j + " ");
    		}

    		out.print(0 + " ");
    	}
    	// if (i == 0 || j == 0) {
    	// 	out.println(0);	
    	// }
		out.close();	
    }

    private String bit2str(int mask, int n) {
    	String s = "";
    	for(int i=0;i<n;i++){
    		if ((mask & (1<<i)) > 0){
    			s+="1";
    		}else{
    			s+="0";
    		}
    	}
    	while(s.length() < n)
    		s+="0";

    	return new StringBuilder(s).reverse().toString();
    }

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

    public static void main(String args[]) throws Exception{
	   new Main().run();
    }
}
// Problem: 8_C. Looking for Order
// Time complexity: np

import java.awt.Point;
import java.util.Arrays;
import java.util.Scanner;

public class C {
    static int[] DP;
    static Point[] Next;
    static int[][] pair;
    static int[] single;
    static int n;

    public static int get(int mask) {
        if (mask + 1 == (1 << n))
            return 0;
        if (DP[mask] != -1)
            return DP[mask];
        int x = 0;
        for (;; x++)
            if ((mask & (1 << x)) == 0)
                break;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            if ((mask & (1 << i)) != 0 || i == x)
                continue;
            int temp = pair[x][i] + get(mask | (1 << i) | (1 << x));
            if (temp < min) {
                min = temp;
                Next[mask] = new Point(x, i);
            }
        }
        int temp = single[x] + get(mask | (1 << x));
        if (temp < min) {
            min = temp;
            Next[mask] = new Point(x, -1);
        }
        return DP[mask] = min;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Point start = new Point(in.nextInt(), in.nextInt());
        n = in.nextInt();
        Point[] A = new Point[n];
        for (int i = 0; i < n; i++)
            A[i] = new Point(in.nextInt(), in.nextInt());
        DP = new int[1 << n];
        Next = new Point[1 << n];
        Arrays.fill(DP, -1);
        pair = new int[n][n];
        single = new int[n];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++) {
                int dx1 = A[i].x - start.x;
                int dy1 = A[i].y - start.y;
                int dx2 = A[j].x - A[i].x;
                int dy2 = A[j].y - A[i].y;
                int dx3 = A[j].x - start.x;
                int dy3 = A[j].y - start.y;
                pair[i][j] = dx1 * dx1 + dy1 * dy1 + dx2 * dx2 + dy2 * dy2
                        + dx3 * dx3 + dy3 * dy3;
                single[i] = 2 * (dx1 * dx1 + dy1 * dy1);
            }
        int ans = get(0);
        System.out.println(ans);
        int mask = 0;
        while (mask + 1 != (1 << n)) {
            Point temp = Next[mask];
            if (temp.y == -1)
                System.out.print("0 " + (temp.x + 1) + " ");
            else {
                System.out
                        .print("0 " + (temp.x + 1) + " " + (temp.y + 1) + " ");
                mask |= (1 << temp.y);
            }
            mask |= (1 << temp.x);
        }
        System.out.println("0");
    }
}