#![allow(unused_imports)] #![allow(non_snake_case)] use std::cmp::*; use std::collections::*; use std::io::Write; #[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 print_array(array: &Vec) { println!( "{}", array .iter() .map(|ref x| x.to_string()) .collect::>() .join(" ") ); } fn query(a: &BTreeSet, cache: &HashMap, i32>) -> i32 { if cache.contains_key(a) { return cache[a]; } let a = a.into_iter().map(|x| x + 1).collect::>(); println!("? {}", a.len()); print_array(&a); let ret = read::(); ret } fn main() { let n = read::(); let mut decided: BTreeSet = vec![0, 1].into_iter().collect::>(); let mut not_decided = (2..n).collect::>(); let mut cache = HashMap::new(); loop { if query(&decided, &cache) == 1 { break; } let (ok, ng) = binary_search(0, not_decided.len(), |x| { if x == 0 { return true; } if x == not_decided.len() { return false; } let mut query_numbers = not_decided.iter().cloned().take(x).collect::>(); for &num in decided.iter() { query_numbers.insert(num); } let ret = query(&query_numbers, &cache); cache.insert(query_numbers, ret); ret == 0 }); decided.insert(not_decided[ok]); not_decided.remove(ok); debug!(ok, decided); if not_decided.is_empty() { break; } } let mut hojuu = false; if decided.len() == 2 { hojuu = true; decided.insert(2); } decided.remove(&0); let mut zero_needed = false; if query(&decided, &cache) == 0 { zero_needed = true; } decided.insert(0); decided.remove(&1); if query(&decided, &cache) == 0 { decided.insert(1); } if !zero_needed { decided.remove(&0); } if hojuu { decided.remove(&2); } let decided = decided.iter().map(|&x| x + 1).collect::>(); println!("! {}", decided.len()); print_array(&decided); } 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() } fn binary_search(lb: usize, ub: usize, mut criterion: F) -> (usize, usize) where F: FnMut(usize) -> bool, { let mut ok = lb; let mut ng = ub; while ng - ok > 1 { let mid = (ng + ok) / 2; if criterion(mid) { ok = mid; } else { ng = mid; } } (ok, ng) }