Source Code
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define fast ios::sync_with_stdio(false);cin.tie(0);
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef tree<int, null_type, less<int>,
        rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int mod = 1e9 + 7;

ll dp[1001][2005][2];
int n;
int calc(int idx, int cnt, bool done){
	if(idx > n || cnt < 0) return 0;
	if(idx == n){
		if(!cnt && done)return 1;
		else return 0;
		}
	if(dp[idx][cnt+1000][done] != -1) return dp[idx][cnt+1000][done];
	ll &ret = dp[idx][cnt+1000][done];
	ret = 0;
	ret = (ret + calc(idx+1, cnt+1, done))%mod; 
	ret = (ret + calc(idx+1, cnt-1, done))%mod;
	if(!done) ret = (ret + calc(idx + 5, cnt+1, 1))%mod;
	return ret;
	}

int main(){
	fast
	cin>>n;
	memset(dp,-1,sizeof(dp));
	
	ll ans = 0;
	
	ans = (ans + calc(5,1,1))%mod;
	ans = (ans + calc(1,1,0))%mod;
	
	
	cout<<ans<<endl;
	
return 0;
}
Copy
Bracket Sequence Bahaa
GNU G++17
38 ms
32.5 MB
Wrong Answer