Problem:
Score : 100 points

Problem Statement

Let N be a positive integer.
You are given a string s of length N - 1, consisting of < and >.

Find the number of permutations (p_1, p_2, \ldots, p_N) of (1, 2, \ldots, N) that satisfy the following condition, modulo 10^9 + 7:

For each i (1 \leq i \leq N - 1), p_i < p_{i + 1} if the i-th character in s is <, and p_i > p_{i + 1} if the i-th character in s is >.

Constraints

N is an integer.

2 \leq N \leq 3000

s is a string of length N - 1.

s consists of < and >.

Input

Input is given from Standard Input in the following format:

N
s

Output

Print the number of permutations that satisfy the condition, modulo 10^9 + 7.

Sample Input 1

4
<><

Sample Output 1

5

There are five permutations that satisfy the condition, as follows:

(1, 3, 2, 4)

(1, 4, 2, 3)

(2, 3, 1, 4)

(2, 4, 1, 3)

(3, 4, 1, 2)

Sample Input 2

5
<<<<

Sample Output 2

1

There is one permutation that satisfies the condition, as follows:

(1, 2, 3, 4, 5)

Sample Input 3

20
>>>><>>><>><>>><<>>

Sample Output 3

217136290

Be sure to print the number modulo 10^9 + 7.

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

#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
 
#define int long long int
#define ld long double
#define mod 1000000007 
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define forn(i,s, e) for (int i = s; i <= e; i++)
#define fornd(i,s, e) for (int i = s ; i >= e; i--)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define print(x) for(auto el: x) cout<<el<<" ";cout<<"\n"
#define PSET(x,y) fixed<<setprecision(y)<<x
// #define bits(x) __builtin_popcount(x)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
// void fileio()
// {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
// }
 
 
template <typename T> 
void swap(T& a, T& b){
    T temp = a;
    a = b;
    b = temp;
}
void selfadd(int& a, int b){
    a = a+b;
    if(a>=mod)
        a = a-mod;
}
void selfsub(int& a, int b){
    a = a-b+mod;
    if(a>=mod)
        a = a-mod;
}  
const int N = 200005; 
 
int n;
string s;
int dp[3003][3003];
int visited[3003];

int rec(int index,int here){
    if(index==n-1){
        return 1;
    }
    if(dp[index][here] != -1)
        return dp[index][here];

    int ans = 0;
    visited[here] = 1;
    if(s[index] == '<'){
        for(int i = here+1; i<=n;i++){
            if(visited[i] == 0){
                // visited[i]=1;
                selfadd(ans, rec(index+1, i));
                // visited[i] = 0;    
            }
        }
    }else{
        for(int i = here-1; i > 0 ; i--){
            if(visited[i] == 0){
                // visited[i]=1;
                selfadd(ans, rec(index+1, i));
                // visited[i] = 0;    
            }    
        }
    }
    visited[here] = 0;

    return dp[index][here] = ans;
}
 
void solve(){
    
    cin>>n;
    cin>>s;
    memset(dp,-1,sizeof(dp));

    int ans = 0;
    for(int i=1;i<=n;i++){
        memset(visited,0,sizeof(visited));
        // visited[i] = 1;
        selfadd(ans, rec(0,i));
        // visited[i] = 0;
    }
    cout<<ans<<endl;

}
 
int32_t main()
{
    // fileio();
    fast;
    // int t;
    // cin>>t;
    // for(int y=1;y<=t;y++)
    {
        // cout<<"Case #"<<y<<": ";
        solve();
    }
    return 0;
}