#P12369. Sum of Permutation Values
Sum of Permutation Values
Sum of Permutation Values
Given a permutation (A=(a_1,a_2,\dots,a_n)), define (c_i) as the number of elements among (a_1,a_2,\dots,a_{i-1}) that are less than (a_i), i.e. (c_i = \left|{a_j:, j<i \text{ and } a_j<a_i}\right|). The value of the permutation (A) is defined as (\sum_{i=1}^{n}c_i).
Notice that for any pair of indices ((i,j)) with (i<j), the probability that (a_i < a_j) is (\frac{1}{2}). Hence, the sum of values over all permutations of ({1,2,\dots,n}) is given by
[
\frac{n(n-1)}{4}\times n!.
]
Given an integer (n), compute the sum of the values of all permutations of ({1, 2, \dots, n}).
inputFormat
A single integer (n) representing the number of elements in the permutation.
outputFormat
Output a single integer, the sum of the values of all permutations of ({1,2,\dots,n}).
sample
1
0