pub mod io { use std::io::{BufRead, ErrorKind}; pub fn scan(r: &mut R) -> String { let mut res = Vec::new(); loop { let buf = match r.fill_buf() { Ok(buf) => buf, Err(e) if e.kind() == ErrorKind::Interrupted => continue, Err(e) => panic!(e), }; let (done, used, buf) = { match buf.iter().position(u8::is_ascii_whitespace) { Some(i) => (i | res.len() > 0, i + 1, &buf[..i]), None => (buf.is_empty(), buf.len(), buf), } }; res.extend_from_slice(buf); r.consume(used); if done { return String::from_utf8(res).unwrap(); } } } #[macro_export] macro_rules! scan { ($r:expr) => (io::scan(&mut $r)); ($r:expr, $($t:ty),*) => (($(scan!($r).parse::<$t>().unwrap()),*)); } } use std::io::Write; fn main() { let stdin = std::io::stdin(); let mut reader = std::io::BufReader::new(stdin.lock()); let (n, m) = scan!(reader, usize, u32); let mut dp = vec![vec![0; n + 1]; n * n + 1]; dp[0][0] = 1; for i in 0..2 * n { let mut ndp = vec![vec![0; n + 1]; n * n + 1]; for (k, dp) in dp.into_iter().enumerate().rev() { for (j, now) in dp[0..=n.min(i)].iter().enumerate().rev() { // add 0 if k + j <= n * n { let next = &mut ndp[k + j][j]; *next += now; if *next >= m { *next -= m; } } // add 1 if j + 1 <= n && i - j > j { let next = &mut ndp[k][j + 1]; *next += now; if *next >= m { *next -= m; } } } } dp = ndp; } let stdout = std::io::stdout(); let mut writer = std::io::BufWriter::new(stdout.lock()); for dp in dp { writeln!(writer, "{}", dp.last().unwrap()).ok(); } }