Problem:
Score : 300 points

Problem Statement

There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step.
He can climb up one or two steps at a time.

However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps.

How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps?
Find the count modulo 1\ 000\ 000\ 007.

Constraints

1 \leq N \leq 10^5

0 \leq M \leq N-1

1 \leq a_1 < a_2 < ... < a_M \leq N-1

Input

Input is given from Standard Input in the following format:

N M
a_1
a_2
.
.
.
a_M

Output

Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007.

Sample Input 1

6 1
3

Sample Output 1

4

There are four ways to climb up the stairs, as follows:

0 \to 1 \to 2 \to 4 \to 5 \to 6

0 \to 1 \to 2 \to 4 \to 6

0 \to 2 \to 4 \to 5 \to 6

0 \to 2 \to 4 \to 6

Sample Input 2

10 2
4
5

Sample Output 2

0

There may be no way to climb up the stairs without setting foot on the broken steps.

Sample Input 3

100 5
1
23
45
67
89

Sample Output 3

608200469

Be sure to print the count modulo 1\ 000\ 000\ 007.

Solution in Rust (1.15.1) (judge verdict: Accepted)

use std::str::FromStr;
use std::io::Read;
use std::ops::Sub;
use std::convert::From;
use std::ops::Div;
use std::ops::Mul;
use std::ops::Add;

const MODULO: u64 = 1_000_000_007;

#[derive(Copy, Clone)]
pub struct M64 {
    v: u64,
}

pub struct CombTable {
    factorial: Vec<M64>,
    fact_inv: Vec<M64>,
}

impl CombTable {
    pub fn new(val: u64) -> Self {
        let n = val as usize;
        let mut v = Vec::with_capacity(n + 1);
        v.push(M64::new(1));
        for i in 0..n {
            let prev = v[i];
            v.push(prev * M64::new((i + 1) as u64));
        }

        let mut vi = vec![M64::new(0); n + 1];
        vi[n] = v[n].pow(MODULO - 2);
        for i in 0..n {
            vi[n - i - 1] = vi[n - i] * M64::new((n - i) as u64);
        }
        CombTable {
            factorial: v,
            fact_inv: vi,
        }
    }

    pub fn comb(&self, n: u64, r: u64) -> M64 {
        let nu = n as usize;
        let ru = r as usize;
        self.factorial[nu] * self.fact_inv[ru] * self.fact_inv[nu - ru]
    }
}

pub trait Modulo {
    fn new(x: u64) -> Self;
    fn pow(&self, n: u64) -> M64;
    fn to_u64(&self) -> u64;
}

impl Modulo for M64 {
    fn new(x: u64) -> Self {
        M64 { v: x }
    }

    fn pow(&self, n: u64) -> M64 {
        let mut remain_multiple_count = n;
        let mut base_square = M64 { v: self.v };
        let mut current = M64 { v: 1 };
        while remain_multiple_count > 0 {
            if remain_multiple_count & 1 == 1 {
                current = current * base_square;
            }
            base_square = base_square * base_square;
            remain_multiple_count /= 2;
        }
        current
    }

    fn to_u64(&self) -> u64 {
        self.v
    }
}

impl Div for M64 {
    type Output = Self;
    fn div(self, other: Self) -> Self::Output {
        self * other.pow(MODULO - 2)
    }
}

impl Mul for M64 {
    type Output = Self;
    fn mul(self, other: Self) -> Self::Output {
        M64 { v: (self.v * other.v) % MODULO }
    }
}

impl Add for M64 {
    type Output = Self;
    fn add(self, other: Self) -> Self::Output {
        M64 { v: (self.v + other.v) % MODULO }
    }
}

pub trait AsZeroOrigin {
    fn as_zero_origin(self) -> Self;
}

pub trait AsZeroOriginWithMatrix {
    fn as_zero_origin(self) -> Self;
}

impl<T> AsZeroOrigin for Vec<T>
where
    T: Sub<T, Output = T> + From<u8>,
{
    fn as_zero_origin(self) -> Self {
        self.into_iter().map(|i| i - T::from(1)).collect()
    }
}

impl<T> AsZeroOriginWithMatrix for Vec<Vec<T>>
where
    T: Sub<T, Output = T> + From<u8>,
{
    fn as_zero_origin(self) -> Self {
        self.into_iter()
            .map(|v| v.into_iter().map(|i| i - T::from(1)).collect())
            .collect()
    }
}

pub trait Convert<T>
where
    T: FromStr,
{
    fn read_one(&mut self) -> T;
    fn to_vec(&mut self, n: usize) -> Vec<T>;
    fn to_matrix(&mut self, n: usize, m: usize) -> Vec<Vec<T>>;

    fn to_tuples<U>(&mut self, n: usize) -> Vec<(T, U)>
    where
        U: FromStr;
}

impl<'a, T> Convert<T> for ::std::str::SplitWhitespace<'a>
where
    T: FromStr,
{
    fn read_one(&mut self) -> T {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }

    fn to_vec(&mut self, n: usize) -> Vec<T> {
        (0..n)
            .map(|_| self.next().unwrap().parse().ok().unwrap())
            .collect::<Vec<_>>()
    }

    fn to_matrix(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.to_vec(m)).collect::<Vec<_>>()
    }

    fn to_tuples<U>(&mut self, n: usize) -> Vec<(T, U)>
    where
        U: FromStr,
    {
        (0..n)
            .map(|_| {
                let a = self.next().unwrap().parse().ok().unwrap();
                let b = self.next().unwrap().parse().ok().unwrap();
                (a, b)
            })
            .collect::<Vec<_>>()
    }
}

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

trait Count {
    fn count(&self, n: u64) -> M64;
}

impl Count for CombTable {
    fn count(&self, n: u64) -> M64 {
        let mut sum = M64::new(n);
        for r in 2..(n / 2 + 1) {
            sum = sum + self.comb(n - r, r);
        }
        sum
    }
}

fn to_operations(n: u64, v: Vec<u64>) -> Vec<u64> {
    if v.is_empty() {
        return vec![n];
    }

    let mut out = Vec::new();
    out.push(v[0] - 1);
    if v.len() >= 2 {
        for w in v.windows(2) {
            out.push(w[1] - w[0] - 2);
        }
    }
    out.push(n - *v.last().unwrap() - 1);
    out.into_iter().filter(|&x| x > 0).collect()
}

fn evaluate(n: u64, v: Vec<u64>) -> u64 {
    if v.windows(2).any(|w| w[0] + 1 == w[1]) {
        return 0;
    }

    let table = CombTable::new(n);

    to_operations(n, v)
        .into_iter()
        .fold(M64::new(1), |st, x| st * table.count(x))
        .to_u64()
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let n = iter.read_one();
    let m = iter.read_one();
    let v: Vec<u64> = iter.to_vec(m);

    println!("{}", evaluate(n, v));
}