This problem is in Contest(s) below:
Contest 1502:Trie及Ac自动机入门
Contest 1296:字符串入门