Codeforces Round 261 (Div. 2)
D
Pashmak and Parmida's problem
Codeforces
1800
原题
← CE →
翻译中…

Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak.

翻译中…

There is a sequence $*a*$ that consists of $*n*$ integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$. Let's denote $*f*(*l*, *r*, *x*)$ the number of indices $*k*$ such that: $*l* ≤ *k* ≤ *r*$ and $*a*_{*k*} = *x*$. His task is to calculate the number of pairs of indicies $*i*, *j*$ $(1 ≤ *i* < *j* ≤ *n*)$ such that $*f*(1, *i*, *a*_{*i*}) > *f*(*j*, *n*, *a*_{*j*})$.

翻译中…

Help Pashmak with the test.

翻译中…

Input

翻译中…

The first line of the input contains an integer $*n*$ $(1 ≤ *n* ≤ 10^{6})$. The second line contains $*n*$ space-separated integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ $(1 ≤ *a*_{*i*} ≤ 10^{9})$.

翻译中…

Output

翻译中…

Print a single integer — the answer to the problem.

翻译中…

样例

Input #1
7
1 2 1 1 2 2 1
Output #1
8
InputCopy OutputCopy
Input #2
3
1 1 1
Output #2
1
InputCopy OutputCopy
Input #3
5
1 2 3 4 5
Output #3
0
InputCopy OutputCopy
题目信息
题号
459D
时间限制
3 s
内存限制
256 MB
标签
数据结构
分治
排序

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