"""Failure mode: the other Bernoulli convention. This is a routine a language model can produce when the prompt does not name a convention: one that is correct under the *second* Bernoulli convention (``B1 = +1/2``) when the specification asked for the first (``B1 = -1/2``). Nothing here is mathematically wrong. It is wrong *for this specification*, and that distinction is the entire point. A single unstated convention makes two correct programs disagree, and no amount of re-reading the code will reveal it if you do not know the convention exists. Expected checker diagnosis: ``b1-sign``, with a first divergence at ``n=1``. """ from fractions import Fraction from math import comb def bernoulli(n: int) -> Fraction: """Return B_n using the second convention (B1 = +1/2).""" if n < 0: raise ValueError("n must be >= 0") values = [Fraction(0)] * (n + 1) for m in range(n + 1): values[m] = Fraction(1) for k in range(m): values[m] -= Fraction(comb(m, k) * values[k], m - k + 1) return values[n]