const MOD: usize = 1e9 as usize + 7; fn lower_bound(target: usize, vals: &Vec) -> usize { let mut upper = vals.len(); let mut lower = 0usize; while upper > lower { let middle = (upper + lower) / 2; if vals[middle] < target { lower = middle+1; } else { upper = middle; } } upper } fn upper_bound(target: usize, vals: &Vec) -> usize { let mut upper = vals.len(); let mut lower = 0usize; while upper > lower { let middle = (upper + lower) / 2; if vals[middle] <= target { lower = middle+1; } else { upper = middle; } } upper } fn main() { let mut nk = String::new(); std::io::stdin().read_line(&mut nk).ok(); let nk: Vec = nk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = nk[0]; let k = nk[1]; let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let a: Vec = a.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); if a.iter().any(|&v| v > k) { println!("0"); return; } let mut uppers = a.iter().filter(|&&v| v > k/2).copied().collect::>(); let mut lowers = a.iter().filter(|&&v| v <= k/2).copied().collect::>(); if uppers.len() > n/2 { println!("0"); return; } uppers.sort(); uppers.reverse(); lowers.sort(); let mut result = 1usize; for i in 0..uppers.len() { let left = upper_bound(k-uppers[i], &lowers); if left <= i { println!("0"); return; } result *= left - i; result %= MOD; } let limit = lowers.len() - uppers.len(); for i in 0..limit/2 { result *= limit-2*i-1; result %= MOD; } println!("{}", result); }