This problem is in Contest(s) below:
Contest 1016:函数模板和类模板