fn run() { input! { n: usize, } assert!(n <= 14); type Map = std::collections::BTreeMap; let mut dp = Map::new(); dp.insert((vec![0], vec![n + 1]), 1u64); for i in 1..=n { let mut next = Map::new(); for ((lis, lds), way) in dp { for j in 1..=i { let mut lis = lis.clone(); let mut lds = lds.clone(); lis[1..] .iter_mut() .chain(lds[1..].iter_mut()) .for_each(|v| { if *v >= j { *v += 1; } }); if let Some(x) = lis.iter().position(|p| j < *p) { lis[x] = j; } else { lis.push(j); } if let Some(x) = lds.iter().position(|p| j > *p) { lds[x] = j; } else { lds.push(j); } *next.entry((lis, lds)).or_insert(0) += way; } } dp = next; } let ans = dp .iter() .filter(|(k, _)| k.0.len() - 1 + k.1.len() - 1 == n) .map(|p| *p.1) .sum::(); println!("{}", ans % 998_244_353); } fn main() { run(); } // ---------- begin input macro ---------- // reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 #[macro_export] macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } #[macro_export] macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } #[macro_export] macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // ---------- end input macro ----------