Rakuten Payment validates compact symbol sequences generated by payment-processing components. Given a string length, alphabet size, pattern, and target occurrence count, compute how many strings contain the pattern exactly k times.
Occurrences may overlap. For example, "aaa" contains "aa" twice, at positions 0 and 1.
Return the count modulo mod.
Implement count_strings(n, alphabet_size, pattern, k, mod):
n is the required string length.alphabet_size lowercase English letters: a, b, ..., starting from a.pattern is a non-empty lowercase string using only characters in that alphabet.n whose number of occurrences of pattern is exactly k.[0, mod - 1].Use an efficient algorithm. Enumerating all alphabet_size ** n strings is infeasible.
def count_strings(n, alphabet_size, pattern, k, mod):