fn solve(_reader: R, _writer: &mut W) { let mut _scanner = Scanner::new(_reader); #[allow(unused_macros)] macro_rules! scan { ($t:ty) => { _scanner.next::<$t>() }; ($($t:ty),+) => { ($(scan!($t)),+) }; ($t:ty; $n:expr) => {{ let mut vec = Vec::with_capacity($n); for _ in 0..$n { vec.push(scan!($t)); } vec }}; ($t_0:ty, $t_1:ty; $n:expr) => { scan!($t_0 = 0, $t_1 = 1; $n) }; ($t_0:ty, $t_1:ty, $t_2:ty; $n:expr) => { scan!($t_0 = 0, $t_1 = 1, $t_2 = 2; $n) }; ($($t:ty = $i:tt),+; $n:expr) => {{ let mut vecs = ($(Vec::<$t>::with_capacity($n)),+); for _ in 0..$n {$( vecs.$i.push(scan!($t)); )+} vecs }}; } #[allow(unused_macros)] macro_rules! println { () => { writeln!(_writer).unwrap() }; ($fmt:expr) => { writeln!(_writer, $fmt).unwrap() }; ($fmt:expr, $($arg:tt)*) => { writeln!(_writer, $fmt, $($arg)*).unwrap() }; } use std::cmp::{max, min}; let k = scan!(u64); fn noel_chan(x: u64) -> Option { let x = x * 2; let a = f64::sqrt(x as f64) as u64; let b = x / a; if a * b == x && max(a, b) - min(a, b) == 1 { Some(max(a, b)) } else { None } } fn taplis_chan(k: u64, min_cnt0: u64) -> Result<(u64, String), u64> { let mut cnt0 = min_cnt0; let mut comb0 = 2u64.pow(cnt0 as u32); while k % comb0 != 0 || noel_chan(k / comb0).is_none() { cnt0 += 1; comb0 *= 2; } let cnt1 = noel_chan(k / comb0).unwrap(); let n = cnt0 + cnt1; if n < 1 || 30 < n { return Err(cnt0); } let mut b_str = String::new(); for _ in 0..cnt0 { b_str += "0 "; } for _ in 0..cnt1 { b_str += "1 "; } Ok((n, b_str)) } let mut min_cnt0 = 0; loop { match taplis_chan(k, min_cnt0) { Ok((n, b_str)) => { println!("{}", n); println!("{}", b_str); return; } Err(cnt_0) => { min_cnt0 = cnt_0 + 1; } } } } fn main() { let stdin = stdin(); let stdout = stdout(); #[cfg(debug_assertions)] let mut writer = stdout.lock(); #[cfg(not(debug_assertions))] let mut writer = BufWriter::new(stdout.lock()); solve(stdin.lock(), &mut writer); writer.flush().unwrap(); } use io::Scanner; use std::io::{stdin, stdout, BufRead, BufWriter, Write}; pub mod io { pub use self::scanner::*; mod scanner { use std::fmt::Debug; use std::io::BufRead; use std::str; use std::str::FromStr; pub struct Scanner { reader: R, buffer: Vec, position: usize, } impl Scanner { pub fn new(reader: R) -> Self { Scanner { reader: reader, buffer: vec![], position: 0 } } pub fn next(&mut self) -> T where T::Err: Debug, { if self.buffer.is_empty() { self.read_line(); } loop { match self.buffer.get(self.position) { Some(&b' ') => self.position += 1, Some(&b'\n') => self.read_line(), Some(_) => break, None => panic!("EOF reached"), } } let start = self.position; loop { match self.buffer.get(self.position) { Some(&b' ') | Some(&b'\n') | None => break, Some(_) => self.position += 1, } } str::from_utf8(&self.buffer[start..self.position]).unwrap().parse().unwrap() } fn read_line(&mut self) { self.position = 0; self.buffer.clear(); self.reader.read_until(b'\n', &mut self.buffer).unwrap(); } } } }