Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

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-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Oct/21/2019 11:56:02 (h2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|