#abc206cL. 习题11.3.6 交换(Swappable)

习题11.3.6 交换(Swappable)

Score : 300300 points

Problem Statement

Given an array of NN integers A=(A_1,A_2,...,A_N)A=(A\_1,A\_2,...,A\_N), find the number of pairs (i,j)(i,j) of integers satisfying all of the following conditions:

  • 1i<jN1 \le i < j \le N

  • A_iA_jA\_i \neq A\_j

Constraints

  • All values in input are integers.

  • 2N3×1052 \le N \le 3 \times 10^5

  • 1A_i1091 \le A\_i \le 10^9


Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \dots ANA_N

Output

Print the answer as an integer.


Sample Input 1

3

1 7 1

Sample Output 1

2

In this input, we have A=(1,7,1)A=(1,7,1).

  • For the pair (1,2)(1,2), A_1A_2A\_1 \neq A\_2.

  • For the pair (1,3)(1,3), A_1=A_3A\_1 = A\_3.

  • For the pair (2,3)(2,3), A_2A_3A\_2 \neq A\_3.


Sample Input 2

10

1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000

Sample Output 2

45


Sample Input 3

20

7 8 1 1 4 9 9 6 8 2 4 1 1 9 5 5 5 3 6 4

Sample Output 3

173