
    Given a customer's credit utilization sequence represented as a string of digits, write a function to identify how many periods of consistent financial behavior exist, where a period is defined as a substring whose digit sum equals its duration in months. This analysis helps assess the stability of a customer's credit usage patterns for risk evaluation.
    

    
from collections import defaultdict

def count_Substrings(s):
    """
    Given a customer's credit utilization sequence represented as a string of digits, write a function to identify how many periods of consistent financial behavior exist, where a period is defined as a substring whose digit sum equals its duration in months. This analysis helps assess the stability of a customer's credit usage patterns for risk evaluation.
    

    """
from collections import defaultdict

def count_Substrings(s):
    """
    Given a customer's credit utilization sequence represented as a string of digits, write a function to identify how many periods of consistent financial behavior exist, where a period is defined as a substring whose digit sum equals its duration in months. This analysis helps assess the stability of a customer's credit usage patterns for risk evaluation.
    

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