Problem:
Score : 1200 points

Problem Statement

Snuke has decided to play with N cards and a deque (that is, a double-ended queue).
Each card shows an integer from 1 through N, and the deque is initially empty.

Snuke will insert the cards at the beginning or the end of the deque one at a time, in order from 1 to N.
Then, he will perform the following action N times: take out the card from the beginning or the end of the deque and eat it.

Afterwards, we will construct an integer sequence by arranging the integers written on the eaten cards, in the order they are eaten. Among the sequences that can be obtained in this way, find the number of the sequences such that the K-th element is 1. Print the answer modulo 10^{9} + 7.

Constraints

1 ≦ K ≦ N ≦ 2{,}000

Input

The input is given from Standard Input in the following format:

N K

Output

Print the answer modulo 10^{9} + 7.

Sample Input 1

2 1

Sample Output 1

1

There is one sequence satisfying the condition: 1,2. One possible way to obtain this sequence is the following:

Insert both cards, 1 and 2, at the end of the deque.

Eat the card at the beginning of the deque twice.

Sample Input 2

17 2

Sample Output 2

262144

Sample Input 3

2000 1000

Sample Output 3

674286644

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

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    return 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.is_err() || res.ok().unwrap() == 0 || u8b[0] <= ' ' as u8 {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = std::string::String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}
fn parse<T: std::str::FromStr>(s: &str) -> T { s.parse::<T>().ok().unwrap() }

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

const MOD: i64 = 1_000_000_007;

fn powmod(x: i64, mut e: i64, m: i64) -> i64 {
    let mut sum = 1;
    let mut cur = x % m;
    while e > 0 {
        if e % 2 != 0 {
            sum = sum * cur % m;
        }
        cur = cur * cur % m;
        e /= 2;
    }
    sum
}

fn make_dp_table(n: usize) -> Vec<Vec<i64>> {
    let mut dp = vec![Vec::new(); n];
    dp[0] = vec![0; 2 * n];
    for i in 0 .. 2 * n {
        dp[0][i] = 1;
    }
    for i in 1 .. n {
        dp[i] = vec![0; 2 * n - i];
        for j in 0 .. 2 * n - i {
            dp[i][j] = (dp[i - 1][j + 1] + if j > 0 { dp[i][j - 1] } else { 0 })
                % MOD;
        }
    }
    dp
}

fn main() {
    let n = get();
    let k: usize = get::<usize>() - 1;
    let mut tot: i64 = 0;
    let dp = make_dp_table(n);
    if k < n - 1 {
        for m in n - k - 1 .. n {
            let mut tmp = dp[n - m - 1][m + 1 + k - n];
            for i in 0 .. n - k - 2 {
                tmp = tmp * (m - 1 - i) as i64 % MOD;
                tmp = tmp * powmod(i as i64 + 1, MOD - 2, MOD) % MOD; 
            }
            tot += tmp;
            tot %= MOD;
        }
    } else {
        tot = dp[n - 1][0];
    }
    for _ in k + 2 .. n {
        tot = tot * 2 % MOD;
    }
    println!("{}", tot);
}