CF459D Pashmak and Parmida's problem
Description
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\le k\le r $ and $ a_{k}=x $ . His task is to calculate the number of pairs of indicies $ i,j $ $ (1 \le i < j \le n) $ such that $ f(1,i,a_{i}) > f(j,n,a_{j}) $ .
Help Pashmak with the test.
Input Format
The first line of the input contains an integer $ n $ $ (1\le n\le 10^{6}) $ . The second line contains $ n $ space-separated integers $ a_{1},a_{2},\cdots ,a_{n} $ $ (1\le a_{i}\le 10^{9}) $ .
Output Format
Print a single integer — the answer to the problem.