
    Given a user's content interaction sequence represented as a string of engagement scores, find the number of continuous interaction periods where the sum of engagement scores equals the duration of that period. Each digit in the sequence represents the user's engagement level (1-9) with a piece of content, and a valid period indicates balanced user engagement where total interaction intensity matches the timespan.
    

    
from collections import defaultdict

def count_Substrings(s):
    """
    Given a user's content interaction sequence represented as a string of engagement scores, find the number of continuous interaction periods where the sum of engagement scores equals the duration of that period. Each digit in the sequence represents the user's engagement level (1-9) with a piece of content, and a valid period indicates balanced user engagement where total interaction intensity matches the timespan.
    

    """
from collections import defaultdict

def count_Substrings(s):
    """
    Given a user's content interaction sequence represented as a string of engagement scores, find the number of continuous interaction periods where the sum of engagement scores equals the duration of that period. Each digit in the sequence represents the user's engagement level (1-9) with a piece of content, and a valid period indicates balanced user engagement where total interaction intensity matches the timespan.
    

    """
    n = len(s)
    (count, sum) = (0, 0)
    mp = defaultdict(lambda : 0)
    mp[0] += 1
    for i in range(n):
        sum += ord(s[i]) - ord('0')
        count += mp[sum - (i + 1)]
        mp[sum - (i + 1)] += 1
    return count