use std::collections::BTreeMap; use proconio::input; fn main() { let answer = match solve() { Some(value) => format!( "{}\n{}", value.len(), value .iter() .map(|val| val.to_string()) .collect::>() .join(" ") ), None => "-1".to_string(), }; println!("{}", answer); } fn solve() -> Option> { input! { n: usize, aa: [usize; n], } let mut pool = BTreeMap::from([(0_usize, 0_usize)]); for (i, &a) in aa.iter().enumerate() { let next_pool = pool .iter() .map(|(&value, &bits)| (value ^ a, bits | 1 << i)) .collect::>(); for &(next_value, next_bits) in &next_pool { if pool.contains_key(&next_value) { let ans_bits = pool[&next_value] ^ next_bits; return Some( (0_usize..) .take_while(|&i| ans_bits >> i != 0) .filter(|&i| ans_bits >> i & 1 == 1) .map(|i| i + 1) .collect(), ); } } pool.extend(next_pool); } None }