Programming teacher Dmitry Olegovich is going to propose the following task for one of his tests for students:

You are given a tree T with n vertices, specified by its adjacency matrix a[1... n, 1... n]. What is the output of the following pseudocode?
    
    
      
    used[1 ... n] = {0, ..., 0};  
      
    procedure dfs(v):  
        print v;  
        used[v] = 1;  
        for i = 1, 2, ..., n:  
            if (a[v][i] == 1 and used[i] == 0):  
                dfs(i);  
      
    dfs(1);  
    

In order to simplify the test results checking procedure, Dmitry Olegovich decided to create a tree T such that the result is his favorite sequence b. On the other hand, Dmitry Olegovich doesn't want to provide students with same trees as input, otherwise they might cheat. That's why Dmitry Olegovich is trying to find out the number of different trees T such that the result of running the above pseudocode with T as input is exactly the sequence b. Can you help him?

Two trees with n vertices are called different if their adjacency matrices a1 and a2 are different, i. e. there exists a pair (i, j), such that 1 ≤ i, j ≤ n and a1[i][j] ≠ a2[i][j].

Input

The first line contains the positive integer n (1 ≤ n ≤ 500) — the length of sequence b. 

The second line contains n positive integers b1, b2, ..., bn (1 ≤ bi ≤ n). It is guaranteed that b is a permutation, or in other words, each of the numbers 1, 2, ..., n appears exactly once in the sequence b. Also it is guaranteed that b1 = 1.

Output

Output the number of trees satisfying the conditions above modulo 109 + 7.

Examples

Input

3
1 2 3


Output

2


Input

3
1 3 2


Output

1
//package codeforces;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class F {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter writer = new PrintWriter(System.out);
    StringTokenizer stringTokenizer;

    String next() throws IOException {
        while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
            stringTokenizer = new StringTokenizer(reader.readLine());
        }
        return stringTokenizer.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    int MOD = 1000 * 1000 * 1000 + 7;

    int sum(int a, int b) {
        a += b;
        return a >= MOD ? a - MOD : a;
    }

    int product(int a, int b) {
        return (int) (1l * a * b % MOD);
    }

    void solve() throws IOException {
        final int n = nextInt();
        final int[] b = new int[n];
        for(int i = 0; i < n; i++) {
            b[i] = nextInt();
        }
        class Utils {
            int countTrees(int from, int to) {
                if(from == to) return 1;
                if(from + 1 == to) return 1;
                return countKidsTrees(from + 1, to);
            }

            int countKidsTrees(int from, int to) {
                if(from == to) return 1;
                if(from + 1 == to) return 1;
                int result = countTrees(from, to);
                for(int i = from + 1; i < to; i++) {
                    if(b[i] > b[from]) {
                        result = sum(result, product(countTrees(from, i), countKidsTrees(i, to)));
                    }
                }
                return result;
            }
        }
        class CachedUtils extends Utils {
            boolean[][] hit = new boolean[n + 1][n + 1];
            int[][] cache = new int[n + 1][n + 1];

            @Override
            int countKidsTrees(int from, int to) {
                if(!hit[from][to]) {
                    hit[from][to] = true;
                    cache[from][to] = super.countKidsTrees(from, to);
                }
                return cache[from][to];
            }
        }
        writer.println(new CachedUtils().countTrees(0, n));
        writer.close();
    }

    public static void main(String[] args) throws IOException {
        new F().solve();
    }
}


