#abc252d. D - Distinct Trio

D - Distinct Trio

Score : 400400 points

问题描述

给定一个长度为 NN 的序列:A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N)

找出满足以下两个条件的三元组 (i,j,k)(i,j,k) 的数量。

  • 1i<j<kN1\leq i < j < k \leq N
  • AiA_iAjA_jAkA_k 均不相同。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a sequence of length NN: A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N).
Find the number of triples (i,j,k)(i,j,k) that satisfy both of the following conditions.

  • 1i<j<kN1\leq i \lt j \lt k \leq N
  • AiA_i, AjA_j, and AkA_k are distinct.

Constraints

  • 3N2×1053 \leq N \leq 2\times 10^5
  • 1Ai2×1051 \leq A_i \leq 2\times 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \ldots ANA_N

Output

Print the answer.

Sample Input 1

4
3 1 4 1

Sample Output 1

2

The two triples (i,j,k)(i,j,k) satisfying the conditions are (1,2,3)(1,2,3) and (1,3,4)(1,3,4).

Sample Input 2

10
99999 99998 99997 99996 99995 99994 99993 99992 99991 99990

Sample Output 2

120

Sample Input 3

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

Sample Output 3

355

update @ 2024/3/10 10:45:35