import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class Main { static long DP[][] = new long[1202][1202]; static long C[][] = new long[1202][1202]; static long mod = 1000*1000*1000 + 7; static long fac[] = new long[1202]; static int arr[]; static ArrayList sets = new ArrayList(); static long solve(int ind,int s,int f) { if(s < 0) return 0; if(ind == sets.size()) { return 1; } if(s == 0) return 0; if(DP[ind][s] != -1) return DP[ind][s]; long ret = 0; int curr = sets.get(ind); ret += solve(ind,s - 1,f); if(curr % s == 0) ret += (curr / s) * solve(ind + 1,s,1)%mod; ret %= mod; ret %= mod; return DP[ind][s]=ret; } public static void main(String[]args)throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; int n = new Integer(br.readLine()); st = new StringTokenizer(br.readLine()); arr = new int[n]; for(int i = 0 ; i < n ; ++i) arr[i] = new Integer(st.nextToken()); for(int i = 0 ; i <= 1200 ; ++i) Arrays.fill(DP[i], -1); int s = 1; for(int i = 1 ; i < n ; ++i) { if(arr[i] > arr[i - 1]) ++s; else { sets.add(s); s = 1; i++; } } if(s != 0) sets.add(s); fac[0] = 1L; for(int i = 1 ; i <= 1201; ++i) { fac[i] = (1L*fac[i - 1] * i)%mod; } C[0][0] = 1; for(int i = 1 ; i <= 1200 ; ++i) { C[i][0] = 1; for(int j = 1 ; j <= 1200 ; ++j) { C[i][j] = C[i - 1][j - 1]%mod + C[i - 1][j]%mod; C[i][j] %= mod; } } System.out.println(solve(0,n,0)); } }