import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); long[] dp = new long[1 << n]; long max = 0; int mask = 0; for (int i = 0; i < n; i++) { dp[1 << i] = sc.nextInt(); if (max < dp[1 << i]) { max = dp[1 << i]; mask = (1 << i); } } int[][] matrix = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { matrix[i][j] = sc.nextInt(); } } for (int i = 1; i < (1 << n); i++) { if (dp[i] > 0) { continue; } for (int j = 0; j < n; j++) { if ((i & (1 << j)) == 0) { continue; } dp[i] += dp[1 << j] + dp[i ^ (1 << j)]; for (int k = j + 1; k < n; k++) { if ((i % (1 << k)) == 0) { continue; } dp[i] += matrix[j][k]; } break; } if (max < dp[i]) { max = dp[i]; mask = i; } } System.out.println(max); ArrayList ans = new ArrayList<>(); for (int i = 0; i < n; i++) { if ((mask & (1 << i)) > 0) { ans.add(i + 1); } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < ans.size(); i++) { if (i > 0) { sb.append(" "); } sb.append(ans.get(i)); } System.out.println(sb); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }