#P1637. 三元上升子序列

三元上升子序列

Description

Erwin has recently become very interested in something called thair...

In a sequence with nn integers a1,a2,,ana_1,a_2,\ldots,a_n, three numbers are called thair if and only if i<j<ki<j<k and ai<aj<aka_i<a_j<a_k.

Find the number of thair in the sequence.

Input Format

The first line contains a positive integer nn.

The second line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n.

Output Format

Print one integer in a single line indicating the number of thair.

4
2 1 3 4
2
5
1 2 2 3 4
7

Hint

Sample 2 Explanation

The 77 thair are:

  • 1 2 3.
  • 1 2 4.
  • 1 2 3.
  • 1 2 4.
  • 1 3 4.
  • 2 3 4.
  • 2 3 4.

Constraints

  • For 30%30\% of the testdata, it is guaranteed that n100n\le100.
  • For 60%60\% of the testdata, it is guaranteed that n2000n\le2000.
  • For 100%100\% of the testdata, it is guaranteed that 1n3×1041 \leq n\le3\times10^4 and 1ai1051\le a_i\leq 10^5.

Translated by ChatGPT 5