"""Original statistics exercise, not a reproduction of Anthropic training.
Python 3.10+, standard library only; deterministic (no random seed).
"""
import math

def zero_failure_upper(n, confidence=0.95):
    if isinstance(n, bool) or not isinstance(n, int) or n < 1:
        raise ValueError("n must be a positive integer")
    if not math.isfinite(confidence) or not 0 < confidence < 1:
        raise ValueError("confidence must lie strictly between 0 and 1")
    return -math.expm1(math.log1p(-confidence) / n)

if __name__ == "__main__":
    for n in (100, 1000):
        upper = zero_failure_upper(n)
        print(f"0/{n}: one-sided 95% upper bound = {100*upper:.4f}%")
    assert abs(zero_failure_upper(1) - 0.95) < 1e-12
    assert zero_failure_upper(1000) < zero_failure_upper(100)
    assert abs((1-zero_failure_upper(100))**100 - 0.05) < 1e-12
    for invalid in (0, -1, 1.5, True):
        try:
            zero_failure_upper(invalid)
        except ValueError:
            pass
        else:
            raise AssertionError("invalid sample size accepted")
    print("7 checks passed")
