You are playing a game with a bag of red and black balls. Initially, you are told that the bag has n balls total. In addition, you are also told that the bag has probability pi / 106 of containing exactly i red balls.You now would like to buy balls from this bag. You really like the color red, so red balls are worth a unit of 1, while black balls are worth nothing. To buy a ball, if there are still balls in the bag, you pay a cost c with 0 ≤ c ≤ 1, and draw a ball randomly from the bag. You can choose to stop buying at any point (and you can even choose to not buy anything at all).Given that you buy optimally to maximize the expected profit (i.e. # red balls - cost needed to obtain them), print the maximum expected profit.

The first line of input will contain two integers n, X (1 ≤ n ≤ 10 000, 0 ≤ X ≤ 106). The next line of input will contain n + 1 integers p0, p1, ... pn (0 ≤ pi ≤ 106, ) The value of c can be computed as .

Print a single floating point number representing the optimal expected value. Your answer will be accepted if it has absolute or relative error at most 10 - 9. More specifically, if your answer is a and the jury answer is b, your answer will be accepted if .

NoteHere, there is equal probability for the bag to contain 0,1,2,3 red balls. Also, it costs 0.2 to draw a ball from the bag.

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
#include <unordered_map>
#include <ctime>
typedef  long long ll;
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define inf9 (1000000000)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
#define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);}
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef unsigned int uint;
#define MAX 10025
bool debug = 0;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
string direc="RDLU";
ll ln, lk, lm;
void etp(bool f = 0) {
    puts(f ?"YES" : "NO");
    exit(0);
}
void addmod(int &x, int y, int mod = MOD) {
    assert(y>=0);
    x+=y; if (x>=mod) x-=mod;
    assert(x>=0 && x<mod);
}
void et() {
    puts("-1"); exit(0);
}

ld dp[2][MAX],p[2][MAX];
void fmain(int tid) {
    scanf("%d", &n);
    ld C;
    scanf("%Lf", &C); C/=1e6;
    for(int i=0;i<=n;i++) {
        scanf("%Lf", &p[0][i]); p[0][i]/=1e6;
        dp[0][i]=i;
    }
    int t=0;
    for(int i=n-1;~i;i--) {
        int cur =t^1, pre=t; t^=1;
        for(int red=0;red<=i;red++) {
            ld p1 = p[pre][red+1] * (red+1)/(i+1);
            ld p0 = p[pre][red] * (i+1-red) / (i+1);
            p[cur][red] = p0+p1;
            if (p[cur][red]==0) continue;
            ld P = p1/(p1+p0);
            ld tmp = P* dp[pre][red+1] + (1-P) * dp[pre][red] - C;
            dp[cur][red] = max(tmp, (ld)red);
        }
    }
    printf("%.10Lf\n", dp[t][0]);
}
int main() {
    int t=1;
//    scanf("%d", &t);
    REQ(i,t) {
        fmain(i);
    }
    return 0;
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 200005;
const ld PI = 4*atan((ld)1);

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1,T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T,SZ>& a);

    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
        re(first); re(rest...);
    }

    template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
    template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
    template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
}

using namespace input;

namespace output {
    template<class T1, class T2> void pr(const pair<T1,T2>& x);
    template<class T, size_t SZ> void pr(const array<T,SZ>& x);
    template<class T> void pr(const vector<T>& x);
    template<class T> void pr(const set<T>& x);
    template<class T1, class T2> void pr(const map<T1,T2>& x);

    template<class T> void pr(const T& x) { cout << x; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
        pr(first); pr(rest...);
    }

    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{",x.f,", ",x.s,"}");
    }
    template<class T> void prContain(const T& x) {
        pr("{");
        bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; // const needed for vector<bool>
        pr("}");
    }
    template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
    template<class T> void pr(const vector<T>& x) { prContain(x); }
    template<class T> void pr(const set<T>& x) { prContain(x); }
    template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

    void ps() { pr("\n"); }
    template<class Arg> void ps(const Arg& first) {
        pr(first); ps(); // no space at end of line
    }
    template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
        pr(first," "); ps(rest...); // print w/ spaces
    }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
    }
}

using namespace io;

template<class T> T invGeneral(T a, T b) {
    a %= b; if (a == 0) return b == 1 ? 0 : -1;
    T x = invGeneral(b,a);
    return x == -1 ? -1 : ((1-(ll)b*x)/a+b)%b;
}

template<class T> struct modular {
    T val;
    explicit operator T() const { return val; }
    modular() { val = 0; }
    modular(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD;
    }

    friend ostream& operator<<(ostream& os, const modular& a) { return os << a.val; }
    friend bool operator==(const modular& a, const modular& b) { return a.val == b.val; }
    friend bool operator!=(const modular& a, const modular& b) { return !(a == b); }
    friend bool operator<(const modular& a, const modular& b) { return a.val < b.val; }

    modular operator-() const { return modular(-val); }
    modular& operator+=(const modular& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
    modular& operator-=(const modular& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
    modular& operator*=(const modular& m) { val = (ll)val*m.val%MOD; return *this; }
    friend modular pow(modular a, ll p) {
        modular ans = 1; for (; p; p /= 2, a *= a) if (p&1) ans *= a;
        return ans;
    }
    friend modular inv(const modular& a) {
        auto i = invGeneral(a.val,MOD); assert(i != -1);
        return i;
    } // equivalent to return exp(b,MOD-2) if MOD is prime
    modular& operator/=(const modular& m) { return (*this) *= inv(m); }

    friend modular operator+(modular a, const modular& b) { return a += b; }
    friend modular operator-(modular a, const modular& b) { return a -= b; }
    friend modular operator*(modular a, const modular& b) { return a *= b; }

    friend modular operator/(modular a, const modular& b) { return a /= b; }
};

typedef modular<int> mi;
typedef pair<mi,mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
double c;
vd p, dp;

int main() {
    setIO(); re(n,c); c /= 1000000;
	p.rsz(n+1); re(p); trav(t,p) t /= 1000000;
	dp.rsz(n+1);
	F0Rd(sum,n) {
		F0R(i,sum+1) {
			double a = p[i]*(sum+1-i)/(sum+1), b = p[i+1]*(i+1)/(sum+1);
			p[i] = a+b;
			if (a+b > 0) {
				double z = b/(a+b);
				dp[i] = max(z*(dp[i+1]+1)+(1-z)*dp[i]-c,0.0);
			}
		}
		dp.pop_back(), p.pop_back();
	}
	cout << fixed << setprecision(12) << dp[0];
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/

// Wanna Hack? GL...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;/////

const int maxn=1e4+10,Six=1e6;

ld dp[maxn],f[maxn],C[maxn];

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n,x;cin>>n>>x;
    ld c=ld(x)/Six;
    C[0]=1;
    for(int i=1;i<=n;i++){
	for(int j=i;j>=1;j--)
	    C[j]+=C[j-1];
    }
    for(int i=0;i<=n;i++){
	cin>>f[i];
	if(f[i]==0) f[i]=1;
	else f[i]*=1e20;
	f[i]/=C[i];
    }
    for(int tot=n-1;tot>=0;tot--){
	for(int i=0;i<=tot;i++){
	    f[i]+=f[i+1];
	    dp[i]=max(ld(0),dp[i] -c + (f[i+1]/f[i])*(dp[i+1]-dp[i]+1));
	}
    }
    return cout<<setprecision(10)<<fixed<<dp[0]<<endl,0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 200005;
const ld PI = 4*atan((ld)1);

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

namespace input {
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1,T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T,SZ>& a);

    template<class T> void re(T& x) { cin >> x; }
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
        re(first); re(rest...);
    }

    template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
    template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
    template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
}

using namespace input;

namespace output {
    template<class T1, class T2> void pr(const pair<T1,T2>& x);
    template<class T, size_t SZ> void pr(const array<T,SZ>& x);
    template<class T> void pr(const vector<T>& x);
    template<class T> void pr(const set<T>& x);
    template<class T1, class T2> void pr(const map<T1,T2>& x);

    template<class T> void pr(const T& x) { cout << x; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
        pr(first); pr(rest...);
    }

    template<class T1, class T2> void pr(const pair<T1,T2>& x) {
        pr("{",x.f,", ",x.s,"}");
    }
    template<class T> void prContain(const T& x) {
        pr("{");
        bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0;
        pr("}");
    }
    template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
    template<class T> void pr(const vector<T>& x) { prContain(x); }
    template<class T> void pr(const set<T>& x) { prContain(x); }
    template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

    void ps() { pr("\n"); }
    template<class Arg> void ps(const Arg& first) {
        pr(first); ps();
    }
    template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
        pr(first," "); ps(rest...);
    }
}

using namespace output;

namespace io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
    }
}

using namespace io;

template<class T> T invGeneral(T a, T b) {
    a %= b; if (a == 0) return b == 1 ? 0 : -1;
    T x = invGeneral(b,a);
    return x == -1 ? -1 : ((1-(ll)b*x)/a+b)%b;
}

template<class T> struct modular {
    T val;
    explicit operator T() const { return val; }
    modular() { val = 0; }
    modular(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD;
    }

    friend ostream& operator<<(ostream& os, const modular& a) { return os << a.val; }
    friend bool operator==(const modular& a, const modular& b) { return a.val == b.val; }
    friend bool operator!=(const modular& a, const modular& b) { return !(a == b); }
    friend bool operator<(const modular& a, const modular& b) { return a.val < b.val; }

    modular operator-() const { return modular(-val); }
    modular& operator+=(const modular& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
    modular& operator-=(const modular& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
    modular& operator*=(const modular& m) { val = (ll)val*m.val%MOD; return *this; }
    friend modular pow(modular a, ll p) {
        modular ans = 1; for (; p; p /= 2, a *= a) if (p&1) ans *= a;
        return ans;
    }
    friend modular inv(const modular& a) {
        auto i = invGeneral(a.val,MOD); assert(i != -1);
        return i;
    }
    modular& operator/=(const modular& m) { return (*this) *= inv(m); }

    friend modular operator+(modular a, const modular& b) { return a += b; }
    friend modular operator-(modular a, const modular& b) { return a -= b; }
    friend modular operator*(modular a, const modular& b) { return a *= b; }

    friend modular operator/(modular a, const modular& b) { return a /= b; }
};

typedef modular<int> mi;
typedef pair<mi,mi> pmi;
typedef vector<mi> vmi;
typedef vector<pmi> vpmi;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
double c;
vd p, dp;

int main() {
    setIO(); re(n,c); c /= 1000000;
	p.rsz(n+1); re(p); trav(t,p) t /= 1000000;
	dp.rsz(n+1);
	F0Rd(sum,n) {
		F0R(i,sum+1) {
			double a = p[i]*(sum+1-i)/(sum+1), b = p[i+1]*(i+1)/(sum+1);
			p[i] = a+b;
			if (a+b > 0) {
				double z = b/(a+b);
				dp[i] = max(z*(dp[i+1]+1)+(1-z)*dp[i]-c,0.0);
			}
		}
		dp.pop_back(), p.pop_back();
	}
	cout << fixed << setprecision(12) << dp[0];
}

#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
using namespace std;
double c,pro[2][10001],dp[2][10001];
int n,x,ts;
int main()
{
	int i,j,s,p,q,flag;
	double proe;
	scanf("%d%d",&n,&x);
	c=x/1e6;
	for(i=0;i<=n;i++)
	{
		scanf("%d",&ts);
		pro[0][i]=ts/1e6;
	}
	flag=0;
	for(i=n-1;i>=0;i--)
	{
		for(j=0;j<=i;j++)
		{
			 pro[1-flag][j]=dp[1-flag][j]=0;
			 if(pro[flag][j]==0&&pro[flag][j+1]==0)
			     continue;
		      proe=pro[flag][j+1]*(j+1)/(pro[flag][j]*(i+1-j)+pro[flag][j+1]*(j+1));
             pro[1-flag][j]=(pro[flag][j+1]*(j+1)+pro[flag][j]*(i+1-j))/(i+1);
		     dp[1-flag][j]=max(0.,proe*(dp[flag][j+1]+1)+(1-proe)*dp[flag][j]-c);
		}
		pro[1-flag][i+1]=dp[1-flag][i+1]=0;
		flag^=1;
	}
	printf("%.20f\n",dp[flag][0]);
	return 0;
}

#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
using namespace std;
double c,pro[2][10001],dp[2][10001];
int n,x,ts;
int main()
{
	int i,j,s,p,q,flag;
	scanf("%d%d",&n,&x);
	c=x/1e6;
	for(i=0;i<=n;i++)
	{
		scanf("%d",&ts);
		pro[0][i]=ts/1e6;
	}
	flag=0;
	for(i=n-1;i>=0;i--)
	{
		for(j=0;j<=i;j++)
		{
			 dp[1-flag][j]=pro[1-flag][j]=0;
             if(pro[flag][j+1]==0&&pro[flag][j]==0)
                 continue;
			 double proe=pro[flag][j+1]*(j+1)/(pro[flag][j]*(i+1-j)+pro[flag][j+1]*(j+1));
             pro[1-flag][j]=(pro[flag][j+1]*(j+1)+pro[flag][j]*(i+1-j))/(i+1);
		     dp[1-flag][j]=max(dp[1-flag][j],proe*(dp[flag][j+1]+1)+(1-proe)*dp[flag][j]-c);
		}
		pro[1-flag][i+1]=dp[1-flag][i+1]=0;
		flag^=1;
	}
	printf("%.20f\n",dp[flag][0]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
double dp[2][N],p[2][N];
int n;double c;
int main ()
{
    ios::sync_with_stdio(false);
    scanf("%d%lf",&n,&c);c /= 1e6;
    for (int i = 0;i <= n;i++)
    {
        scanf("%lf",&p[0][i]);p[0][i] /= 1e6;
        dp[0][i] = i;
    }
    int cur = 1;
    for (int i = n - 1;i >= 0;--i,cur ^= 1)
    {
        int pre = cur ^ 1;
        for (int j = 0;j <= i;j++)
        {
            double p1 = p[pre][j + 1] * (j + 1) / (i + 1),
                p2 = p[pre][j] * (i + 1 - j) / (i + 1);
            p[cur][j] = p1 + p2;if (!p[cur][j]) continue;
            double P = p1 / (p1 + p2);
            dp[cur][j] = max(P * dp[pre][j + 1] + (1 - P) * dp[pre][j] - c,double(j));
        }
    }
    printf("%.10lf\n",dp[cur ^ 1][0]);
    return 0;
}

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=10005;
ld f[2][N],s[2][N],p[N],x;
int n,cur,nxt;

int main(){
	read(n),read(x);
	x/=1000000;
	rep(i,0,n){
		read(p[i]);
		p[i]/=1000000;
	}
	rep(i,0,n){
		s[cur][i]=p[i];
		rep(j,1,i) s[cur][i]=s[cur][i]/(n+1-j)*j;
	}
	nxt=1;
	per(i,n-1,0){
		rep(j,0,i){
			s[nxt][j]=s[cur][j]+s[cur][j+1];
			if(s[nxt][j]){
				ld A=s[cur][j+1]/s[nxt][j],B=1-A;
				ld now=A*(f[cur][j+1]+1)+B*f[cur][j]-x;
				f[nxt][j]=max(ld(0),now);
			}
			else f[nxt][j]=0;
		}
		swap(nxt,cur);
	}
	printf("%.10lf\n",double(f[cur][0]));
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define FORW(i,l,r) for(int i = int(l) ; i <= int(r) ; ++i)
#define FORD(i,r,l) for(int i = int(r) ; i >= int(l) ; --i)
#define sz(x)       x.size()
#define all(x)      x.begin(),x.end()
#define dou         double

const int   N   = 1e4 + 2;
const dou   X   = 1e6;

dou n, C;
dou f[2][N];
dou p[2][N];

int main()  {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	cin >> n >> C;  C /= X;

	FORW(i,0,n) {
		cin >> p[0][i];
		p[0][i] /= X;
		f[0][i] = i;
	}

	int t = 0;
	FORD(i,n - 1,0) {
		FORW(j,0,n) {
			p[t ^ 1][j] = (p[t][j + 1] * (j + 1) + p[t][j] * (i + 1 - j)) / (i + 1);

			dou p1 = p[t][j + 1] * (j + 1) / (i + 1);
			dou p2 = p[t][j] * (i + 1 - j) / (i + 1);
			if(p1 + p2 == 0)    continue;

			dou pr = p1 / (p1 + p2);
			f[t ^ 1][j] = max<dou>(j,pr * f[t][j + 1] + (1 - pr) * f[t][j] - C);
		}
		t ^= 1;
	}

	cout << fixed << setprecision(12) << f[t][0] << endl;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
#include <unordered_map>
#include <ctime>
typedef  long long ll;
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define inf9 (1000000000)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
#define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);}
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef unsigned int uint;
#define MAX 10025
bool debug = 0;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
string direc="RDLU";
ll ln, lk, lm;
void etp(bool f = 0) {
    puts(f ?"YES" : "NO");
    exit(0);
}
void addmod(int &x, int y, int mod = MOD) {
    assert(y>=0);
    x+=y; if (x>=mod) x-=mod;
    assert(x>=0 && x<mod);
}
void et() {
    puts("-1"); exit(0);
}

ld dp[2][MAX],p[2][MAX];
void fmain(int tid) {
    scanf("%d", &n);
    ld C;
    scanf("%Lf", &C); C/=1e6;
    for(int i=0;i<=n;i++) {
        scanf("%Lf", &p[0][i]); p[0][i]/=1e6;
        dp[0][i]=i;
    }
    int t=0;
    for(int i=n-1;~i;i--) {
        int cur =t^1, pre=t; t^=1;
        for(int red=0;red<=i;red++) {
            ld p1 = p[pre][red+1] * (red+1)/(i+1);
            ld p0 = p[pre][red] * (i+1-red) / (i+1);
            p[cur][red] = p0+p1;
            if (p[cur][red]==0) continue;
            ld P = p1/(p1+p0);
            ld tmp = P* dp[pre][red+1] + (1-P) * dp[pre][red] - C;
            dp[cur][red] = max(tmp, dp[cur][red]);
        }
    }
    printf("%.10Lf\n", dp[t][0]);
}
int main() {
    int t=1;
//    scanf("%d", &t);
    REQ(i,t) {
        fmain(i);
    }
    return 0;
}

// Wanna Hack? GL...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=1e4+10,Six=1e6;
const double eps=1e-12;

double p[maxn],f[2][maxn],dp[2][maxn],prob[2][maxn],C[2][maxn];

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n,x;cin>>n>>x;
    double c=double(x)/Six;
    C[0][0]=1;
    for(int i=1;i<=n;i++){
	C[i&1][0]=1;
	for(int j=1;j<=i;j++)
	    C[i&1][j]=C[1-(i&1)][j]+C[1-(i&1)][j-1];
    }
    for(int i=0;i<=n;i++)
	cin>>p[i],p[i]/=Six;
    for(int tot=n-1;tot>=0;tot--){
	int o=tot&1;
	for(int i=tot;i>=0;i--){
	    f[o][i]= tot==n-1 ? (p[i+1]/C[n&1][i+1]) : f[1-o][i]+f[1-o][i+1];
	    prob[o][i]= tot==n-1 ? (p[i+1]/C[n&1][i+1])+(p[i]/C[n&1][i]) : prob[1-o][i]+prob[1-o][i+1];
    //	    if(prob[o][i]==0) prob[o][i]=eps;
	    double P=f[o][i]/prob[o][i];
	    dp[o][i]=max(double(0),-c + (P)*(1+dp[1-o][i+1]) + (1-P)*(dp[1-o][i]) );
	}
    }
    return cout<<setprecision(10)<<fixed<<dp[0][0]<<endl,0;
}

// Wanna Hack? GL...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;/////

const int maxn=1e4+10,Six=1e6;

double p[maxn],f[maxn],dp[maxn],prob[maxn];
ld C[maxn];

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n,x;cin>>n>>x;
    ld c=ld(x)/Six;
    C[0]=1;
    for(int i=1;i<=n;i++){
	for(int j=i;j>=1;j--)
	    C[j]+=C[j-1];
    }
    for(int i=0;i<=n;i++){
	cin>>p[i],p[i]/=Six;
    }
    for(int tot=n-1;tot>=0;tot--){
	for(int i=0;i<=tot;i++){
	    if(tot==n-1) f[i]=p[i+1]/C[i+1],prob[i]=f[i]+(p[i]/C[i]);
	    else         f[i]+=f[i+1],prob[i]+=prob[i+1];
	    double P=f[i]/prob[i];
	    dp[i]=max(ld(0),-c + (P)*(1+dp[i+1]) + (1-P)*(dp[i]) );
	}
    }
    return cout<<setprecision(10)<<fixed<<dp[0]<<endl,0;
}

// Wanna Hack? GL...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=1e4+10,Six=1e6;
const double eps=1e-12;

int n;
double p[maxn],f[2][maxn],dp[2][maxn],prob[2][maxn],fac[maxn];

double C(int a,int b){
    if(b<0 || a<b) return 0;
    return fac[a]/fac[b]/fac[a-b];
}
double F(int a,int b){
    double ans=0;
    for(int i=a+1;i<=n-b;i++)
	ans+=((p[i]*C(n-a-b-1,i-a-1))/C(n,i));
    return ans;
}
double PP(int a,int b){
    double ans=0;
    for(int i=a;i<=n-b;i++)
	ans+=p[i]*(C(n-a-b,i-a)/C(n,i));
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int x;cin>>n>>x;
    double c=double(x)/Six;
    fac[0]=1;
    for(int i=1;i<=n;i++)
	fac[i]=i*fac[i-1];
    for(int i=0;i<=n;i++)
	cin>>p[i],p[i]/=Six;
    for(int tot=n-1;tot>=0;tot--){
	int o=tot&1;
	for(int i=tot;i>=0;i--){
	    f[o][i]=(i==0 || tot==i || tot==n-1?F(i,tot-i):f[1-o][i]+f[1-o][i+1]);
	    prob[o][i]=(i==0 || tot==i || tot==n-1?PP(i,tot-i):prob[1-o][i]+prob[1-o][i+1]);
	    if(prob[o][i]==0) prob[o][i]=eps;
	    double P=f[o][i]/prob[o][i];
	    dp[o][i]=max(double(0),-c + (P)*(1+dp[1-o][i+1]) + (1-P)*(dp[1-o][i]) );
	}
    }
    return cout<<setprecision(10)<<fixed<<dp[0][0]<<endl,0;
}

// Wanna Hack? GL...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;/////

const int maxn=1e4+10,Six=1e6;

ld p[maxn],f[maxn],dp[maxn],prob[maxn],C[maxn];

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n,x;cin>>n>>x;
    ld c=ld(x)/Six;
    C[0]=1;
    for(int i=1;i<=n;i++){
	for(int j=1;j<=i;j++)
	    C[j]+=C[j-1];
    }
    for(int i=0;i<=n;i++){
	cin>>p[i],p[i]/=Six;
    }
    for(int tot=n-1;tot>=0;tot--){
	for(int i=tot;i>=0;i--){
	    if(tot==n-1) f[i]=p[i+1]/C[i+1],prob[i]=f[i]+(p[i]/C[i]);
	    else         f[i]+=f[i+1],prob[i]+=prob[i+1];
	    double P=f[i]/prob[i];
	    dp[i]=max(ld(0),-c + (P)*(1+dp[i+1]) + (1-P)*(dp[i]) );
	}
    }
    return cout<<setprecision(10)<<fixed<<dp[0]<<endl,0;
}

// Wanna Hack? GL...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=1e3+10,Six=1e6;

int n;
double p[maxn],f[maxn][maxn],dp[maxn][maxn],prob[maxn][maxn],fac[maxn];

double C(int a,int b){
    if(b<0 || a<b) return 0;
    return fac[a]/fac[b]/fac[a-b];
}
double F(int a,int b){
    double ans=0;
    for(int i=a+1;i<=n-b;i++)
	ans+=((p[i]*C(n-a-b-1,i-a-1))/C(n,i));
    return ans;
}
double PP(int a,int b){
    double ans=0;
    for(int i=a;i<=n-b;i++)
	ans+=p[i]*(C(n-a-b,i-a)/C(n,i));
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int x;cin>>n>>x;
    double c=double(x)/Six;
    fac[0]=1;
    for(int i=1;i<=n;i++)
	fac[i]=i*fac[i-1];
    for(int i=0;i<=n;i++)
	cin>>p[i],p[i]/=Six;
    for(int tot=0;tot<n;tot++)
	for(int i=0;i<=tot;i++)
	    f[tot][i]=(i==0 ||tot==i || tot==n-1?F(i,tot-i):f[tot-1][i]+f[tot-1][i-1]);
    prob[0][0]=1;
    for(int tot=0;tot<n;tot++)
	for(int i=0;i<=tot;i++)
	    prob[tot][i]=(i==0 || tot==i || tot==n-1?PP(i,tot-i):prob[tot-1][i]+prob[tot-1][i-1]);
    for(int tot=n-1;tot>=0;tot--)
	for(int i=0;i<=tot;i++){
	    double P=f[tot][i]/prob[tot][i];
	    dp[tot][i]=max(double(0),-c + (P)*(1+dp[tot+1][i+1]) + (1-P)*(dp[tot+1][i]) );
	}
    return cout<<setprecision(10)<<fixed<<dp[0][0]<<endl,0;
}

// Wanna Hack? GL...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef double ld;

const int maxn=1e4+10,Six=1e6;
const double eps=1e-12;

ld p[maxn],f[2][maxn],dp[2][maxn],prob[2][maxn],C[2][maxn];

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n,x;cin>>n>>x;
    ld c=ld(x)/Six;
    C[0][0]=1;
    for(int i=1;i<=n;i++){
	C[i&1][0]=1;
	for(int j=1;j<=i;j++)
	    C[i&1][j]=C[1-(i&1)][j]+C[1-(i&1)][j-1];
    }
    for(int i=0;i<=n;i++)
	cin>>p[i],p[i]/=Six;
    for(int tot=n-1;tot>=0;tot--){
	int o=tot&1;
	for(int i=tot;i>=0;i--){
	    f[o][i]= tot==n-1 ? (p[i+1]/C[n&1][i+1]) : f[1-o][i]+f[1-o][i+1];
	    prob[o][i]= tot==n-1 ? (p[i+1]/C[n&1][i+1])+(p[i]/C[n&1][i]) : prob[1-o][i]+prob[1-o][i+1];
    //	    if(prob[o][i]==0) prob[o][i]=eps;
	    double P=f[o][i]/prob[o][i];
	    dp[o][i]=max(ld(0),-c + (P)*(1+dp[1-o][i+1]) + (1-P)*(dp[1-o][i]) );
	}
    }
    return cout<<setprecision(10)<<fixed<<dp[0][0]<<endl,0;
}

// Wanna Hack? GL...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;/////

const int maxn=1e4+10,Six=1e6;

ld p[maxn],f[maxn],dp[maxn],prob[maxn],C[maxn];

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n,x;cin>>n>>x;
    ld c=ld(x)/Six;
    C[0]=1;
    for(int i=1;i<=n;i++){
	for(int j=i;j>=1;j--)
	    C[j]+=C[j-1];
    }
    for(int i=0;i<=n;i++){
	cin>>p[i],p[i]/=Six;
    }
    for(int tot=n-1;tot>=0;tot--){
	for(int i=0;i<=tot;i++){
	    if(tot==n-1) f[i]=p[i+1]/C[i+1],prob[i]=f[i]+(p[i]/C[i]);
	    else         f[i]+=f[i+1],prob[i]+=prob[i+1];
	    ld P=f[i]/prob[i];
	    dp[i]+=-c+P*(1+dp[i+1]-dp[i]);
	    if(dp[i]<0) dp[i]=0;
	}
    }
    return cout<<setprecision(10)<<fixed<<dp[0]<<endl,0;
}

// Wanna Hack? GL...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=1e4+10,Six=1e6;

int n;
double p[maxn],f[2][maxn],dp[2][maxn],prob[2][maxn],fac[maxn];

double C(int a,int b){
    if(b<0 || a<b) return 0;
    return fac[a]/fac[b]/fac[a-b];
}
double F(int a,int b){
    double ans=0;
    for(int i=a+1;i<=n-b;i++)
	ans+=((p[i]*C(n-a-b-1,i-a-1))/C(n,i));
    return ans;
}
double PP(int a,int b){
    double ans=0;
    for(int i=a;i<=n-b;i++)
	ans+=p[i]*(C(n-a-b,i-a)/C(n,i));
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int x;cin>>n>>x;
    double c=double(x)/Six;
    fac[0]=1;
    for(int i=1;i<=n;i++)
	fac[i]=i*fac[i-1];
    for(int i=0;i<=n;i++)
	cin>>p[i],p[i]/=Six;
    for(int tot=n-1;tot>=0;tot--){
	int o=tot&1;
	for(int i=tot;i>=0;i--){
	    f[o][i]=(i==0 ||tot==i || tot==n-1?F(i,tot-i):f[1-o][i]+f[1-o][i+1]);
	    prob[o][i]=(i==0 || tot==i || tot==n-1?PP(i,tot-i):prob[1-o][i]+prob[1-o][i+1]);
	    double P=f[o][i]/prob[o][i];
	    dp[o][i]=max(double(0),-c + (P)*(1+dp[1-o][i+1]) + (1-P)*(dp[1-o][i]) );
	}
    }
    return cout<<setprecision(10)<<fixed<<dp[0][0]<<endl,0;
}

#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
using namespace std;
double c,pro[2][10001],dp[2][10001];
int n,x,ts;
int main()
{
	int i,j,s,p,q,flag;
	scanf("%d%d",&n,&x);
	c=x/1e6;
	for(i=0;i<=n;i++)
	{
		scanf("%d",&ts);
		pro[0][i]=ts/1e6;
	}
	flag=0;
	for(i=n-1;i>=0;i--)
	{
		for(j=0;j<=i;j++)
		{
			 dp[1-flag][j]=pro[1-flag][j]=0;
             if(pro[flag][j+1]<1e-11&&pro[flag][j+1]<1e-11)
                 continue;
			 double proe=pro[flag][j+1]*(j+1)/(pro[flag][j]*(i+1-j)+pro[flag][j+1]*(j+1));
             pro[1-flag][j]=(pro[flag][j+1]*(j+1)+pro[flag][j]*(i+1-j))/(i+1);
		     dp[1-flag][j]=max(dp[1-flag][j],proe*(dp[flag][j+1]+1)+(1-proe)*dp[flag][j]-c);
		}
		pro[1-flag][i+1]=dp[1-flag][i+1]=0;
		flag^=1;
	}
	printf("%.20f\n",dp[flag][0]);
	return 0;
}

#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
using namespace std;
double c,pro[2][10001],dp[2][10001];
int n,x,ts;
int main()
{
	int i,j,s,p,q,flag;
	scanf("%d%d",&n,&x);
	c=x/1e6;
	for(i=0;i<=n;i++)
	{
		scanf("%d",&ts);
		pro[0][i]=ts/1e6;
	}
	flag=0;
	for(i=n-1;i>=0;i--)
	{
		for(j=0;j<=i;j++)
		{
			 dp[1-flag][j]=0;
             if(pro[flag][j+1]<1e-11&&pro[flag][j+1]<1e-11)
                 continue;
			 double proe=pro[flag][j+1]*(j+1)/(pro[flag][j]*(i+1-j)+pro[flag][j+1]*(j+1));
             pro[1-flag][j]=(pro[flag][j+1]*(j+1)+pro[flag][j]*(i+1-j))/(i+1);
		     dp[1-flag][j]=max(dp[1-flag][j],proe*(dp[flag][j+1]+1)+(1-proe)*dp[flag][j]-c);
		}
		pro[1-flag][i+1]=dp[1-flag][i+1]=0;
		flag^=1;
	}
	printf("%.20f\n",dp[flag][0]);
	return 0;
}

#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
using namespace std;
double c,pro[2][10001],dp[2][10001];
int n,x,ts;
int main()
{
	int i,j,s,p,q,flag;
	scanf("%d%d",&n,&x);
	c=x/1e6;
	for(i=0;i<=n;i++)
	{
		scanf("%d",&ts);
		pro[0][i]=ts/1e6;
	}
	flag=0;
	for(i=n-1;i>=0;i--)
	{
		for(j=0;j<=i;j++)
		{
			 dp[1-flag][j]=pro[1-flag][j]=0;
             if(pro[flag][j+1]<1e-11&&pro[flag][j]<1e-11)
                 continue;
			 double proe=pro[flag][j+1]*(j+1)/(pro[flag][j]*(i+1-j)+pro[flag][j+1]*(j+1));
             pro[1-flag][j]=(pro[flag][j+1]*(j+1)+pro[flag][j]*(i+1-j))/(i+1);
		     dp[1-flag][j]=max(dp[1-flag][j],proe*(dp[flag][j+1]+1)+(1-proe)*dp[flag][j]-c);
		}
		pro[1-flag][i+1]=dp[1-flag][i+1]=0;
		flag^=1;
	}
	printf("%.20f\n",dp[flag][0]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 11000;

double p[N], e[N], dp[N], _dp[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n; scanf("%d", &n);
	double c, x; scanf("%lf", &c); c /= 1e6;
	for (int i = 0; i <= n; i++) scanf("%lf", &x), p[i] = x / 1e6;
	double ret = 1;
	for (int i = 0; i <= n / 2; i++) {
		p[i] /= ret;
		e[i] = p[i] * i;
		dp[i] = i - n * c;
		if (i + i < n) {
			p[n - i] /= ret;
			e[n - i] = p[n - i] * (n - i);
			dp[n - i] = n - i - n * c;
		}
		ret /= i + 1;
		ret *= n - i;
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= i; j++) {
			p[j] += p[j + 1];
			e[j] += e[j + 1];
		}
		for (int j = 0; j <= i; j++) {
			double prob = min(1.0, max(0.0, (e[j] / p[j] - j) / (n - i)));
			_dp[j] = max(j - i * c, dp[j] * (1 - prob) + dp[j + 1] * prob);
		}
		for (int j = 0; j <= i; j++) dp[j] = _dp[j];
	}
	printf("%.15f\n", dp[0]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 11000;

double p[N], e[N], dp[N], _dp[N];

int main() {
	int n; scanf("%d", &n);
	double c, x; scanf("%lf", &c); c /= 1e6;
	for (int i = 0; i <= n; i++) scanf("%lf", &x), p[i] = x / 1e6;
	double ret = 1;
	for (int i = 0; i <= n / 2; i++) {
		p[i] /= ret;
		e[i] = p[i] * i;
		dp[i] = i - n * c;
		if (i + i < n) {
			p[n - i] /= ret;
			e[n - i] = p[n - i] * (n - i);
			dp[n - i] = n - i - n * c;
		}
		ret /= i + 1;
		ret *= n - i;
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= i; j++) {
			p[j] += p[j + 1];
			e[j] += e[j + 1];
		}
		for (int j = 0; j <= i; j++) {
			if (fabs(p[j]) < 1e-100) {
				_dp[j] = j - i * c;
				continue;
			}
			double prob = (e[j] / p[j] - j) / (n - i);
			_dp[j] = max(j - i * c, dp[j] * (1 - prob) + dp[j + 1] * prob);
		}
		for (int j = 0; j <= i; j++) dp[j] = _dp[j];
	}
	printf("%.15f\n", dp[0]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 11000;

double p[N], e[N], dp[N], _dp[N];

int main() {
	int n; scanf("%d", &n);
	double c, x; scanf("%lf", &c); c /= 1e6;
	for (int i = 0; i <= n; i++) scanf("%lf", &x), p[i] = x / 1e6;
	double ret = 1;
	for (int i = 0; i <= n / 2; i++) {
		p[i] /= ret;
		e[i] = p[i] * i;
		dp[i] = i - n * c;
		if (i + i < n) {
			p[n - i] /= ret;
			e[n - i] = p[n - i] * (n - i);
			dp[n - i] = n - i - n * c;
		}
		ret /= i + 1;
		ret *= n - i;
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= i; j++) {
			p[j] += p[j + 1];
			e[j] += e[j + 1];
		}
		for (int j = 0; j <= i; j++) {
			long double prob = ((long double)e[j] - (long double)j * p[j]) / p[j] / (n - i);
			_dp[j] = max((long double)j - i * c, dp[j] * (1 - prob) + dp[j + 1] * prob);
		}
		for (int j = 0; j <= i; j++) dp[j] = _dp[j];
	}
	printf("%.15f\n", dp[0]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 11000;

double p[N], e[N], dp[N], _dp[N];

int main() {
	int n; scanf("%d", &n);
	double c; scanf("%lf", &c); c /= 1e6;
	for (int i = 0; i <= n; i++) scanf("%lf", &p[i]), p[i] /= 1e6;
	double ret = 1;
	for (int i = 0; i <= n; i++) {
		p[i] *= ret;
		e[i] = p[i] * i;
		dp[i] = i - n * c;
		if (i < n) ret *= 1.0 * (i + 1) / (n - i);
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= i; j++) {
			p[j] += p[j + 1];
			e[j] += e[j + 1];
		}
		for (int j = 0; j <= i; j++) {
			double prob = (e[j] / p[j] - j) / (n - i);
			_dp[j] = max(j - i * c, dp[j] * (1 - prob) + dp[j + 1] * prob);
		}
		for (int j = 0; j <= i; j++) dp[j] = _dp[j];
	}
	printf("%.12lf\n", dp[0]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 11000;

double p[N], e[N], dp[N], _dp[N];

int main() {
	int n; scanf("%d", &n);
	double c, x; scanf("%lf", &c); c /= 1e6;
	for (int i = 0; i <= n; i++) scanf("%lf", &x), p[i] = x / 1e6;
	double ret = 1;
	for (int i = 0; i <= n / 2; i++) {
		p[i] /= ret;
		e[i] = p[i] * i;
		dp[i] = i - n * c;
		if (i + i < n) {
			p[n - i] /= ret;
			e[n - i] = p[n - i] * (n - i);
			dp[n - i] = n - i - n * c;
		}
		ret /= i + 1;
		ret *= n - i;
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= i; j++) {
			p[j] += p[j + 1];
			e[j] += e[j + 1];
		}
		for (int j = 0; j <= i; j++) {
			double prob = (e[j] / p[j] - j) / (n - i);
			_dp[j] = max(j - i * c, dp[j] * (1 - prob) + dp[j + 1] * prob);
		}
		for (int j = 0; j <= i; j++) dp[j] = _dp[j];
	}
	printf("%.15f\n", dp[0]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 11000;

double p[N], e[N], dp[N], _dp[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n; scanf("%d", &n);
	double cc, x; scanf("%lf", &cc); double c = cc / 1e6;
	for (int i = 0; i <= n; i++) scanf("%lf", &x), p[i] = x / 1e6;
	double ret = 1;
	for (int i = 0; i <= n; i++) {
		p[i] /= ret;
		e[i] = p[i] * i;
		dp[i] = i - n * c;
		ret /= i + 1;
		ret *= n - i;
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= i; j++) {
			p[j] += p[j + 1];
			e[j] += e[j + 1];
		}
		for (int j = 0; j <= i; j++) {
			double prob = (e[j] / p[j] - j) / (n - i);
			_dp[j] = max(j - i * c, dp[j] * (1 - prob) + dp[j + 1] * prob);
		}
		for (int j = 0; j <= i; j++) dp[j] = _dp[j];
	}
	printf("%.15f\n", dp[0]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 11000;

double p[N], e[N], dp[N], _dp[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n; scanf("%d", &n);
	double c, x; scanf("%lf", &c); c /= 1e6;
	for (int i = 0; i <= n; i++) scanf("%lf", &x), p[i] = x / 1e6;
	double ret = 1;
	for (int i = 0; i <= n / 2; i++) {
		p[i] /= ret;
		e[i] = p[i] * i;
		dp[i] = i - n * c;
		if (i + i < n) {
			p[n - i] /= ret;
			e[n - i] = p[n - i] * (n - i);
			dp[n - i] = n - i - n * c;
		}
		ret /= i + 1;
		ret *= n - i;
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= i; j++) {
			p[j] += p[j + 1];
			e[j] += e[j + 1];
		}
		for (int j = 0; j <= i; j++) {
			double prob = max(0.0, min(1.0, (e[j] - j * p[j]) / p[j] / (n - i)));
			_dp[j] = max(j - i * c, dp[j] * (1 - prob) + dp[j + 1] * prob);
		}
		for (int j = 0; j <= i; j++) dp[j] = _dp[j];
	}
	printf("%.15f\n", dp[0]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 11000;

double p[N], e[N], dp[N], _dp[N];

int main() {
	int n; scanf("%d", &n);
	double c, x; scanf("%lf", &c); c /= 1e6;
	for (int i = 0; i <= n; i++) scanf("%lf", &x), p[i] = x * 1e20;
	double ret = 1;
	for (int i = 0; i <= n / 2; i++) {
		p[i] /= ret;
		e[i] = p[i] * i;
		dp[i] = i - n * c;
		if (i + i < n) {
			p[n - i] /= ret;
			e[n - i] = p[n - i] * (n - i);
			dp[n - i] = n - i - n * c;
		}
		ret /= i + 1;
		ret *= n - i;
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= i; j++) {
			p[j] += p[j + 1];
			e[j] += e[j + 1];
		}
		for (int j = 0; j <= i; j++) _dp[j] = j - i * c;
		for (int j = 0; j <= i; j++) {
			double prob = (e[j] - j * p[j]) / p[j] / (n - i);
			_dp[j] = max(j - i * c, dp[j] * (1 - prob) + dp[j + 1] * prob);
		}
		for (int j = 0; j <= i; j++) dp[j] = _dp[j];
	}
	printf("%.15f\n", (double)dp[0]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 11000;

double p[N], e[N], dp[N], _dp[N];

int main() {
	int n; scanf("%d", &n);
	double c, x; scanf("%lf", &c); c /= 1e6;
	for (int i = 0; i <= n; i++) scanf("%lf", &x), p[i] = x / 1e6;
	double ret = 1;
	for (int i = 0; i <= n / 2; i++) {
		p[i] /= ret;
		e[i] = p[i] * i;
		dp[i] = i - n * c;
		if (i + i < n) {
			p[n - i] /= ret;
			e[n - i] = p[n - i] * (n - i);
			dp[n - i] = n - i - n * c;
		}
		ret /= i + 1;
		ret *= n - i;
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= i; j++) {
			p[j] += p[j + 1];
			e[j] += e[j + 1];
		}
		for (int j = 0; j <= i; j++) {
			if (p[j] < 1e-200) _dp[j] = j - i * c;
			else {
				double prob = min(1.0, max(0.0, (e[j] / p[j] - j) / (n - i)));
				_dp[j] = max(j - i * c, dp[j] * (1 - prob) + dp[j + 1] * prob);
			}
		}
		for (int j = 0; j <= i; j++) dp[j] = _dp[j];
	}
	printf("%.15f\n", dp[0]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 11000;

double p[N], e[N], dp[N], _dp[N];

int main() {
	int n; scanf("%d", &n);
	double c, x; scanf("%lf", &c); c /= 1e6;
	for (int i = 0; i <= n; i++) scanf("%lf", &x), p[i] = x * 1e100;
	double ret = 1;
	for (int i = 0; i <= n / 2; i++) {
		p[i] /= ret;
		e[i] = p[i] * i;
		dp[i] = i - n * c;
		if (i + i < n) {
			p[n - i] /= ret;
			e[n - i] = p[n - i] * (n - i);
			dp[n - i] = n - i - n * c;
		}
		ret /= i + 1;
		ret *= n - i;
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= i; j++) {
			p[j] += p[j + 1];
			e[j] += e[j + 1];
		}
		for (int j = 0; j <= i; j++) _dp[j] = j - i * c;
		for (int j = 0; j <= i; j++) {
			double prob = (e[j] - j * p[j]) / p[j] / (n - i);
			if (prob == 0) _dp[j] = j - i * c;
			else if (prob == 1) _dp[j] = dp[j + 1];
			else  _dp[j] = max(j - i * c, dp[j] * (1 - prob) + dp[j + 1] * prob);
		}
		for (int j = 0; j <= i; j++) dp[j] = _dp[j];
	}
	printf("%.15f\n", (double)dp[0]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 11000;

double p[N], e[N], dp[N], _dp[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n; scanf("%d", &n);
	double c, x; scanf("%lf", &c); c /= 1e6;
	for (int i = 0; i <= n; i++) scanf("%lf", &x), p[i] = x / 1e6;
	double ret = 1;
	for (int i = 0; i <= n / 2; i++) {
		p[i] /= ret;
		e[i] = p[i] * i;
		dp[i] = i - n * c;
		if (i + i < n) {
			p[n - i] /= ret;
			e[n - i] = p[n - i] * (n - i);
			dp[n - i] = n - i - n * c;
		}
		ret /= i + 1;
		ret *= n - i;
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= i; j++) {
			p[j] += p[j + 1];
			e[j] += e[j + 1];
		}
		for (int j = 0; j <= i; j++) {
			double prob = (e[j] - j * p[j]) / p[j] / (n - i);
			_dp[j] = max(j - i * c, dp[j] * (1 - prob) + dp[j + 1] * prob);
		}
		for (int j = 0; j <= i; j++) dp[j] = _dp[j];
	}
	printf("%.15f\n", dp[0]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 11000;

double p[N], e[N], dp[N], _dp[N];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n; scanf("%d", &n);
	double c, x; scanf("%lf", &c); c /= 1e6;
	for (int i = 0; i <= n; i++) scanf("%lf", &x), p[i] = x * 1e20;
	double ret = 1;
	for (int i = 0; i <= n / 2; i++) {
		p[i] /= ret;
		e[i] = p[i] * i;
		dp[i] = i - n * c;
		if (i + i < n) {
			p[n - i] /= ret;
			e[n - i] = p[n - i] * (n - i);
			dp[n - i] = n - i - n * c;
		}
		ret /= i + 1;
		ret *= n - i;
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j <= i; j++) {
			p[j] += p[j + 1];
			e[j] += e[j + 1];
		}
		for (int j = 0; j <= i; j++) _dp[j] = j - i * c;
		for (int j = 0; j <= i; j++) {
			double prob = (e[j] - j * p[j]) / p[j] / (n - i);
			if (prob == 0) _dp[j] = j - i * c;
			else if (prob == 1) _dp[j] = dp[j + 1];
			else  _dp[j] = max(j - i * c, dp[j] * (1 - prob) + dp[j + 1] * prob);
		}
		for (int j = 0; j <= i; j++) dp[j] = _dp[j];
	}
	printf("%.15f\n", (double)dp[0]);
	return 0;
}

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <assert.h>
int N, M, Q, B, L, a[100001], d[100001], A[47][47], cnt[47][100001], LA;
int Query(int, int);
void Change(int p, int w)
{
	if (a[p] == w)
		return;
	int bel = (p - 1) / L + 1;
	for (int i = 0; i < bel; i++)
		for (int j = bel; j <= B; j++)
			A[i][j] += d[cnt[j][w] - cnt[i][w] + 1] - d[cnt[j][a[p]] - cnt[i][a[p]]];
	for (int i = bel; i <= B; i++)
	{
		cnt[i][a[p]]--;
		cnt[i][w]++;
	}
	a[p] = w;
}
int Query(int l, int r)
{
	static int u[100001];
	int bl = (l + L - 2) / L, br = r / L;
	if (bl > br)
	{
		int O = 0;
		for (int i = l; i <= r; i++)
			O += d[++u[a[i]]];
		for (int i = l; i <= r; i++)
			u[a[i]] = 0;
		return O;
	}
	else
	{
		int O = A[bl][br];
		for (int i = l; i <= bl * L; i++)
			O += d[++u[a[i]] + cnt[br][a[i]] - cnt[bl][a[i]]];
		for (int i = r; i > br * L; i--)
			O += d[++u[a[i]] + cnt[br][a[i]] - cnt[bl][a[i]]];
		for (int i = l; i <= bl * L; i++)
			u[a[i]] = 0;
		for (int i = r; i > br * L; i--)
			u[a[i]] = 0;
		return O;
	}
}
int main()
{
	scanf("%d%d%d", &N, &M, &Q);
	for (int i = 1; i <= N; i++)
		scanf("%d", a + i);
	for (int i = 1; i <= N; i++)
		scanf("%d", d + i);
	L = std::min(N, std::max(1, int(exp(log(N) * 2 / 3))));
	B = N / L;
	for (int i = 1; i <= B; i++)
	{
		for (int j = 1; j <= M; j++)
			cnt[i][j] = cnt[i - 1][j];
		for (int j = (i - 1) * L + 1; j <= i * L; j++)
			cnt[i][a[j]]++;
	}
	for (int i = 0; i < B; i++)
		for (int j = i + 1; j <= B; j++)
			for (int k = 1; k <= M; k++)
				A[i][j] += d[cnt[j][k] - cnt[i][k]];
	for (int i = N; i; i--)
		d[i] -= d[i - 1];
	while (Q--)
	{
		int op, x, y;
		scanf("%d%d%d", &op, &x, &y);
		//x ^= LA;
		//y ^= LA;
		if (op == 1)
			Change(x, y);
		else
			printf("%d\n", LA = Query(x, y));
	}
	return 0;
}

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef double ld;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=10005;
const ld eps=1e-16;
ld f[2][N],s[2][N],p[N],x;
int n,cur,nxt;

int main(){
	read(n),read(x);
	x/=1000000;
	rep(i,0,n){
		read(p[i]);
		p[i]/=1000000;
	}
	rep(i,0,n) s[cur][i]=p[i];
	nxt=1;
	per(i,n-1,0){
		rep(j,0,i){
			s[nxt][j]=s[cur][j]+s[cur][j+1];
			if(s[nxt][j]>eps){
				ld A=s[cur][j+1]/s[nxt][j],B=1-A;
				ld now=A*(f[cur][j+1]+1)+B*f[cur][j]-x;
				f[nxt][j]=max(0.0,now);
			}
		}
		swap(nxt,cur);
	}
	printf("%.10lf\n",f[cur][0]);
	return 0;
}

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef double ld;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=10005;
const ld eps=1e-16;
ld f[2][N],s[2][N],p[N],x;
int n,cur,nxt;

int main(){
	read(n),read(x);
	x/=1000000;
	rep(i,0,n){
		read(p[i]);
		p[i]/=1000000;
	}
	rep(i,0,n){
		s[cur][i]=p[i];
		rep(j,1,i) s[cur][i]=s[cur][i]/(n+1-j)*j;
	}
	nxt=1;
	per(i,n-1,0){
		memset(f[nxt],0,sizeof f[nxt]);
		memset(s[nxt],0,sizeof s[nxt]);
		rep(j,0,i){
			s[nxt][j]=s[cur][j]+s[cur][j+1];
			if(s[nxt][j]>eps){
				ld A=s[cur][j+1]/s[nxt][j],B=1-A;
				ld now=A*(f[cur][j+1]+1)+B*f[cur][j]-x;
				f[nxt][j]=max(0.0,now);
//				printf("%d %d   %.4lf  %.2lf\n",i,j,f[nxt][j],A);
			}
		}
		swap(nxt,cur);
	}
	printf("%.10lf\n",f[cur][0]);
	return 0;
}

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef double ld;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=10005;
ld f[2][N],s[2][N],p[N],x;
int n,cur,nxt;

int main(){
	read(n),read(x);
	x/=1000000;
	rep(i,0,n){
		read(p[i]);
		p[i]/=1000000;
	}
	rep(i,0,n){
		s[cur][i]=p[i];
		rep(j,1,i) s[cur][i]=s[cur][i]/(n+1-j)*j;
	}
	nxt=1;
	per(i,n-1,0){
		memset(f[nxt],0,sizeof f[nxt]);
		memset(s[nxt],0,sizeof s[nxt]);
		rep(j,0,i){
			s[nxt][j]=s[cur][j]+s[cur][j+1];
			if(s[nxt][j]){
				ld A=s[cur][j+1]/s[nxt][j],B=1-A;
				ld now=A*(f[cur][j+1]+1)+B*f[cur][j]-x;
				f[nxt][j]=max(0.0,now);
			}
		}
		swap(nxt,cur);
	}
	printf("%.10lf\n",f[cur][0]);
	return 0;
}