import sys input = lambda : sys.stdin.readline().strip() mod = 10**9+7 class RangeMinimumQuery: def __init__(self, n, F=min, e=float("inf"), fill=None): self.n = n self.n0 = 2**(n-1).bit_length() self.F = F self.e = e if fill is None: fill = e self.data = [fill]*(2*self.n0) def construct(self, a): for i, x in enumerate(a): self.data[i+self.n0-1] = x for i in range(self.n0-2, -1, -1): self.data[i] = self.F(self.data[2*i+1], self.data[2*i+2]) def query(self, l,r): l += self.n0 r += self.n0 res = self.e while l < r: if r&1: r -= 1 res = self.F(res, self.data[r-1]) if l&1: res = self.F(res, self.data[l-1]) l += 1 l >>=1 r >>=1 return res def update(self, i, x): i += self.n0-1 self.data[i] = x while i: i = ~-i//2 self.data[i] = self.F(self.data[2*i+1], self.data[2*i+2]) def updater(a,b): if a[0] == b[0]: return (a[0], (a[1]+b[1])%mod) elif a[0] > b[0]: return a else: return b n = int(input()) a = list(map(int, input().split())) seg = RangeMinimumQuery(n, updater, (0,0), None) b = [[ai, i] for i, ai in enumerate(a)] b.sort(key=lambda x: (x[0], -x[1])) for i in range(n): _, j = b[i] tmp = seg.query(0, j) if tmp == (0,0): seg.update(j, (tmp[0]+1, 1)) else: seg.update(j, (tmp[0]+1, tmp[1])) ans = seg.query(0, n)[1] print(ans)