// probability of exactly r successes in n trials,
// if p is the probability of success in one trial.
// 0 <= p <= 1, 0 <= r <= n
double binom(int n, int r, double p) {
const int x = std::min(r, n-r);
double d = 1;
int i = 0, j = 2*x+n;
while (i < j) {
const int k = d<1 ? i++...