using System.Linq; using System.Collections.Generic; using System; public class Hello { public static int n; public static int[] a; public static int[,] b; static void Main() { n = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); a = Array.ConvertAll(line, int.Parse); b = new int[n, n]; for (int i = 0; i < n; i++) { line = Console.ReadLine().Trim().Split(' '); for (int j = 0; j < n; j++) b[i, j] = int.Parse(line[j]); } getAns(); } static long calc(List p) { var res = 0L; var pc = p.Count(); for (int i = 0; i < pc - 1; i++) for (int j = i + 1; j < pc; j++) res += b[p[i] - 1, p[j] - 1]; return res; } static void getAns() { var ans = long.MinValue; var ansp = new List(); var imax = 1 << n; for (int i = 1; i < imax; i++) { var temp = 0L; var p = new List(); for (int j = 0; j < 18; j++) { if (((i >> j) & 1) == 1) { temp += a[j]; p.Add(j + 1); } } temp += calc(p); if (temp > ans) { ans = temp; ansp = p; } } Console.WriteLine(ans); Console.WriteLine(string.Join(" ", ansp)); } }