CSES - Increasing Subsequence II | Dãy con tăng II

View as PDF



Author:
Problem types
Points: 1700 (p) Time limit: 1.0s Memory limit: 512M Input: stdin Output: stdout

Given an array of \(n\) integers, your task is to calculate the number of increasing subsequences it contains. If two subsequences have the same values but in different positions in the array, they are counted separately.

Input

The first input line has an integer \(n\): the size of the array.

The second line has \(n\) integers \(x_1,x_2,…,x_n\): the contents of the array.

Output

Print one integer: the number of increasing subsequences modulo \(10^9+7\).

Constraints

  • \(1\leq n \leq 2 ⋅ 10^5\)
  • \(1\leq x_i \leq 10^9\)

Example

Sample input

3  
2 1 3

Sample output

5

Note

The increasing subsequences are \([2]\), \([1]\), \([3]\), \([2,3]\) and \([1,3]\).


Comments (5)

Most recent
Loading comments...