#![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 dist(mut start: i128, bound: i32) -> i128 { let mut ret = 0; for _ in 0..bound { ret += start; start /= 2; } ret } fn main() { let d = read::(); let mut max_bound = 0; while d > 2i128.pow(max_bound) { max_bound += 1; } debug!(max_bound); let criterion = |mid, bound: i32| dist(mid, bound) <= d; for bound in (1..max_bound + 1).rev() { let (ok, _) = binary_search(1, 100000_00000_00000_001, bound as i32, criterion); if dist(ok, bound as i32) == d { println!("{}", ok); return; } } } fn read() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn binary_search(lb: i128, ub: i128, bound: i32, criterion: F) -> (i128, i128) where F: Fn(i128, i32) -> bool, { assert_eq!(criterion(lb, bound), true); assert_eq!(criterion(ub, bound), false); let mut ok = lb; let mut ng = ub; while ng - ok > 1 { let mid = (ng + ok) / 2; if criterion(mid, bound) { ok = mid; } else { ng = mid; } } (ok, ng) }