Problem:
Max Score: 1000 Points

Problem Statement

There is a railroad company in Atcoder Kingdom, "Atcoder Railroad".

There are N + 1 stations numbered 0, 1, 2, ..., N along a railway.

Currently, two kinds of train are operated, local and express.

A local train stops at every station, and it takes one minute from station i to i + 1, and vice versa.

An express train only stops at station S_0, S_1, S_2, ..., S_{K-1} (0 = S_0 < S_1 < S_2 < ... < S_{K-1} = N). It takes one minute from station S_i to S_{i + 1}, and vice versa.

But the president of Atcoder Railroad, Semiexp said it is not very convenient so he planned to operate one more kind of train, "semi-express".

The stations where the semi-express stops (This is T_0, T_1, T_2, ..., T_{L-1}, 0 = T_0 < T_1 < T_2 < ... < T_{L-1} = N) have to follow following conditions:

From station T_i to T_{i+1} takes 1 minutes, and vice versa.

The center of Atcoder Kingdom is station 0, and you have to be able to go to station i atmost X minutes.

If the express stops at the station, semi-express should stops at the station.

Print the number of ways of the set of the station where semi-express stops (sequence T).

Since the answer can be large, print the number modulo 10^9 + 7.

Input Format

N K X
S_0 S_1 S_2 ... S_{K-1}

Output Format

Print the number of ways of the set of the station where semi-express stops, mod 10^9 + 7 in one line.

Print \n (line break) in the end.

Constraints

2 ≤ K ≤ 2500.

1 ≤ X ≤ 2500.

S_0 = 0, S_{K-1} = N.

1 ≤ S_{i + 1} - S_i ≤ 10000.

Scoring

Subtask 1 [120 points]

N, K, X ≤ 15.

Subtask 2 [90 points]

K, X ≤ 15.

S_{i + 1} - S_i ≤ 15.

Subtask 3 [260 points]

K, X ≤ 40.

S_{i + 1} - S_i ≤ 40.

Subtask 4 [160 points]

K, X ≤ 300.

S_{i + 1} - S_i ≤ 300.

Subtask 5 [370 points]

There are no additional constraints.

Sample Input 1

7 2 3
0 7

Sample Output 1

55

The set of trains that stops station 0 and 7, and can't satisfy the condition is:

[0, 7], [0, 1, 7], [0, 1, 2, 7], [0, 1, 6, 7], [0, 1, 2, 6, 7], [0, 1, 2, 3, 6, 7], [0, 1, 2, 5, 6, 7], [0, 1, 2, 3, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], 9 ways.

Therefore, the number of ways is 2^6 - 9 = 55.

Solution in Rust (1.15.1) (judge verdict: Runtime Error)

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

const MOD: i64 = 1_000_000_007;

fn is_ok(n: usize, x: usize, prev: &[Vec<usize>]) -> bool {
    let mut dp = vec![0; n + 1];
    dp[0] = 0;
    for i in 1 .. n + 1 {
        let mut mi = 1 << 28;
        for &v in prev[i].iter() {
            mi = min(mi, dp[v] + 1);
        }
        dp[i] = mi;
    }
    println!("prev = {:?}, dp = {:?}", prev, dp);
    dp.iter().all(|&v| v <= x)
}

fn one_segm(len: usize, x: usize) -> i64 {
    let mut tot = 0;
    assert!(len <= 16);
    for bits in 0 .. 1 << (len - 1) {
        let mut prev = vec![Vec::new(); len + 1];
        for i in 0 .. len {
            prev[i + 1].push(i);
            prev[i].push(i + 1);
        }
        prev[0].push(len);
        prev[len].push(0);
        let mut pool = Vec::new();
        pool.push(0);
        for i in 0 .. len - 1 {
            if (bits & 1 << i) != 0 {
                pool.push(i + 1);
            }
        }
        pool.push(len);
        for i in 0 .. pool.len() - 1 {
            prev[pool[i + 1]].push(pool[i]);
            prev[pool[i]].push(pool[i + 1]);
        }
        // bfs
        let mut dist = vec![1 << 28; len + 1];
        let mut que = VecDeque::new();
        que.push_back((0, 0));
        while let Some((v, d)) = que.pop_front() {
            if dist[v] <= d { continue; }
            dist[v] = d;
            for &w in prev[v].iter() {
                que.push_back((w, d + 1));
            }
        }
        if dist.iter().all(|&val| val <= x) {
            tot += 1;
        }
    }
    tot
}

fn solve() {
    let n: usize = get();
    let k: usize = get();
    let x: usize = get();
    let s: Vec<usize> = (0 .. k).map(|_| get()).collect();
    let mut prod = 1;
    for i in 0 .. k - 1 {
        if x >= i {
            prod *= one_segm(s[i + 1] - s[i], x - i);
            prod %= MOD;
        } else {
            prod = 0;
        }
    }
    println!("{}", prod);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}