import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } int[][] b = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { b[i][j] = sc.nextInt(); } } sc.close(); long ans = 0; Set as = new HashSet<>(); int end = 1 << n; for (int i = 0; i < end; i++) { long val = 0; Set set = new HashSet<>(); for (int j = 0; j < n; j++) { if ((i >> j & 1) == 1) { val += a[j]; for (int j2 = 0; j2 < j; j2++) { if (set.contains(j2)) { val += b[j][j2]; } } set.add(j); } } if (val > ans) { ans = val; as = set; } } System.out.println(ans); StringBuilder sb = new StringBuilder(); for (int i : as) { sb.append(i + 1).append(' '); } sb.deleteCharAt(sb.length() - 1); System.out.println(sb.toString()); } }