| ICPC Masters Mexico LATAM 2023 |
|---|
| Закончено |
Acme Corp is analyzing a new potentially explosive substance that has been characterized on a chemical strip. The chemical strips used by Acme Corp to characterize substances consist of an $$$N$$$-section strip that is immersed in the chemical and allowed to react for at least one day. Once the reaction is complete, each of the $$$N$$$ sections will contain a characteristic of the element represented by a lowercase letter of the English alphabet (a-z).
Acme has identified that there are $$$L$$$ letters that represent risk factors in a substance. A substance is potentially explosive if it contains at least one substring that has exactly $$$K$$$ risk factors. The more substrings with these characteristics the substance has, the greater its explosive potential. Therefore, Acme measures the explosive potential of the substance as the number of substrings in the strip that meet these criteria.
Counting the explosive potential is time-consuming, and to optimize it, Acme Corp has hired you to create a program that, given the string representing the characterization strip, the letters considered risk factors, and the number $$$K$$$, determines the explosive potential of the substance in which that strip was immersed.
The first line of input contains three integer numbers $$$N$$$ ($$$1 \leq N \leq 10^6$$$) and $$$K$$$ ($$$1 \leq K \leq 10^6$$$), and $$$L$$$ ($$$0 \leq L \leq 26$$$) representing the number of sections on the strip, the number of risk factors a substring should have to increase the explosive potential of the substance, and the number of letters identified as risk factors.
The next line of input contains a string with exactly $$$N$$$ characters, representing the characterization of the substance in the strip.
The third and last line contains a string with exactly $$$L$$$ characters, the letters that are considered risk factors. Each character in the string is unique.
Output a line with a single integer, the total explosive potential of the substance in which the strip in the input was immersed.
4 1 1 abac a
6
4 2 2 bcfe bf
2
4 10 2 abdc ad
0
| Название |
|---|


