# CF459D Pashmak and Parmida's problem

• 25通过
• 75提交
• 题目来源
• 评测方式 RemoteJudge
• 标签
• 难度 提高+/省选-
• 时空限制 3000ms / 256MB
• 提示：收藏到任务计划后，可在首页查看。

## 题意翻译

给出长度为n的序列a。

f(i,j,x)表示ai..aj中x的出现次数。

求有多少对i,j满足f(1,i,ai) > f(j,n,aj)。(i<j)

## 题目描述

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&lt;j<=n)$ such that $f(1,i,a_{i})&gt;f(j,n,a_{j})$ .

Help Pashmak with the test.

## 输入输出格式

输入格式：

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})$ .

输出格式：

Print a single integer — the answer to the problem.

## 输入输出样例

输入样例#1： 复制
7
1 2 1 1 2 2 1

输出样例#1： 复制
8

输入样例#2： 复制
3
1 1 1

输出样例#2： 复制
1

输入样例#3： 复制
5
1 2 3 4 5

输出样例#3： 复制
0

提示
标程仅供做题后或实在无思路时参考。
请自觉、自律地使用该功能并请对自己的学习负责。
如果发现恶意抄袭标程，将按照I类违反进行处理。