
    Write a function that analyzes bus occupancy data to identify periods where the total passenger count matches the duration of the time window, where the input is a string of single-digit passenger counts at sequential stops. For example, if "1234" represents four consecutive stops, we need to find all segments where the sum of passenger counts equals the length of that segment.
    

    
from collections import defaultdict

def count_Substrings(s):
    """
    Write a function that analyzes bus occupancy data to identify periods where the total passenger count matches the duration of the time window, where the input is a string of single-digit passenger counts at sequential stops. For example, if "1234" represents four consecutive stops, we need to find all segments where the sum of passenger counts equals the length of that segment.
    

    """
from collections import defaultdict

def count_Substrings(s):
    """
    Write a function that analyzes bus occupancy data to identify periods where the total passenger count matches the duration of the time window, where the input is a string of single-digit passenger counts at sequential stops. For example, if "1234" represents four consecutive stops, we need to find all segments where the sum of passenger counts equals the length of that segment.
    

    """
    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