Codeforces Round 388 (Div. 2)
E
Inversions After Shuffle
Codeforces
2400
原题
← D→
翻译中…

You are given a permutation of integers from $1$ to $*n*$. Exactly once you apply the following operation to this permutation: pick a random segment and shuffle its elements. Formally:

翻译中…
  1. Pick a random segment (continuous subsequence) from $*l*$ to $*r*$. All image segments are equiprobable.
  2. Let $*k* = *r* - *l* + 1$, i.e. the length of the chosen segment. Pick a random permutation of integers from $1$ to $*k*$, $*p*_{1}, *p*_{2}, ..., *p*_{*k*}$. All $*k*!$ permutation are equiprobable.
  3. This permutation is applied to elements of the chosen segment, i.e. permutation $*a*_{1}, *a*_{2}, ..., *a*_{*l* - 1}, *a*_{*l*}, *a*_{*l* + 1}, ..., *a*_{*r* - 1}, *a*_{*r*}, *a*_{*r* + 1}, ..., *a*_{*n*}$ is transformed to $*a*_{1}, *a*_{2}, ..., *a*_{*l* - 1}, *a*_{*l* - 1 + *p*_{1}}, *a*_{*l* - 1 + *p*_{2}}, ..., *a*_{*l* - 1 + *p*_{*k* - 1}}, *a*_{*l* - 1 + *p*_{*k*}}, *a*_{*r* + 1}, ..., *a*_{*n*}$.
翻译中…

Inversion if a pair of elements (not necessary neighbouring) with the wrong relative order. In other words, the number of inversion is equal to the number of pairs $(*i*, *j*)$ such that $*i* < *j*$ and $*a*_{*i*} > *a*_{*j*}$. Find the expected number of inversions after we apply exactly one operation mentioned above.

翻译中…

Input

翻译中…

The first line contains a single integer $*n*$ ($1 ≤ *n* ≤ 100 000$) — the length of the permutation.

翻译中…

The second line contains $*n*$ distinct integers from $1$ to $*n*$ — elements of the permutation.

翻译中…

Output

翻译中…

Print one real value — the expected number of inversions. Your answer will be considered correct if its absolute or relative error does not exceed $10^{ - 9}$.

翻译中…

Namely: let's assume that your answer is $*a*$, and the answer of the jury is $*b*$. The checker program will consider your answer correct, if image.

翻译中…

样例

Input #1
3
2 3 1
Output #1
1.916666666666666666666666666667
InputCopy OutputCopy
题目信息
题号
749E
时间限制
1 s
内存限制
256 MB
标签
数据结构
概率论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。