n = read_line.to_i a = read_line.split.map(&.to_i64) b = (1..n).map { read_line.split.map(&.to_i64) } ans, bit = (1...1 << n).max_of { |bit| x = (0...n).select { |i| bit.bit(i) == 1 } {x.sum { |i| a[i] } + x.combinations(2).sum { |(i, j)| b[i][j] }, x} } puts ans, bit.join(' ', &.+(1))