import java.io.BufferedReader import java.io.InputStream import java.io.InputStreamReader import java.util.* import kotlin.math.abs import kotlin.math.max import kotlin.math.min val MOD = 1_000_000_007 class Solver(stream: InputStream, private val out: java.io.PrintWriter) { fun solve() { val N = ni() val A = na(N) val (ix, pos) = LIS(A, N) debug{ix.joinToString { it.toString() }} debug(pos) val C = Array(ix.size){ BIT(ix[it].size) } for (i in 0 until N) { val p = pos[i] val cnt = if (p == 0) 1 else C[p-1].sum(ix[p-1][i]!!) debug{"$cnt"} C[p].add(ix[p][i]!!, cnt) } val ans = C[ix.lastIndex].sum(ix.last().size) out.println(ans) } fun LIS(A: IntArray, N: Int): Pair>, IntArray> { val ix = Array(N){ mutableListOf()} val lis = IntArray(N) var p = 0 val pos = IntArray(N) for (i in 0 until A.size) { var l = -1 var h = p while(h - l > 1) { val m = (h + l) / 2 if (lis[m] >= A[i]) h = m else l = m } lis[h] = A[i] ix[h].add(i) if (h > 0) ix[h-1].add(i) p = max(p, h + 1) pos[i] = h } val ix2 = Array(p){ mutableMapOf() } for (i in 0 until p) { ix[i].sortWith(compareBy({A[it]}, {-it})) for (j in 0 until ix[i].size) { ix2[i][ix[i][j]] = j } } return Pair(ix2, pos) } class BIT(n: Int) { private val N = if (Integer.highestOneBit(n) == n) n else Integer.highestOneBit(n) shl 1 private val bit = LongArray(N + 1) fun sum(i: Int): Long { var x = i var s = 0L while(x > 0) { s += bit[x] x -= x and -x } return s % MOD } fun add(i: Int, a: Long) { var x = i + 1 while(x <= N) { bit[x] = (bit[x] + a) % MOD x += x and -x } } } private val isDebug = try { // なんか本番でエラーでる System.getenv("MY_DEBUG") != null } catch (t: Throwable) { false } private var tokenizer: StringTokenizer? = null private val reader = BufferedReader(InputStreamReader(stream), 32768) private fun next(): String { while (tokenizer == null || !tokenizer!!.hasMoreTokens()) { tokenizer = StringTokenizer(reader.readLine()) } return tokenizer!!.nextToken() } private fun ni() = next().toInt() private fun nl() = next().toLong() private fun ns() = next() private fun na(n: Int, offset: Int = 0): IntArray { return map(n, offset) { ni() } } private inline fun map(n: Int, offset: Int = 0, f: (Int) -> Int): IntArray { val res = IntArray(n) for (i in 0 until n) { res[i] = f(i + offset) } return res } private inline fun debug(msg: () -> String) { if (isDebug) System.err.println(msg()) } private fun debug(a: LongArray) { debug { a.joinToString(" ") } } private fun debug(a: IntArray) { debug { a.joinToString(" ") } } private fun debug(a: BooleanArray) { debug { a.map { if (it) 1 else 0 }.joinToString("") } } private fun debugDim(A: Array) { if (isDebug) { for (a in A) { debug(a) } } } /** * 勝手にimport消されるのを防ぎたい */ private fun hoge() { min(1, 2) max(1, 2) abs(-10) } } fun pair(a: A, b: B) = RPair(a, b) data class RPair(val _1: A, val _2: B) fun main() { val out = java.io.PrintWriter(System.out) Solver(System.`in`, out).solve() out.flush() }