#[doc = " https://github.com/hatoo/competitive-rust-snippets"] #[allow(unused_imports)] use std::cmp::{max, min, Ordering}; #[allow(unused_imports)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; #[allow(unused_imports)] use std::io::{stdin, stdout, BufWriter, Write}; #[allow(unused_imports)] use std::iter::FromIterator; mod util { use std::fmt::Debug; use std::io::{stdin, stdout, BufWriter, StdoutLock}; use std::str::FromStr; #[allow(dead_code)] pub fn line() -> String { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.trim().to_string() } #[allow(dead_code)] pub fn chars() -> Vec { line().chars().collect() } #[allow(dead_code)] pub fn gets() -> Vec where ::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse().unwrap()) .collect() } #[allow(dead_code)] pub fn with_bufwriter) -> ()>(f: F) { let out = stdout(); let writer = BufWriter::new(out.lock()); f(writer) } } #[allow(unused_macros)] macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; } #[allow(unused_macros)] macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } } const BIG_STACK_SIZE: bool = true; #[allow(dead_code)] fn main() { use std::thread; if BIG_STACK_SIZE { thread::Builder::new() .stack_size(32 * 1024 * 1024) .name("solve".into()) .spawn(solve) .unwrap() .join() .unwrap(); } else { solve(); } } #[allow(dead_code)] pub fn gcd(a: u64, b: u64) -> u64 { if b == 0 { a } else { gcd(b, a % b) } } #[allow(dead_code)] pub fn lcm(a: u64, b: u64) -> u64 { a / gcd(a, b) * b } #[allow(dead_code)] #[doc = " (gcd, x, y)"] pub fn extgcd(a: i64, b: i64) -> (i64, i64, i64) { if b == 0 { (a, 1, 0) } else { let (gcd, x, y) = extgcd(b, a % b); (gcd, y, x - (a / b) * y) } } #[allow(dead_code)] #[doc = " x ^ n % m"] pub fn mod_pow(x: u64, n: u64, m: u64) -> u64 { let mut res = 1; let mut x = x % m; let mut n = n; while n > 0 { if n & 1 == 1 { res = (res * x) % m; } x = (x * x) % m; n >>= 1; } res } #[allow(dead_code)] pub fn mod_inverse(a: u64, m: u64) -> u64 { let (_, x, _) = extgcd(a as i64, m as i64); ((m as i64 + x) as u64 % m) % m } #[allow(dead_code)] pub fn fact_table(len: usize, m: u64) -> Vec { let mut res = vec![1; len + 1]; for i in 1..len + 1 { res[i] = (i as u64 * res[i - 1]) % m; } res } #[allow(dead_code)] #[doc = " Factorial and Inverse factorial table"] pub fn fact_inv_table(size: usize, m: u64) -> (Vec, Vec) { let mut fact = vec![1; size]; let mut fact_inv = vec![1; size]; for i in 2..size { fact[i] = fact[i - 1] * i as u64 % m; fact_inv[i] = m - ((m / i as u64) * fact_inv[(m % i as u64) as usize] % m); } for i in 1..size { fact_inv[i] = fact_inv[i - 1] * fact_inv[i] % m; } (fact, fact_inv) } #[allow(dead_code)] pub fn mod_fact(n: u64, p: u64, fact: &[u64]) -> (u64, u64) { if n == 0 { (1, 0) } else { let (a, b) = mod_fact(n / p, p, fact); let pow = b + n / p; if n / p % 2 != 0 { (a * (p - fact[(n % p) as usize]) % p, pow) } else { (a * fact[(n % p) as usize] % p, pow) } } } #[allow(dead_code)] #[doc = " C(n, k) % p"] pub fn mod_comb(n: u64, k: u64, p: u64, fact: &[u64]) -> u64 { if n < k { 0 } else { let (a1, e1) = mod_fact(n, p, fact); let (a2, e2) = mod_fact(k, p, fact); let (a3, e3) = mod_fact(n - k, p, fact); if e1 > e2 + e3 { 0 } else { a1 * mod_inverse(a2 * a3 % p, p) % p } } } #[allow(dead_code)] #[doc = " H(n, k) % p"] pub fn mod_comb_repetition(n: u64, k: u64, p: u64, fact: &[u64]) -> u64 { mod_comb(n - 1 + k, n - 1, p, fact) } #[allow(dead_code)] pub const M: u64 = 1_000_000_007; fn solve() { let fact = fact_table(100000, M); let (n, k) = get!(usize, usize); if k == 0 { println!("{}", fact[n]); return; } let mut xs = get!(u64;;); xs.sort(); if !xs.windows(2).all(|w| w[0] | w[1] == w[1]) || 1 << n < xs[k - 1] { println!("0"); return; } xs.insert(0, 0); let ans = xs .windows(2) .map(|w| { let l = (w[0] ^ w[1]).count_ones(); fact[l as usize] }).fold(1, |a, b| a * b % M); let rest = fact[n - xs[k].count_ones() as usize]; let ans = ans * rest % M; println!("{}", ans); }