3098.Pashmak and Parmida's problem

Time Limit: 1s Memory Limit: 256MB

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 a1,a2,...,an. Let's denote f(l,r,x) the number of indices k such that: l \le k \le r and ak=x. His task is to calculate the number of pairs of indicies i,j (1 \le i \lt j \le n) such that f(1,i,ai) \gt f(j,n,aj).

Help Pashmak with the test.

Input Format(From the terminal/stdin)

The first line of the input contains an integer n (1 \le n \le 106). The second line contains n space-separated integers a1,a2,...,an (1 \le ai \le 109).

Output Format(To the terminal/stdout)

Print a single integer - the answer to the problem.

Sample Input 1

Copy
7
1 2 1 1 2 2 1
 \n
 · · · · · · \n

Sample Output 1

Copy
8
 \n

Sample Input 2

Copy
3
1 1 1
 \n
 · · \n

Sample Output 2

Copy
1
 \n

Sample Input 3

Copy
5
1 2 3 4 5
 \n
 · · · · \n

Sample Output 3

Copy
0
 \n

Submit

请先 登录

© 2025 FAQs