import java.io.PrintWriter import java.util.* import kotlin.math.* fun PrintWriter.solve() { val n = nextInt() val a = Array(n) { nextLong() } val b = Array(n) { Array(n) { nextLong() } } var ans = -1L to BooleanArray(n) { false } for (i in 0 until 1.shl(n)) { val choice = BooleanArray(n) { false } for (j in 0 until n) { if (i.shr(j) % 2 != 0) { choice[j] = true } } var score = 0L for (j in 0 until n) { if (choice[j]) score += a[j] } for (j in 0 until n) { for (k in j + 1 until n) { if (choice[j] && choice[k]) { score += b[j][k] } } } if (ans.first < score) { ans = score to choice } } println(ans.first) println((0 until n).filter { ans.second[it] }.map { it + 1 }.joinToString(" ")) } fun main() { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine()!! fun nextDouble() = next().toDouble() // endregion