#ARC122B. [ARC122B] Insurance

[ARC122B] Insurance

Score : 500500 points

Problem Statement

Snuke has read his own fortune for tomorrow, and learned that there are NN scenarios that can happen, one of which will happen tomorrow with equal probability. The ii-th scenario will cost him AiA_i yen (Japanese currency).

Following this, Snuke has decided to get insurance today. If he pays xx yen to his insurance company, he will get compensation of min(Ai,2x)\min(A_i,2x) yen when AiA_i yen is lost. Here, he can choose any non-negative real number as xx.

Snuke wants to minimize the expected value of the amount of money he loses, which is x+Aimin(Ai,2x)x+A_i-\min(A_i,2x). Find the minimized value.

Constraints

  • 1N1051 \leq N \leq 10^5
  • 1Ai1091 \leq A_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \cdots ANA_N

Output

Print the answer. Your answer will be judged correct when its absolute or relative error is at most 10610^{-6}.

3
3 1 4
1.83333333333333333333

The optimum choice is x=1.5x=1.5. After paying 1.51.5 yen, one of the following three scenarios will happen with equal probability:

  • Scenario 11: Lose 33 yen and get compensation of min(3,2x)=3\min(3,2x)=3 yen. After all, Snuke loses x+A1min(A1,2x)=1.5+33=1.5x+A_1-\min(A_1,2x)=1.5+3-3=1.5 yen.
  • Scenario 22: Lose 11 yen and get compensation of min(1,2x)=1\min(1,2x)=1 yen. After all, Snuke loses x+A2min(A2,2x)=1.5+11=1.5x+A_2-\min(A_2,2x)=1.5+1-1=1.5 yen.
  • Scenario 33: Lose 44 yen and get compensation of min(4,2x)=3\min(4,2x)=3 yen. After all, Snuke loses x+A3min(A3,2x)=1.5+43=2.5x+A_3-\min(A_3,2x)=1.5+4-3=2.5 yen.

Thus, the expected amount of money lost is (1.5+1.5+2.5)/3=1.833333(1.5+1.5+2.5)/3=1.833333\cdots yen.

10
866111664 178537096 844917655 218662351 383133839 231371336 353498483 865935868 472381277 579910117
362925658.10000000000000000000