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 Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

/*
[ ( ^ _ ^ ) ]
*/

// problem: atc/dp_t

// package atc.t;

import java.io.*;
import java.util.*;


public class Main {
    int INF = (int)1e9;
    long MOD = 1000000007;

    char lt = '>';
    int n;
    HashMap<String, Long> mp;

    long go(int x, int lst, boolean[] vis, char[] s) {
        if(x>=n) {
            return 1;
        }
        String k = x +" "+lst;
        for(boolean v: vis) k = k + (v?1:0);
        if(mp.containsKey(k)) {
            return mp.get(k);
        }
        long rs = 0;
        for(int i=0; i<n; i++) {
            if(!vis[i]) {
                if(s[x]==lt && lst > i) {
                    vis[i] = true;
                    rs += go(x+1, i, vis, s);
                    vis[i] = false;
                } else if(s[x]!=lt && i > lst) {
                    vis[i] = true;
                    rs += go(x+1, i, vis, s);
                    vis[i] = false;
                }
                if(rs >= MOD) rs %= MOD;
            }
        }
        mp.put(k, rs);
        return rs;
    }

    void solve(InputReader in, PrintWriter out) throws IOException {
        n = in.nextInt();
        char[] s = (" "+in.next().trim()).toCharArray();
        // long rs = 0;
        // boolean[] vis = new boolean[n];
        // mp = new HashMap<>();
        // for(int i=0; i<n; i++) {
        //     vis[i] = true;
        //     rs += go(1, i, vis, s);
        //     vis[i] = false;
        //     if(rs >= MOD) rs -= MOD;
        // }
        // out.println(rs);
        // show("", s);
        long[][] dp = new long[n][n];
        dp[0][0] = 1;
        for(int i=1; i<n; i++) {
            for(int j=0; j<=i; j++) {
                if(s[i]==lt) {
                    dp[i][j] = dp[i-1][i-1] - (j>0?dp[i-1][j-1]:0);
                    dp[i][j] = (dp[i][j]%MOD + MOD)%MOD;
                } else {
                    if(j>0) dp[i][j] = dp[i-1][j-1];
                }
                if(j>0) dp[i][j] = (dp[i][j] + dp[i][j-1])%MOD;
            }
            // show("", dp[i]);
        }
        out.println(dp[n-1][n-1]);
    }
    

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new Main().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }
    
    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
    
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}