This problem is in Contest(s) below:
Contest 1130:十月队测题
Contest 1170:备战Noip2018