Swedish coins (1) P95248


Statement
 

pdf   zip

You have a collection CC of nn old Swedish coins. Every coin ii has a probability pip_i of landing heads (and a probability 1pi1 - p_i of landing tails). Consider the following experiment for every subset SS of CC: Flip each coin in SS exactly once, and count the number of heads; you win if this number is odd. Let w(S)w(S) denote the winning probability of the subset SS.

Given two real numbers \ell and rr, and a collection of coins CC, how many subsets SS of CC are such that <w(S)<r\ell < w(S) < r?

Input

Input consists of several cases. Every case begins with two real numbers \ell and rr, followed by nn, followed by p1pnp_1 \dots p_n. Assume 0<<r<10 < \ell < r < 1, 1n401 \le n \le 40 and 0<pi<10 < p_i < 1.

Output

For every case, print the number of subsets SS such that <w(S)<r\ell < w(S) < r. The input cases have no precision issues.

Observation

Please take into account that the result can be larger than 101210^{12}.

Public test cases
  • Input

    0.2 0.4
    1  0.3
    
    0.4 0.5
    1  0.3
    
    0.45 0.71
    2  0.7 0.6
    
    0.49 0.51
    5  0.5 0.5 0.5 0.5 0.5
    

    Output

    1
    0
    3
    31
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++