#P10500. Rainbow 的信号

Rainbow 的信号

Problem Description

After Freda invented the pager, Rainbow further improved the signal used by the pager to send messages.

Since we are now in the digital information age, the signal invented by Rainbow is represented by NN natural numbers.

To prevent the big bad guy VariantF from eavesdropping on the conversation between two people, Rainbow split the conversation into three parts: AA, BB, and CC, and encrypted them with three passwords aa, bb, and cc respectively.

Now Freda has received Rainbow's message, and her first task is to decrypt it.

Freda learned that the passwords for these three parts are computed as follows:

Among the NN numbers from 1N1 \sim N, two numbers l,rl, r are chosen uniformly at random. If l>rl > r, swap l,rl, r.

Take out the numbers from the ll-th to the rr-th in the signal to form a sequence PP.

The password for part AA is the mathematical expectation of the xor\operatorname{xor} sum of sequence PP. The xor\operatorname{xor} sum is the value obtained by applying XOR to all numbers in PP. The expectation of the xor\operatorname{xor} sum is the average of the xor\operatorname{xor} sums over all possible choices of l,rl, r.

The password for part BB is the expected value of the and\operatorname{and} sum of sequence PP, defined similarly to the xor\operatorname{xor} sum.

The password for part CC is the expected value of the or\operatorname{or} sum of sequence PP, defined similarly to the xor\operatorname{xor} sum.

Please help compute these three passwords.

Input Format

The first line contains a positive integer NN.

The second line contains NN natural numbers, representing the signal received by Freda.

Output Format

Output one line with three real numbers, representing the expected values of the xor\operatorname{xor} sum, the and\operatorname{and} sum, and the or\operatorname{or} sum, respectively. Round to 33 decimal places. Separate adjacent numbers with one space.

2
4 5
2.750 4.250 4.750

Hint

Sample Explanation

Sample 1 contains four possible choices of l,rl, r in total:

l,rl, r xor\operatorname{xor} sum and\operatorname{and} sum or\operatorname{or} sum
1,11,1 44 44 44
1,21,2 11 55
2,12,1
2,22,2 55

Each pair l,rl, r has the same probability of occurring, so taking the average of the xor\operatorname{xor} sum, the and\operatorname{and} sum, and the or\operatorname{or} sum gives their mathematical expectation.

Constraints

For 20%20\% of the testdata, 1N1001 \le N \le 100 .
For 40%40\% of the testdata, 1N10001 \le N \le 1000 .
For another 30%30\% of the testdata, the NN numbers are 00 or 11 .
For 100%100\% of the testdata, 1N1000001 \le N \le 100000, and each of the NN natural numbers is at most 10910^9 .

Translated by ChatGPT 5