This problem is in Contest(s) below:
Contest 1105:后缀自动机