Flip a biased coin n times, heads with probability p. Return the expected
number of adjacent positions where both flips were heads.
There are adjacent pairs and each is HH with probability , so the answer is . The pairs overlap and are therefore dependent, which does not matter: expectation adds regardless.
Input
n = 10
p = 0.5
Output
2.25