lib C;fun strtoll(s: UInt8*,p: UInt8**,b: Int32): Int64;end class String;def to_i64;C.strtoll(self,nil,10);end;end n = gets.to_s.to_i64 a = gets.to_s.split.map{ |e| e.to_i64 } b = Array(Array(Int64)).new(n){ |s| gets.to_s.split.map{ |e| e.to_i64 } } ans = Int64::MIN ans_cmb = [] of Int64 ia = (0i64...n).to_a (1i64..n).each do |i| ia.each_combination(i) do |cmb| tmp = cmb.sum{ |j| a[j].to_i64 }.to_i64 tmp += cmb.each_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 + 1i64 }.join(' ')