# 22-26 февраля. Старшая лига - Дерево Фенвика

# Mega Inversions

The `n`

upper bound for any sorting algorithm is easy to obtain: just take two elements that are misplaced with respect to each other and swap them. Conrad conceived an algorithm that proceeds by taking not two, but three misplaced elements. That is, take three elements ^{2}`a`

> _{i}`a`

> _{j}`a`

with _{k}**i** < **j** < **k** and place them in order `a`

, _{k}`a`

, _{j}`a`

. Now if for the original algorithm the steps are bounded by the maximum number of inversions _{i}**n** (**n** - **1**) / **2**, Conrad is at his wits' end as to the upper bound for such triples in a given sequence. He asks you to write a program that counts the number of such triples.

#### Input

The first line is the length of the sequence **n** (**1** ≤ **n** ≤ `10`

). The next line contains the integer sequence ^{5}`a`

,_{1}`a`

, ..., _{2}`a`

(_{n}**1** ≤ `a`

≤ _{i}**n**).

#### Output

Print the number of inverted triples.

3 1 2 3

0

4 3 3 2 1

2