use std::io::{BufRead, Write}; struct Lines { b: B, buf: Vec } impl Lines { fn next(&mut self) -> &str { self.buf.clear(); self.b.read_until(b'\n', &mut self.buf).ok(); if self.buf.ends_with(&[b'\n']) { self.buf.pop(); if self.buf.ends_with(&[b'\r']) { self.buf.pop(); } } std::str::from_utf8(&self.buf).unwrap() } } macro_rules! parse { ($s:expr, Usize1) => (parse!($s, usize) - 1); ($s:expr, Bytes) => ($s.as_bytes().to_vec()); ($s:expr, Chars) => ($s.chars().collect::>()); ($s:expr, $t:ty) => ($s.parse::<$t>().unwrap()); } macro_rules! scan { ($iter:expr, ($($t:ident),*)) => ( ($(scan!($iter, $t)),*) ); ($iter:expr, [$t:ident]) => ( $iter.map(|s| parse!(s, $t)).collect::>() ); ($iter:expr, $t:ident) => ( parse!($iter.next().unwrap(), $t) ); } macro_rules! read { ($lines:expr, [$t:tt; $n:expr]) => ( (0..$n).map(|_| read!($lines, $t)).collect::>() ); ($lines:expr, $t:tt) => ({ let iter = &mut $lines.next().split(' '); scan!(iter, $t) }); } fn run(mut lines: Lines, mut writer: W) { let n = read!(lines, usize); let a = read!(lines, [i64]); let b = read!(lines, [[i64]; n]); let mut ans: usize = 0; let mut max = i64::MIN; for i in 1..(1 << n) { let mut res = 0; for (j, (a, b)) in a.iter().zip(b.iter()).enumerate() { if i >> j & 1 == 0 { continue; } res += a; for (k, b) in b.iter().enumerate() { if j == k { break; } if i >> k & 1 == 0 { continue; } res += b; } } if max < res { ans = i; max = res; } } writeln!(writer, "{}", max).ok(); let m = ans.count_ones() as usize; let mut buf = Vec::with_capacity(m); for i in 0..n { if ans >> i & 1 == 0 { continue; } buf.push(i + 1); } for i in buf.iter().take(m.saturating_sub(1)) { write!(writer, "{} ", i).ok(); } writeln!(writer, "{}", buf.last().unwrap()).ok(); } fn main() { let (stdin, stdout) = (std::io::stdin(), std::io::stdout()); let lines = Lines { b: stdin.lock(), buf: Vec::new() }; run(lines, std::io::BufWriter::new(stdout.lock())); }