#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let n = read::(); let a = read_vec::(); let mut b = vec![]; for i in 0..n { b.push(read_vec::()); } let mut ans = -std::i64::MAX; let mut answers = vec![]; for state in 0..1 << n { let mut used = vec![]; let mut temp = 0; for j in 0..n { if (state >> j) & 1 == 1 { used.push(j); temp += a[j] } } for i in 0..used.len() { for j in i + 1..used.len() { temp += b[used[i]][used[j]]; } } if ans < temp { ans = temp; answers = used; } } println!("{}", ans); for ans in answers.iter().take(answers.len() - 1) { print!("{} ", ans + 1); } println!("{}", answers[answers.len() - 1] + 1); } fn read() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec() -> Vec { read::() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }