#P1637. Counting Thair Subsequences

    ID: 14923 Type: Default 1000ms 256MiB

Counting Thair Subsequences

Counting Thair Subsequences

Erwin is fascinated by a concept called thair. In a sequence of n integers, thair is defined as a triple of numbers ai, aj, ak such that i < j < k and ai < aj < ak. In other words, three numbers form a thair if and only if:

$i<j<k$ and $a_i<a_j<a_k$

Your task is to count the number of thair triples in the given sequence.

inputFormat

The input consists of two lines. The first line contains an integer n ($1 \leq n \leq 10^5$ depending on constraints). The second line contains n space-separated integers representing the sequence: a1, a2, ..., an.

outputFormat

Output a single integer, which is the number of thair triples in the given sequence.

sample

3
1 2 3
1

</p>