#[macro_export] macro_rules! setup { { mut $input:ident: SplitWhitespace $(,)? } => { use std::io::Read; let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).ok(); let mut $input = buf.split_whitespace(); }; } #[macro_export] macro_rules! parse_next { ($str_iter:expr) => { $str_iter.next().unwrap().parse().ok().unwrap() }; } fn main() { setup! { mut input: SplitWhitespace }; let x: i64 = parse_next!(input); let y: i64 = parse_next!(input); let ans = (|| { if !(x == 0 || y == 0 || x.abs() == y.abs()) { return -1; } use std::collections::{HashSet, VecDeque}; let mut queue = VecDeque::new(); let mut visited = HashSet::new(); let mut depth = 0; { let root = (x, y); queue.push_back(root); visited.insert(root); } while !queue.is_empty() { for _ in 0..queue.len() { let (x, y) = match queue.pop_front() { Some(value) => value, None => unreachable!(), }; if x == y { return depth; } let children = vec![(y, x), (x + y, x - y)]; for child in children.into_iter() { if visited.contains(&child) { continue; } queue.push_back(child); visited.insert(child); } } depth += 1; } unreachable!(); })(); println!("{}", ans); }