Language models read text as symbols, and a tokenizer invents them: it starts with single letters and keeps gluing two neighbours into a new symbol, so common chunks of text take fewer symbols. Write merge_once(tokens): add one new symbol, two neighbouring symbols glued together, chosen to make the text as short as possible, and glue it everywhere it fits, left to right. If two pairs would do equally well, take the one that shows up first in the text.