Problem:
Score : 800 points

Problem Statement

Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the 0 key, the 1 key and the backspace key.

To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:

The 0 key: a letter 0 will be inserted to the right of the string.

The 1 key: a letter 1 will be inserted to the right of the string.

The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.

Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.

Constraints

1 ≦ N ≦ 5000

1 ≦ |s| ≦ N

s consists of the letters 0 and 1.

Partial Score

400 points will be awarded for passing the test set satisfying 1 ≦ N ≦ 300.

Input

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

N
s

Output

Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7.

Sample Input 1

3
0

Sample Output 1

5

We will denote the backspace key by B. The following 5 ways to press the keys will cause the editor to display the string 0 in the end: 00B, 01B, 0B0, 1B0, BB0. In the last way, nothing will happen when the backspace key is pressed.

Sample Input 2

300
1100100

Sample Output 2

519054663

Sample Input 3

5000
01000001011101000100001101101111011001000110010101110010000

Sample Output 3

500886057

Solution in C++14 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define int         int64_t
#define ii          pair<int,int>
#define dd          pair<double,double>
#define vi          vector<int>
#define pb          push_back
#define all(x)      (x).begin(), (x).end()
#define checkBit(v, p)      (v&(1LL << p))
#define loop(i,a,b) for(int i = a;i < int(b);i++)
#define x           first
#define y           second
using namespace std;

int inf = 4e18, mod = 1e9+7;

int power(int b, int e){
    if(e == 0) return 1;
    if(e == 1) return b;
    int cur = power(b,e/2);
    return cur * cur % mod * (e%2?b:1) % mod;
}

int32_t main()
{
    ios_base::sync_with_stdio(false); cout << fixed <<setprecision(0);
    int n,sum; cin >> n;
    string s; cin >> s;
    int l = s.size();
    vector<vi> dp(n+1, vi(n+1,0));
    dp[0][0] = 1;
    for(int i=1;i <= n; i++){
        dp[i][0] = 1;
        for(int j = 1;j<=n;j++){
            dp[i][j] = dp[i-1][j] + (i - 1 - (j - 1) * 2 > 0 ? dp[i-1][j-1] : 0);
            dp[i][j] %= mod;
        }
    }
    sum = power(2, (n - l) / 2) * ((n - l) % 2 ? 0 :dp[n][(n - l) / 2]) % mod;
    sum += power(2, (n - l - 1) / 2) * ((n - l - 1) % 2 ? 0 :dp[n - 1][(n - l - 1) / 2]) % mod;
    for(int i = 1;i < n; i++){
        int tmp = 0;
        for(int j = 0; j < i; j++){
            tmp = (tmp + dp[i][j] * power(2,j) % mod) % mod;
        }
        if((n-i-1 - l) % 2 == 0 && (n-i-1 - l) >= 0)
            sum = (sum + tmp * dp[n - i - 1][(n-i-1 - l) / 2] % mod * power(2, (n-i-1 - l) / 2) % mod) % mod;
    }
    cout << sum << endl;
    return 0;
}