Pattern Matching

CodeForces - 1476E