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
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Stanislav Pak
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskF solver = new TaskF();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskF {
	private static final long UNDEFINED = -1L;
	private static final long MOD = 1000000007L;
	long[][] t, d;
	int[] p;
    public void solve(int testNumber, InputReader in, OutputWriter out) {
		int n = in.readInt();
		p = new int[n];
		for (int i = 0; i < n; ++i) p[i] = in.readInt() - 1;
		t = new long[n][];
		d = new long[n][];
		for (int i = 0; i < n; ++i) {
			t[i] = ArrayUtils.createArray(n, UNDEFINED);
			d[i] = ArrayUtils.createArray(n, UNDEFINED);
		}
		out.printLine(calcT(0, n - 1));
    }

	private long calcT(int l, int r) {
		if (l == r) {
			return 1L;
		}
		if (t[l][r] != UNDEFINED) {
			return t[l][r];
		}
		return t[l][r] = calcD(l + 1, r);
	}

	private long calcD(int l, int r) {
		if (l == r) {
			return 1L;
		}
		if (d[l][r] != UNDEFINED) {
			return d[l][r];
		}
		d[l][r] = calcT(l, r);
		for (int i = l; i < r; ++i) {
			if (p[l] < p[i + 1]) {
				d[l][r] += calcT(l, i) * calcD(i + 1, r) % MOD;
			}
		}
		return d[l][r] %= MOD;
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	public static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public void close() {
		writer.close();
	}

	public void printLine(long i) {
		writer.println(i);
	}

}

class ArrayUtils {

	public static long[] createArray(int count, long value) {
		long[] array = new long[count];
		Arrays.fill(array, value);
		return array;
	}

}
