A function f takes a string X and returns f(X)=A+X+B+X+C, where + is string concatenation and A, B, C are fixed non-empty strings.
Repeated application is defined by f1(X)=f(X) and fK(X)=f(fK−1(X)).
You are given strings A, B, C, S, F and an integer K. Count how many times F occurs as a substring of fK(S). Occurrences that start at different positions are counted separately, even when they overlap.