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++14 (Clang 3.8.0) (judge verdict: Wrong Answer)

#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
using namespace std;

const int maxn = 300010,inf = 1<<29;
int W,H,N,ans,tree[maxn*4],tag[maxn*4];

inline int gi()
{
	char ch; int ret = 0,f = 1;
	do ch = getchar(); while (!(ch >= '0'&&ch <= '9')&&ch != '-');
	if (ch == '-') f = -1,ch = getchar();
	do ret = ret*10+ch-'0',ch = getchar(); while (ch >= '0'&&ch <= '9');
	return ret*f;
}

struct node
{
	int x,y;
	inline node(int _x = 0,int _y = 0):x(_x),y(_y) {}
	inline void read() { x = gi(); y = gi(); }
	friend inline bool operator <(const node &a,const node &b) { return a.x < b.x; }
}P[maxn];

inline void build(int now,int l,int r)
{
	tree[now] = -inf; tag[now] = 0; if (l == r) return;
	int mid = (l+r) >> 1;
	build(now<<1,l,mid); build(now<<1|1,mid+1,r);
}

inline void pushdown(int now,int l,int r)
{
	if (l != r)
	{
		tree[now<<1] += tag[now]; tag[now<<1] += tag[now];
		tree[now<<1|1] += tag[now]; tag[now<<1|1] += tag[now];
	}
	tag[now] = 0;
}

inline void modify(int now,int l,int r,int ql,int qr,int key)
{
	if (tag[now]) pushdown(now,l,r);
	if (l == ql&&r == qr) { tree[now] += key; tag[now] = key; return; }
	int mid = (l+r) >> 1;
	if (qr <= mid) modify(now<<1,l,mid,ql,qr,key);
	else if (ql > mid) modify(now<<1|1,mid+1,r,ql,qr,key);
	else modify(now<<1,l,mid,ql,mid,key),modify(now<<1|1,mid+1,r,mid+1,qr,key);
	tree[now] = max(tree[now<<1],tree[now<<1|1]);
}

inline void change(int now,int l,int r,int pos,int key)
{
	if (tag[now]) pushdown(now,l,r);
	if (l == r) { tree[now] = key; return; }
	int mid = (l+r) >> 1;
	if (pos <= mid) change(now<<1,l,mid,pos,key);
	else change(now<<1|1,mid+1,r,pos,key);
	tree[now] = max(tree[now<<1],tree[now<<1|1]);
}

inline void work()
{
	sort(P+1,P+N+1); build(1,1,N+1);
	stack <node> S1,S2; int mid = H>>1;
	change(1,1,N+1,1,H); S1.push(node(mid,0)); S2.push(node(H-mid,0));
	for (int i = 1;i <= N;++i)
	{
		ans = max(ans,(P[i].x+tree[1])<<1); int h;
		if (P[i].y <= mid)
		{
			for (h = mid;!S1.empty()&&mid-P[i].y < (S1.top()).x;h = (S1.top()).x,S1.pop())
				modify(1,1,N+1,(S1.top()).y+1,i,mid-P[i].y-h);
			if (S1.empty()) S1.push(node(mid-P[i].y,0));
			else modify(1,1,N+1,(S1.top()).y+1,i,mid-P[i].y-h);
			S1.push(node(mid-P[i].y,i));
		}
		else
		{
			for (h = H-mid;!S2.empty()&&P[i].y-mid < (S2.top()).x;h = (S2.top()).x,S2.pop())
				modify(1,1,N+1,(S2.top()).y+1,i,P[i].y-mid-h);
			if (S2.empty()) S2.push(node(P[i].y-mid,0));
			else modify(1,1,N+1,(S2.top()).y+1,i,P[i].y-mid-h);
			S2.push(node(P[i].y-mid,i));
		}
		change(1,1,N+1,i+1,H-P[i].x);
	}
	ans = max(ans,(W+tree[1])<<1);
}

int main()
{
//	freopen("D.in","r",stdin);
//	freopen("D.out","w",stdout);
	W = gi(); H = gi(); N = gi();
	for (int i = 1;i <= N;++i) P[i].read();
	ans = max((H+1)<<1,(W+1)<<1);
	work();
	for (int i = 1;i <= N;++i) swap(P[i].x,P[i].y); swap(H,W);
	work();
	cout << ans << endl;
	return 0;
}