Solution (source code)

= Solution

Condition on a position retained after basis reconciliation, so Bob used Alice's basis. If Eve does not intercept, no error occurs. If she intercepts, her uniformly chosen basis agrees with Alice's with probability $1/2$, again causing no error. With probability $1/2$ she uses the conjugate basis; her measurement and resent state then make Bob's bit uniformly random, giving an error with probability $1/2$.

Therefore the <bit error rate> in the retained key is
$$
\boxed{p\times\frac12\times\frac12=\frac p4.}
$$