This problem is in Contest(s) below:
Contest 1239:暑期C++编程训练A8
Contest 1240:暑期C++编程训练B8