Codeforces Round 526 (Div. 1)
D
The Fair Nut's getting crazy
Codeforces
3500
原题
← CE →
翻译中…

The Fair Nut has found an array $a$ of $n$ integers. We call subarray $l \ldots r$ a sequence of consecutive elements of an array with indexes from $l$ to $r$, i.e. $a_l, a_{l+1}, a_{l+2}, \ldots, a_{r-1}, a_{r}$.

翻译中…

No one knows the reason, but he calls a pair of subsegments good if and only if the following conditions are satisfied:

翻译中…
  1. These subsegments should not be nested. That is, each of the subsegments should contain an element (as an index) that does not belong to another subsegment.
  2. Subsegments intersect and each element that belongs to the intersection belongs each of segments only once.
翻译中…

For example $a=[1, 2, 3, 5, 5]$. Pairs $(1 \ldots 3; 2 \ldots 5)$ and $(1 \ldots 2; 2 \ldots 3)$) — are good, but $(1 \dots 3; 2 \ldots 3)$ and $(3 \ldots 4; 4 \ldots 5)$ — are not (subsegment $1 \ldots 3$ contains subsegment $2 \ldots 3$, integer $5$ belongs both segments, but occurs twice in subsegment $4 \ldots 5$).

翻译中…

Help the Fair Nut to find out the number of pairs of good subsegments! The answer can be rather big so print it modulo $10^9+7$.

翻译中…

Input

翻译中…

The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the length of array $a$.

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$) — the array elements.

翻译中…

Output

翻译中…

Print single integer — the number of pairs of good subsegments modulo $10^9+7$.

翻译中…

Note

翻译中…

In the first example, there is only one pair of good subsegments: $(1 \ldots 2, 2 \ldots 3)$.

翻译中…

In the second example, there are four pairs of good subsegments:

翻译中…
  • $(1 \ldots 2, 2 \ldots 3)$
  • $(2 \ldots 3, 3 \ldots 4)$
  • $(2 \ldots 3, 3 \ldots 5)$
  • $(3 \ldots 4, 4 \ldots 5)$
翻译中…

样例

Input #1
3
1 2 3
Output #1
1
InputCopy OutputCopy
Input #2
5
1 2 1 2 3
Output #2
4
InputCopy OutputCopy
题目信息
题号
1083D
时间限制
4 s
内存限制
256 MB
标签
数据结构
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。