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: Accepted)

#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

const int MOD = 1000000007;

inline void add(int &a, int b) {
    a += b;
    if (a >= MOD) {
       a -= MOD;
   }
}

inline void sub(int &a, int b) {
    a -= b;
    if (a < 0) {
       a += MOD;
   }
}

inline int mul(int a, int b) {
    return (long long) a * b % MOD;
}

inline int power(int a, int b) {
    int res = 1;

    while (b > 0) {
        if (b & 1) res = mul(res, a);
        b >>= 1;
        a = mul(a, a);
    }

    return res;
}

inline int inverse(int x) {
    return power(x, MOD - 2);
}

const int MX = 3010;
ll inv[MX], fact[MX], ifact[MX];

void init() {
    inv[1] = 1;
    for (int i = 2; i < MX; ++i) {
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
    }
    fact[0] = ifact[0] = 1;
    for (int i = 1; i < MX; ++i) {
        fact[i] = fact[i-1] * i % MOD;
        ifact[i] = ifact[i-1] * inv[i] % MOD;
    }
}

ll comb(int n, int r) {
    if (n < 0 || r < 0 || r > n) return 0;
    return fact[n] * ifact[r] % MOD * ifact[n - r] % MOD;
}

int main() {
    int N; cin >> N;
    init();
    string s; cin >> s;
    vi vec;
    vec.pb(0);

    rep(i, N-1) {
        if (s[i] == '<') {
            vec.pb(i + 1);
        }
    }
    vec.pb(N);

    vector<ll> dp(vec.size());

    dp[0] = 1;

    rep(i, vec.size()) {
        rep(j, i) {
            ll way = dp[j] * ifact[vec[i] - vec[j]] % MOD;
            if ((i - j) % 2 == 0) {
                dp[i] -= way;
            } else {
                dp[i] += way;
            }
            dp[i] %= MOD;
            if (dp[i] < 0) dp[i] += MOD;
        }
    }

    cout << dp.back() * fact[N] % MOD << endl;

    return 0;
}