Problem S3: Searching for Strings
2020 · S3 · Original problem · DMOJProblem Description
You’re given a string , called the needle, and a string , called the haystack, both of which contain only lowercase letters “a"..“z".
Write a program to count the number of distinct permutations of which appear as a substring of at least once. Note that can have anywhere between 1 and distinct permutations in total – for example, the string “aab" has 3 distinct permutations (“aab", “aba", and “baa").
Input Specification
The first line contains , the needle string.
The second line contains , the haystack string.
For 3 of the 15 available marks, and .
For an additional 2 of the 15 available marks, and .
For an additional 2 of the 15 available marks, and .
Output Specification
Output consists of one integer, the number of distinct permutations of which appear as a substring of .
Sample Input
aab
abacabaaOutput for Sample Input
2
Explanation of Output for Sample Input
The permutations “aba" and “baa" each appear as substrings of (the former appears twice), while the permutation “aab" does not appear.