#!/bin/python import sys def solve(arr, i, k, prev): if i >= len(arr): return 1 n = i+1 while n < len(arr) and n < i+k: if arr[n-1] > arr[n]: break n+=1 k_max = n-i result = 0 curr = 1 for num_sets in xrange(1, k_max+1): curr *= num_sets if k == len(arr): result += solve(arr, i+num_sets, num_sets, curr) else: result += prev/curr*solve(arr, i+num_sets, num_sets, curr) return result % (10**9 + 7) n = int(raw_input().strip()) m = map(int, raw_input().strip().split(' ')) # your code goes here print solve(m, 0, len(m), 0)