// ---------- begin ModInt ---------- mod modint { #[allow(dead_code)] pub struct Mod; impl ConstantModulo for Mod { const MOD: u32 = 1_000_000_007; } #[allow(dead_code)] pub struct StaticMod; static mut STATIC_MOD: u32 = 0; impl Modulo for StaticMod { fn modulo() -> u32 { unsafe { STATIC_MOD } } } #[allow(dead_code)] impl StaticMod { pub fn set_modulo(p: u32) { unsafe { STATIC_MOD = p; } } } use std::marker::*; use std::ops::*; pub trait Modulo { fn modulo() -> u32; } pub trait ConstantModulo { const MOD: u32; } impl Modulo for T where T: ConstantModulo, { fn modulo() -> u32 { T::MOD } } pub struct ModInt(pub u32, PhantomData); impl Clone for ModInt { fn clone(&self) -> Self { ModInt::new_unchecked(self.0) } } impl Copy for ModInt {} impl Add for ModInt { type Output = ModInt; fn add(self, rhs: Self) -> Self::Output { let mut d = self.0 + rhs.0; if d >= T::modulo() { d -= T::modulo(); } ModInt::new_unchecked(d) } } impl AddAssign for ModInt { fn add_assign(&mut self, rhs: Self) { *self = *self + rhs; } } impl Sub for ModInt { type Output = ModInt; fn sub(self, rhs: Self) -> Self::Output { let mut d = self.0 - rhs.0; if d >= T::modulo() { d += T::modulo(); } ModInt::new_unchecked(d) } } impl SubAssign for ModInt { fn sub_assign(&mut self, rhs: Self) { *self = *self - rhs; } } impl Mul for ModInt { type Output = ModInt; fn mul(self, rhs: Self) -> Self::Output { let v = self.0 as u64 * rhs.0 as u64 % T::modulo() as u64; ModInt::new_unchecked(v as u32) } } impl MulAssign for ModInt { fn mul_assign(&mut self, rhs: Self) { *self = *self * rhs; } } impl Neg for ModInt { type Output = ModInt; fn neg(self) -> Self::Output { if self.0 == 0 { Self::zero() } else { Self::new_unchecked(T::modulo() - self.0) } } } impl std::fmt::Display for ModInt { fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result { write!(f, "{}", self.0) } } impl std::fmt::Debug for ModInt { fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result { write!(f, "{}", self.0) } } impl std::str::FromStr for ModInt { type Err = std::num::ParseIntError; fn from_str(s: &str) -> Result { let val = s.parse::()?; Ok(ModInt::new(val)) } } impl From for ModInt { fn from(val: usize) -> ModInt { ModInt::new_unchecked((val % T::modulo() as usize) as u32) } } impl From for ModInt { fn from(val: u64) -> ModInt { ModInt::new_unchecked((val % T::modulo() as u64) as u32) } } impl From for ModInt { fn from(val: i64) -> ModInt { let m = T::modulo() as i64; ModInt::new((val % m + m) as u32) } } #[allow(dead_code)] impl ModInt { pub fn new_unchecked(d: u32) -> Self { ModInt(d, PhantomData) } pub fn zero() -> Self { ModInt::new_unchecked(0) } pub fn one() -> Self { ModInt::new_unchecked(1) } pub fn is_zero(&self) -> bool { self.0 == 0 } } #[allow(dead_code)] impl ModInt { pub fn new(d: u32) -> Self { ModInt::new_unchecked(d % T::modulo()) } pub fn pow(&self, mut n: u64) -> Self { let mut t = Self::one(); let mut s = *self; while n > 0 { if n & 1 == 1 { t *= s; } s *= s; n >>= 1; } t } pub fn inv(&self) -> Self { assert!(self.0 != 0); self.pow(T::modulo() as u64 - 2) } } } // ---------- end ModInt ---------- // ---------- begin Precalc ---------- mod precalc { use super::modint::*; #[allow(dead_code)] pub struct Precalc { inv: Vec>, fact: Vec>, ifact: Vec>, } #[allow(dead_code)] impl Precalc { pub fn new(n: usize) -> Precalc { let mut inv = vec![ModInt::one(); n + 1]; let mut fact = vec![ModInt::one(); n + 1]; let mut ifact = vec![ModInt::one(); n + 1]; for i in 2..(n + 1) { fact[i] = fact[i - 1] * ModInt::new_unchecked(i as u32); } ifact[n] = fact[n].inv(); if n > 0 { inv[n] = ifact[n] * fact[n - 1]; } for i in (1..n).rev() { ifact[i] = ifact[i + 1] * ModInt::new_unchecked((i + 1) as u32); inv[i] = ifact[i] * fact[i - 1]; } Precalc { inv: inv, fact: fact, ifact: ifact, } } pub fn inv(&self, n: usize) -> ModInt { assert!(n > 0); self.inv[n] } pub fn fact(&self, n: usize) -> ModInt { self.fact[n] } pub fn ifact(&self, n: usize) -> ModInt { self.ifact[n] } pub fn perm(&self, n: usize, k: usize) -> ModInt { if k > n { return ModInt::zero(); } self.fact[n] * self.ifact[n - k] } pub fn comb(&self, n: usize, k: usize) -> ModInt { if k > n { return ModInt::zero(); } self.fact[n] * self.ifact[k] * self.ifact[n - k] } } } // ---------- end Precalc ---------- use modint::*; type M = ModInt; // ---------- begin karatsuba multiplication ---------- fn karatsuba(a: &[T], b: &[T], c: &mut [T], zero: T, buf: &mut [T]) where T: std::marker::Copy + std::ops::Add + std::ops::Sub + std::ops::Mul + { assert!(a.len() == b.len()); let n = a.len(); if n <= 16 { for (i, a) in a.iter().enumerate() { for (c, b) in c[i..].iter_mut().zip(b) { *c = *c + *a * *b; } } return; } if n & 1 == 1 { karatsuba(&a[1..], &b[1..], &mut c[2..], zero, buf); let x = a[0]; let y = b[0]; c[0] = c[0] + x * y; for ((c, a), b) in c[1..].iter_mut().zip(&a[1..]).zip(&b[1..]) { *c = *c + x * *b + *a * y; } return; } let m = n / 2; let (fa, ta) = a.split_at(m); let (fb, tb) = b.split_at(m); karatsuba(fa, fb, &mut c[..n], zero, buf); karatsuba(ta, tb, &mut c[n..], zero, buf); let (x, buf) = buf.split_at_mut(m); let (y, buf) = buf.split_at_mut(m); let (z, buf) = buf.split_at_mut(n); z.iter_mut().for_each(|z| *z = zero); let xpq = x.iter_mut().zip(fa).zip(ta); let yrs = y.iter_mut().zip(fb).zip(tb); for (((x, p), q), ((y, r), s)) in xpq.zip(yrs) { *x = *p + *q; *y = *r + *s; } karatsuba(x, y, z, zero, buf); for ((z, p), q) in z.iter_mut().zip(&c[..n]).zip(&c[n..]) { *z = *z - (*p + *q); } for (c, z) in c[m..].iter_mut().zip(z) { *c = *c + *z; } } pub fn multiply(a: &[T], b: &[T], zero: T) -> Vec where T: std::marker::Copy + std::ops::Add + std::ops::Sub + std::ops::Mul + { assert!(!a.is_empty() && !b.is_empty()); let mut i = 0; let mut j = 0; let mut ans = vec![zero; a.len() + b.len() - 1]; let mut buf = vec![zero; 4 * a.len().min(b.len())]; let mut c = Vec::with_capacity(2 * a.len().min(b.len())); while i < a.len() && j < b.len() { let x = a.len() - i; let y = b.len() - j; let z = x.min(y); c.clear(); c.resize(2 * z, zero); karatsuba(&a[i..(i + z)], &b[j..(j + z)], &mut c, zero, &mut buf); for (ans, c) in ans[(i + j)..].iter_mut().zip(c.iter()) { *ans = *ans + *c; } if x <= y { j += z; } else { i += z; } } ans.truncate(a.len() + b.len() - 1); ans } // ---------- end karatsuba multiplication ---------- fn inverse(a: &[M], n: usize) -> Vec { assert!(a[0].0 > 0); let mut b = vec![a[0].inv(); 1]; let mut k = 1; while k < n { k *= 2; let c = multiply(&b, &b, M::zero()); let x = a.iter().take(k).cloned().collect::>(); let y = multiply(&x, &c, M::zero()); b.resize(k, ModInt::zero()); for (b, y) in b.iter_mut().zip(y) { *b = *b + *b - y; } } b } fn run() { let mut s = String::new(); use std::io::*; std::io::stdin().read_to_string(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let k: usize = it.next().unwrap().parse().unwrap(); let n: usize = it.next().unwrap().parse().unwrap(); let mut a = vec![M::zero(); 100_000 + 1]; a[0] = M::one(); for _ in 0..n { let x: usize = it.next().unwrap().parse().unwrap(); a[x] = -ModInt::one(); } let inv = inverse(&a, k + 1); println!("{}", inv[k].0); } fn main() { run(); }