"""
Count how many times a string is contained in another string by removing at most one character.

xxyzaabxyzzc, xxyz -> xxyz: 1 + xyz: 2 + xyz: 2 + xxy: 1
"""
import re


def find_in_string_with_removal(blob, s):
    count = find_count_in_string(blob, s)
    for i in xrange(len(s)):
        sub_s = s[0:i] + s[i + 1:]
        count += find_count_in_string(blob, sub_s)

    return count


def find_count_in_string(blob, s):
    res = blob.find(s)
    count = 0
    idx = 0
    while res >= 0:
        count += 1
        idx += res + len(s)
        res = blob[idx:].find(s)
    return count


if __name__ == '__main__':
    print find_in_string_with_removal('xxyzaabxyzzc', 'xxyz')