2854.Fuzzy Search

Time Limit: 1s Memory Limit: 256MB

Leonid works for a small and promising start-up that works on decoding the human genome. His duties include solving complex problems of finding certain patterns in long strings consisting of letters 'A', 'T', 'G' and 'C'.

Let's consider the following scenario. There is a fragment of a human DNA chain, recorded as a string S. To analyze the fragment, you need to find all occurrences of string T in a string S. However, the matter is complicated by the fact that the original chain fragment could contain minor mutations, which, however, complicate the task of finding a fragment. Leonid proposed the following approach to solve this problem.

Let's write down integer k \ge 0 - the error threshold. We will say that string T occurs in string S on position i (1 \le i \le |S|-|T|+1), if after putting string T along with this position, each character of string T corresponds to the some character of the same value in string S at the distance of at most k. More formally, for any j (1 \le j \le |T|) there must exist such p (1 \le p \le |S|), that |(i+j-1)-p| \le k and S[p]=T[j].

For example, corresponding to the given definition, string "ACAT" occurs in string "AGCAATTCAT" in positions 2, 3 and 6.

2854_1.png

Note that at k=0 the given definition transforms to a simple definition of the occurrence of a string in a string.

Help Leonid by calculating in how many positions the given string T occurs in the given string S with the given error threshold.

Input Format(From the terminal/stdin)

The first line contains three integers |S|,|T|,k (1 \le |T| \le |S| \le 200000, 0 \le k \le 200000) - the lengths of strings S and T and the error threshold.

The second line contains string S.

The third line contains string T.

Both strings consist only of uppercase letters 'A', 'T', 'G' and 'C'.

Output Format(To the terminal/stdout)

Print a single number - the number of occurrences of T in S with the error threshold k by the given definition.

Sample Input

Copy
10 4 1
AGCAATTCAT
ACAT
  · · \n
          \n
    \n

Sample Output

Copy
3
 \n

Hints

If you happen to know about the structure of the human genome a little more than the author of the problem, and you are not impressed with Leonid's original approach, do not take everything described above seriously.

Submit

请先 登录

© 2025 FAQs