add the solution to problem 3080 and use KMP algorithm