Byteasar the gardener grows a rare tree called Rotatus Informatikus. It has a few notable properties:
The corona of the tree is the sequence of integers read off the leaf labels from left to right.

The tree on the left has corona 3,1,2 and two inversions. A single rotation yields the tree on the right, whose corona 1,3,2 has just one inversion. Both trees have five branches.
The neatness of a tree is the number of inversions in its corona, that is, the number of pairs (i,j) with 1≤i<j≤n and ai>aj in the corona a1,a2,…,an.
Compute the minimum number of inversions in the corona that can be reached by a sequence of rotations.
The first line contains a single integer n (2≤n≤200000), the number of leaves. The description of the tree follows and is defined recursively:
Print one integer: the minimum number of inversions in the corona attainable by a sequence of rotations.
The figure above shows the tree with corona 3,1,2, which has two inversions; a single rotation gives corona 1,3,2 with one inversion, the minimum.