import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] bases = new int[n]; for (int i = 0; i < n; i++) { bases[i] = sc.nextInt(); } 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(); } } long ans = Long.MIN_VALUE; int idx = 0; for (int i = 1; i < (1 << n); i++) { long sum = 0; for (int j = 0; j < n; j++) { if ((i & (1 << j)) == 0) { continue; } sum += bases[j]; for (int k = j + 1; k < n; k++) { if ((i & (1 << j)) == 0) { continue; } sum += matrix[j][k]; } } if (ans < sum) { ans = sum; idx = i; } } System.out.println(ans); StringBuilder sb = new StringBuilder(); boolean isFirst = true; for (int i = 0; i < n; i++) { if ((idx & (1 << i)) == 0) { continue; } if (!isFirst) { sb.append(" "); } isFirst = false; sb.append(i + 1); } System.out.println(sb); } }