import java.util.Scanner; import java.util.List; import java.util.ArrayList; public class No1360 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); List A = new ArrayList(); for (int i=0; i < N; i++) { A.add(scan.nextInt()); } List> B = new ArrayList>(); for (int i=0; i < N; i++) { List l = new ArrayList(); for (int j=0; j < N; j++) { l.add(scan.nextInt()); } B.add(l); } scan.close(); int Max = Integer.MIN_VALUE; int Max_comb = -1; for (int i=0; i < 1 << N; i++) { int point = 0; List prev = new ArrayList(); for (int j=0; j < N; j++) { if ((i & (1 << j)) != 0) { point += A.get(j); for (int p : prev) { point += B.get(p).get(j); } prev.add(j); } } if (Max < point) { Max = point; Max_comb = i; } } List J = new ArrayList(); for (int j=0; j < N; j++) { if ((Max_comb & (1 << j)) != 0) { J.add(String.valueOf(j+1)); } } System.out.println(Max); System.out.println(String.join(" ", J)); } }