Coding and learning of behavioral sequences