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 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

#define POS(i,j) ((i)*n+(j))

const int mod=1000000007;

int *fact=NULL;
int *iFact=NULL;
void init(const int n){
  fact=(int *)calloc(n+1,sizeof(int));
  fact[0]=1;
  int i;
  for(i=1;i<=n;i++) fact[i]=(int64)i*fact[i-1]%mod;
  int t=1;
  int a=fact[n];
  while(a>1){
    t=(int64)t*(mod-mod/a)%mod;
    a=mod%a;
  }
  iFact=(int *)calloc(n+1,sizeof(int));
  iFact[n]=t;
  for(i=n-1;i>=0;i--) iFact[i]=(int64)(i+1)*iFact[i+1]%mod;
}

int comb(int n,int k){
  if(!(0<=k && k<=n)) return 0;
  return (int64)fact[n]*iFact[n-k]%mod*iFact[k]%mod;
}

int calc(int l,int r,char *s,int n,int *dp){
  if(l>=r) return 1;
  if(dp[POS(l,r)]) return dp[POS(l,r)];
  int local=0;
  if(s[l]=='>') local+=calc(l+1,r,s,n,dp);
  if(s[r-1]=='<') local=(local+calc(l,r-1,s,n,dp))%mod;
  for(int i=l;i<r-1;i++){
    if(s[i]=='<' && s[i+1]=='>'){
      local=(local+(int64)calc(l,i,s,n,dp)*calc(i+2,r,s,n,dp)%mod*comb(r-l,i+1-l))%mod;
    }
  }
  dp[POS(l,r)]=local;
  return local;
}

void run(void){
  int n;
  scanf("%d",&n);
  init(n);
  char *s=(char *)calloc(n,sizeof(char));
  scanf("%s",s);
  int *dp=(int *)calloc((n+1)*(n+1),sizeof(int));
  int ans=calc(0,n-1,s,n,dp);
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}