Problem:
Score : 100 points

Problem Statement

Let N be a positive odd number.

There are N coins, numbered 1, 2, \ldots, N.
For each i (1 \leq i \leq N), when Coin i is tossed, it comes up heads with probability p_i and tails with probability 1 - p_i.

Taro has tossed all the N coins.
Find the probability of having more heads than tails.

Constraints

N is an odd number.

1 \leq N \leq 2999

p_i is a real number and has two decimal places.

0 < p_i < 1

Input

Input is given from Standard Input in the following format:

N
p_1 p_2 \ldots p_N

Output

Print the probability of having more heads than tails.
The output is considered correct when the absolute error is not greater than 10^{-9}.

Sample Input 1

3
0.30 0.60 0.80

Sample Output 1

0.612

The probability of each case where we have more heads than tails is as follows:

The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Head) is 0.3 × 0.6 × 0.8 = 0.144;

The probability of having (Coin 1, Coin 2, Coin 3) = (Tail, Head, Head) is 0.7 × 0.6 × 0.8 = 0.336;

The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Tail, Head) is 0.3 × 0.4 × 0.8 = 0.096;

The probability of having (Coin 1, Coin 2, Coin 3) = (Head, Head, Tail) is 0.3 × 0.6 × 0.2 = 0.036.

Thus, the probability of having more heads than tails is 0.144 + 0.336 + 0.096 + 0.036 = 0.612.

Sample Input 2

1
0.50

Sample Output 2

0.5

Outputs such as 0.500, 0.500000001 and 0.499999999 are also considered correct.

Sample Input 3

5
0.42 0.01 0.42 0.99 0.42

Sample Output 3

0.3821815872

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput());
            int n = scan.Integer();
            double[] p = new double[n];
            for (int i = 0; i < n; i++)
            {
                p[i] = scan.Double();
            }
           double[,] dp = new double[n+1, n + 1];
            dp[0, 0] = 1;
            for (int i = 1; i <= n; i++)
            {
                for (int k = 0; k <= n; k++)
                {
                    double mae = 0;
                    if (k > 0) { mae = dp[i - 1, k - 1] * p[i-1]; }
                    dp[i, k] = mae + dp[i - 1, k] * (1 - p[i-1]);
                }
            }
            double ans = 0;
            for (int i = (n + 1) / 2; i <= n; i++)
            {
                ans += dp[n, i];
            }
            Console.WriteLine(ans);
        }
        static int nibutan(int med,int[]a)//med以上が何個あるか
        {
            int mae = 0;
            int ato = a.Length;
            while (true)
            {
                if (ato - mae <= 1) {
                    return mae; }
                int mid = (mae + ato) / 2;
                if (a[mid] > med) { ato = mid; }
                if (a[mid] <= med) { mae = mid; }
            }
        }


        public static int h;
        public static int w;
        public static int BFS(int height, int width, char[,] map)
        {
            int[] dx = new int[] { -1, 0, 0, 1 };
            int[] dy = new int[] { 0, 1, -1, 0 };
            bool[,] visited = new bool[h, w];
            int[,] len = new int[h, w];
            var queue = new Queue<Tuple<int, int>>();
            queue.Enqueue(new Tuple<int, int>(height, width));
            int max = 0;
            visited[height, width] = true;

            while (queue.Count > 0)
            {
                var now = queue.Dequeue();
                for (int i = 0; i < 4; i++)
                {
                    int ny = now.Item1 + dy[i];
                    int nx = now.Item2 + dx[i];
                    if (ny >= h || ny < 0 || nx >= w || nx < 0)
                        continue;
                    if (visited[ny, nx] || map[ny, nx] == '#')
                        continue;
                    visited[ny, nx] = true;
                    len[ny, nx] = len[now.Item1, now.Item2] + 1;
                    max = Math.Max(max, len[ny, nx]);
                    queue.Enqueue(new Tuple<int, int>(ny, nx));
                }
            }
            return max;
        }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        private readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) throw new EndOfStreamException();
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }
        public char Char()
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b;
        }
        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (int)Long(); }
        public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
    public class UnionFind
    {
        public int[] data;

        public UnionFind(int size)
        {
            data = new int[size];
            for (int i = 0; i < size; i++) data[i] = -1;
        }

        public bool Unite(int x, int y)
        {
            x = Root(x);
            y = Root(y);

            if (x != y)
            {
                if (data[y] < data[x])
                {
                    var tmp = y;
                    y = x;
                    x = tmp;
                }
                data[x] += data[y];
                data[y] = x;
            }
            return x != y;
        }

        public bool IsSameGroup(int x, int y)
        {
            return Root(x) == Root(y);
        }

        public int Root(int x)
        {
            return data[x] < 0 ? x : data[x] = Root(data[x]);
        }
    }
}