Yet Another String Matching Problem

CodeForces - 954I