Long-term memory emerges from a sequence of molecular programs that sort, stabilize, and reinforce important experiences.