from bisect import bisect_left from collections import defaultdict def compress(a: list) -> list: d = {v: i for i, v in enumerate(sorted(set(a)))} return [d[v] for v in a] class FenwickTree: def __init__(self, n): self.data = [0] * (n+10) self.n = (n+10) def add(self, p, x): assert 0 <= p < self.n p += 1 while p < len(self.data): self.data[p] += x p += p & -p def sum(self, p): """区間 [0, p] の和""" assert 0 <= p < self.n p += 1 s = 0 while p > 0: s += self.data[p] p -= p & -p return s def rangesum(self, l, r): """区間 [l, r] の和""" assert 0 <= l <= r < self.n s = self.sum(r) if l > 0: s -= self.sum(l-1) return s # LIS のアルゴリズム # 各要素のランクを返す def lis(a: list) -> list: n = len(a) ranks = [0] * n # ranks[i] : A[i] が LIS の何番目か dp = [INF] * n for i in range(n): ranks[i] = bisect_left(dp, a[i]) dp[ranks[i]] = a[i] return ranks MOD = 10 ** 9 + 7 INF = 1 << 60 N = int(input()) A = list(map(int, input().split())) A = compress(A) ranks = lis(A) max_rank = max(ranks) d = defaultdict(list) for i in range(N): d[ranks[i]].append(i) ft = FenwickTree(N) dp = [0] * N for p in d[max_rank]: ft.add(p, 1) dp[p] = 1 # print(f'{A=}') # print(f'{ranks=}') for r in reversed(range(max_rank)): pp = [0] * N dp, pp = pp, dp ft2 = FenwickTree(N) t = FenwickTree(N) up = d[r+1].copy() for p in reversed(d[r]): while up and p < up[-1]: q = up[-1] ft2.add(A[q], pp[q]) up.pop() # print(f'{r=} {p=} {ft2.rangesum(A[p]+1, N)=}') t.add(A[p], ft2.rangesum(A[p]+1, N) % MOD) dp[p] = ft2.rangesum(A[p]+1, N) % MOD ft = t # ans = ft.sum(N) ans = sum(dp) % MOD print(ans)