Codeforces Round 261 (Div. 2) |
---|

Finished |

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.

data structures

divide and conquer

sortings

*1800

No tag edit access

The problem statement has recently been changed. View the changes.

×
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-2023 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Dec/03/2023 17:35:25 (k2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|