Problem. Candidate A gets votes and B gets votes, counted in random order. What is the probability that A is strictly ahead throughout the count?

Answer: (Bertrand). The number of such orderings is .

long long ballotCount(int a, int b) {             // orderings of a A-votes and b B-votes (a > b) with A strictly ahead throughout
    long long c = 1; for (int i = 1; i <= b; i++) c = c * (a + i) / i;   // C(a + b, b)
    return c * (a - b) / (a + b);
}