One-pass Algorithm for "B"