Under construction

Still being built. Things may change

Sort

Time limit2sMemory limit128 MB

Summary
For an array of at most 8 elements, compute the expected number of random-swap steps until sorted for two different swap schemes.
Level

Hard8 of 10

Topics
Probability, Dynamic programming, Simulation
Solved
No attempts yet

Problem

Mirko and Slavko, two rising stars of computer science, often pass the time by inventing new algorithms. Right now they are playing with sorting. Mirko proposed the following algorithm:

while (!sorted(A)) { 
      int i = random(N); 
      int j = random(N); 
      if (A[min(i,j)] > A[max(i,j)]) 
            swap(A[i], A[j]); 
}

Inspired by Mirko's version, Slavko proposed this one:

while (!sorted(A)) {
      int i = random(N-1); 
      int j = i + 1; 
      if (A[i] > A[j]) 
            swap(A[i], A[j]); 
}

The function random(k) returns an integer from 0,1,…,k−10, 1, \ldots, k-1, and every integer is equally likely. sorted(A) is true when AA is in non-decreasing order.

Now they want to know which algorithm is better. Given an array AA of length NN, find the expected number of steps each algorithm needs to finish. One step is one complete iteration of the while loop.

Input

The first line contains the number of elements NN of the array AA (1≤N≤81 \le N \le 8).

The second line contains the NN elements A1,A2,…,ANA_1, A_2, \ldots, A_N of the array, separated by spaces (0≤Ai≤1000 \le A_i \le 100).

Output

On the first line, print the expected number of steps of Mirko's algorithm. On the second line, print the expected number of steps of Slavko's algorithm.

Round each exact expected value to six digits after the decimal point and print exactly six digits after the decimal point. For example, if the expected value is 14.37514.375, print 14.375000.

Examples2

  1. Example 1

    Input
    3
    3 2 1
    
    Expected output
    6.000000
    5.000000
    
  2. Example 2

    Input
    6
    2 7 1 8 2 8
    
    Expected output
    33.000000
    14.375000