No tag edit access

D. Pashmak and Parmida's problem

time limit per test

3 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputParmida 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.

Examples

Input

7

1 2 1 1 2 2 1

Output

8

Input

3

1 1 1

Output

1

Input

5

1 2 3 4 5

Output

0

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Oct/20/2017 13:47:08 (c4).

Desktop version, switch to mobile version.

User lists

Name |
---|