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, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

const MOD: i64 = 1e9 as i64 + 7;

fn main() {
    let (n, k): (usize, usize) = read();

    let mut dp: Vec<Vec<Vec<i64>>> = vec![vec![vec![0; 2]; n+1]; n+1];
    dp[n][0][0] = 1;
    for i in (1..n+1).rev() {
        for j in (0..n+1).rev() {
            for k in 0..2 {
                let base = dp[i][j][k];
                if base == 0 {
                    continue
                }
                if j >= 1 && k == 0 {
                    dp[i][j-1][0] += base;
                    dp[i][j-1][0] %= MOD;
                }

                dp[i-1][j][0] += base;
                dp[i-1][j][0] %= MOD;

                dp[i-1][j+1][1] += base;
                dp[i-1][j+1][1] %= MOD;
            }
        }
    }

    let mut ans = (dp[1][n-k][0] + dp[1][n-k][1]) % MOD;
    for x in 1..n-k {
        ans *= 2;
        ans %= MOD;
    }
    println!("{}", ans);
}