n = gets.to_s.to_i a = gets.to_s.split.map{ |e| e.to_i } b = readlines.map{ |s| s.split.map{ |e| e.to_i } } # p (0..18).sum{ |k| ([*0...18]).combination(k).size } ans = -Float::INFINITY ans_cmb = nil ia = (0...n).to_a (1..n).each do |i| ia.combination(i) do |cmb| tmp = cmb.sum{ |j| a[j] } tmp += cmb.combination(2).sum{ |x, y| b[x][y] } tmp_cmb = cmb if ans < tmp ans = tmp ans_cmb = tmp_cmb end end end puts ans puts ans_cmb.map{ |k| k + 1 }.join(' ')