Orig Description
Iku is unfortunate in that the important string T he had was rewritten to a different string T' by a virus. It is known that the virus rewrote one character of T to a different character. That is, T and T' differ by exactly one character. Iku has prepared a document S where T is believed to appear. As a preparation for restoring T, he wants to determine the number of substrings of S that may match T by differing by only one character.
Given strings T' and S, find the number of substrings of S of length |T'| that differ by only one character from T'.
Input
The input is given in the following format.
S
T'
The first line contains S.
The second line contains T'.
S and T' consist only of upper- and lowercase letters.
Constraints
Each variable in the input satisfies the following constraints.
1 ≤ |S| ≤ 300,000
1 ≤ |T'| ≤ |S|
Output
Output the number of substrings that satisfy the condition in a single line.
Sample Input 1
abcbcdbc
abc
Output for the Sample Input 1
2
cbc starting from the 3rd character of S and dbc starting from the 6th character of S satisfy the condition.
Sample Input 2
aaaaaa
aaaaaa
Output for the Sample Input 2
0
Do not count the string that is a complete match.
Sample Input 3
baaaaaaaa
b
Output for the Sample Input 3
8
Extracted Specification
An uppercase or lowercase string S (1 ≤ |S| ≤ 300,000).
An uppercase or lowercase string T' (1 ≤ |T'| ≤ |S|).
### Example Input:
```
abcbcdbc
abc
```
### Function Signature:
Write a function f(S, T_prime) that takes in the input.
```python
def f(S: str, T_prime: str):
'''
S: a string
T_prime: a string
'''
```
Test Case Generator
Sure! Below is a test case generator function for the given problem statement:
```python
import random
import string
def generate_random_string(length, chars=string.ascii_letters):
return ''.join(random.choice(chars) for _ in range(length))
def tcgen():
# Length of S (1 ≤ |S| ≤ 300,000)
len_S = random.randint(1, 300000)
# Length of T' (1 ≤ |T'| ≤ |S|)
len_T_prime = random.randint(1, len_S)
# Generate random string S
S = generate_random_string(len_S)
# Generate random string T'
T_prime = generate_random_string(len_T_prime)
return S, T_prime
# Example usage of the test case generator
if __name__ == "__main__":
S, T_prime = tcgen()
print("S:", S)
print("T':", T_prime)
```
This test case generator function does the following:
1. Randomly selects the length of the string `S` within the given constraints (1 to 300,000).
2. Randomly selects the length of the string `T'` such that it is no greater than the length of `S`.
3. Generates a random string `S` of the selected length consisting of uppercase and lowercase letters.
4. Generates a random string `T'` of the selected length consisting of uppercase and lowercase letters.
You can use this function to generate random test cases for the problem. The generated test cases will be in line with the given constraints and will help in testing the solution thoroughly.
Extract Arguments
def extract_arguments(fh):
S = fh.readline().strip()
T_prime = fh.readline().strip()
return S, T_prime