QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 100

#5299. Variable Subsequences

Statistics

We are looking for variable subsequences of a given sequence $a = (a_{1}, a_{2}, ..., a_{n})$. A subsequence is obtained from a sequence by removing any number of its terms (possibly 0). More formally, a subsequence of the sequence a is any sequence $(a_{i_{1}}, a_{i_{2}}, ..., a_{i_{k}})$, for which $1 ≤ i_{1} < i_{2} < ... < i_{k} ≤ n$ A variable subsequence is a subsequence such that every two its consecutive terms are different. For example, the sequence (1, 3, 1, 2) is a variable subsequence of the sequence (1, 2, 3, 1, 3, 2, 2).

We would like to know how many distinct and nonempty variable subsequences of a given sequence are there. Two subsequences are considered distinct if the sets of positions in a corresponding to them are different. For instance, the sequence (1, 2, 3, 1, 3, 2, 2) contains two distinct variable subsequences of the form (1, 3, 1, 2).

Input Format

The first line of the standard input contains one integer $n$ ($2 ≤ n ≤ 500\,000$), denoting the length of the sequence $a$. The second line contains $n$ integers $a_{i}$ ($1 ≤ a_{i} ≤ 500\,000$).

Output Format

Your program should write to the first and only line of the standard output a single integer: the number of nonempty variable subsequences of the input sequence modulo $10^{9} + 7$.

Example

Input

4
1 2 1 1

Output

9

Notes

The considered subsequences of the sequence (1, 2, 1, 1) are:

  • (1) - counted three times,
  • (2) - counted once,
  • (1, 2) - counted once,
  • (2, 1) - counted twice and
  • (1, 2, 1) - counted twice.
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.