Problem:
Score : 1000 points

Problem Statement

#nck {
width: 30px;
height: auto;
}

There are N balls and N+1 holes in a line. Balls are numbered 1 through N from left to right. Holes are numbered 1 through N+1 from left to right. The i-th ball is located between the i-th hole and (i+1)-th hole. We denote the distance between neighboring items (one ball and one hole) from left to right as d_i (1 \leq i \leq 2 \times N). You are given two parameters d_1 and x. d_i - d_{i-1} is equal to x for all i (2 \leq i \leq 2 \times N).

We want to push all N balls into holes one by one. When a ball rolls over a hole, the ball will drop into the hole if there is no ball in the hole yet. Otherwise, the ball will pass this hole and continue to roll. (In any scenario considered in this problem, balls will never collide.)

In each step, we will choose one of the remaining balls uniformly at random and then choose a direction (either left or right) uniformly at random and push the ball in this direction. Please calculate the expected total distance rolled by all balls during this process.

For example, when N = 3, d_1 = 1, and x = 1, the following is one possible scenario:

first step: push the ball numbered 2 to its left, it will drop into the hole numbered 2. The distance rolled is 3.

second step: push the ball numbered 1 to its right, it will pass the hole numbered 2 and drop into the hole numbered 3. The distance rolled is 9.

third step: push the ball numbered 3 to its right, it will drop into the hole numbered 4. The distance rolled is 6.

So the total distance in this scenario is 18.

Note that in all scenarios every ball will drop into some hole and there will be a hole containing no ball in the end.

Constraints

1 \leq N \leq 200,000

1 \leq d_1 \leq 100

0 \leq x \leq 100

All input values are integers.

Input

The input is given from Standard Input in the following format:

N d_1 x

Output

Print a floating number denoting the answer. The relative or absolute error of your answer should not be higher than 10^{-9}.

Sample Input 1

1 3 3

Sample Output 1

4.500000000000000

The distance between the only ball and the left hole is 3 and distance between the only ball and the right hole is 6. There are only two scenarios (i.e. push left and push right). The only ball will roll 3 and 6 unit distance, respectively. So the answer for this example is (3+6)/2 = 4.5.

Sample Input 2

2 1 0

Sample Output 2

2.500000000000000

Sample Input 3

1000 100 100

Sample Output 3

649620280.957660079002380

Solution in C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using CompLib.Util;

public class Program
{
    private long N, D1, X;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextLong();
        D1 = sc.NextLong();
        X = sc.NextLong();

        // 適当に玉を転がす
        // 状態 玉の個数1つ減らして同じ

        Console.WriteLine(Calc(N, D1, X));
    }

    decimal Calc(long n, decimal d1, decimal x)
    {
        // 移動距離期待値 
        decimal a = (2 * d1 + (2 * n - 1) * x) / 2;
        if (n == 1) return a;

        // 転がした後の玉jの位置期待値

        // けいさんめんどい！！！！
        // jの1次式

        // 右も同様

        decimal nD1;
        {
            // 1を右に転がす
            // 玉2が新しい玉1になる
            decimal t1 = 3 * d1 + 3 * x;

            // 1を左に転がす
            decimal t2 = d1 + 2 * x;

            // それ以外
            decimal t3 = d1;

            nD1 = (t1 + t2 + t3 * (2 * n - 2)) / (2 * n);
        }

        decimal nD2;
        {
            // 1を転がす
            // 2パターン
            decimal t1 = d1 + 3 * x;


            // 2を左に転がす
            // 1
            decimal t2 = 3 * d1 + 6 * x;

            // それ以外
            // 
            decimal t3 = d1 + x;
            nD2 = (t1 * 2 + t2 + t3 * (2 * n - 3)) / (2 * n);
        }

        decimal nX = nD2 - nD1;

        return a + Calc(n - 1, nD1, nX);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}