open System open System.Collections.Generic // OPERATORS let MOD = 1000000007 let inline ( *~ ) a b = (int64(a) * int64(b) % int64(MOD)) |> int let rec ( ^~ ) (a:int) (b:int) = match b with | 0 -> 1 | b when b%2 = 1 -> let t = a ^~ (b / 2) t *~ t *~ a | b -> let t = a ^~ (b / 2) t *~ t let inline ( +~ ) a b = if (a+b >= MOD) then a+b-MOD else a+b let inline ( /~ ) (a:int) (b:int) = a *~ (b ^~ (MOD - 2)) // /OPERATORS // INPUT let n = Console.ReadLine() |> int let arr = Console.ReadLine().Split([|' '|]) |> Array.map int // /INPUT let GetLen ind = let mutable len = 1 let mutable pos = ind+1 while (pos < n && arr.[pos] > arr.[pos-1]) do pos <- pos + 1 len <- len + 1 len let CIncreasing = [| 0 .. (n-1) |] |> Array.map GetLen let IsIncreasing start len = CIncreasing.[start] >= len let Fact = [| 1..1500 |] |> Array.scan ( *~ ) 1 let CMem = Array2D.create 1500 1500 -1 let C n k = if (CMem.[n, k] = -1) then CMem.[n, k] <- Fact.[n] /~ Fact.[n-k] CMem.[n, k] let mem = Array2D.create 1500 1500 -1 let rec Rec = function | (last, _) when last = n -> 1 | (_, 0) -> 0 | (pos, a) -> //printfn "%d %d" pos a [| 1 .. min a (CIncreasing.[pos]) |] |> Array.map(fun len -> (C a len) *~ RecMemory(len+pos, len)) |> Array.fold (+~) 0 and RecMemory (a, b) = if (mem.[a, b] = -1) then mem.[a, b] <- Rec(a, b) mem.[a, b] let Calc len = RecMemory (len, len) [| 1 .. (CIncreasing.[0]) |] |> Array.map Calc |> Array.fold ( +~ ) 0 |> Console.WriteLine