// No.361 (https://yukicoder.me/problems/no/361) // 門松ゲーム2 #![allow(unreachable_code)] fn main() { let (l, d) = input(); let mut dp = std::collections::HashMap::new(); for i in 1..6 { dp.insert(i, 0); } if grundy(l, d, &mut dp) == 0 { println!("matsu") } else { println!("kado") } // println!("{:#?}", dp) } fn grundy(l: usize, d: usize, dp: &mut std::collections::HashMap) -> usize { if let Some(&v) = dp.get(&l) { v } else { let mut bit = 1; for i in 1..l { for j in i + 1..l { if i + j >= l { break; } let k = l - i - j; if k <= j { break; } if k - i > d { continue; } if grundy(i, d, dp) == 0 && grundy(j, d, dp) == 0 && grundy(k, d, dp) == 0 { bit *= 0 } } } let rt = bit ^ 1; dp.insert(l, rt); rt } } #[inline(always)] fn input() -> (usize, usize) { let e = read_line::(); (e[0], e[1]) } #[inline(always)] fn read_line() -> Vec where T: std::str::FromStr, ::Err: std::fmt::Debug, { let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); s.trim() .split_whitespace() .map(|c| T::from_str(c).unwrap()) .collect() }