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.
样例
7
1 2 1 1 2 2 1
8
3
1 1 1
1
5
1 2 3 4 5
0
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。