ユニークビジョンプログラミングコンテスト2024 春(AtCoder Beginner Contest 346)
G
Alone
AtCoder
⌀ 2166
原题
翻译中…

Problem Statement

翻译中…

You are given an integer sequence $A = (A_1, A_2, \ldots, A_N)$.

翻译中…

Find the number of pairs of integers $(L, R)$ that satisfy the following conditions:

翻译中…
  • $1 \leq L \leq R \leq N$
  • There is a number that appears exactly once among $A_L, A_{L + 1}, \ldots, A_R$. More precisely, there is an integer $x$ such that exactly one integer $i$ satisfies $A_i = x$ and $L \leq i \leq R$.
翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 2 \times 10^5$
  • $1 \leq A_i \leq N$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
A_1 A_2 \ldots A_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
5
2 2 1 2 1
Output #1
12
$12$ pairs of integers satisfy the conditions: $(L, R) = (1, 1), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5), (5, 5)$.
Input #2
4
4 4 4 4
Output #2
4
Input #3
10
1 2 1 4 3 3 3 2 2 4
Output #3
47
题目信息

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