import java.util.Scanner;
public class Main {
static final int MOD = 1000000007;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] a = new int[n+1];
long[] dp= new long[n+1];
for (int i = 1; i <= n; ++i) {
a[i] = scanner.nextInt();
}
dp[0] = 1;
/*
* 审题
* 全排列是指没有重复数字
* 如果索引1-3最大值是1和3就代表1,2,3均出现过了
* */
for (int i = 1; i <= n; ++i) {
int mx = a[i], mi = a[i];
for (int j = i; j >= 1; j--) {
mx = Math.max(mx, a[j]);
mi = Math.min(mi, a[j]);
//线性dp
if (mx - mi == i - j) {
dp[i] = (dp[i] + dp[j - 1]) % MOD;
}
}
}
System.out.println(dp[n]);
}
}