This problem is in Contest(s) below:
Contest 1324:行之高年级第一节课练习(枚举、桶、排序,字符串)
Contest 1761:枚举练习
Contest 1768:普及组(基础)第二天