
    Design a function that analyzes a student's learning sequence code to identify balanced learning segments, where a balanced segment is defined as a continuous sequence of modules whose combined difficulty levels sum equals the number of modules in that sequence. Given a sequence code where each digit represents a module's difficulty level (0-9), determine how many balanced learning segments exist within the student's learning path.
    

    
from collections import defaultdict

def count_Substrings(s):
    """
    Design a function that analyzes a student's learning sequence code to identify balanced learning segments, where a balanced segment is defined as a continuous sequence of modules whose combined difficulty levels sum equals the number of modules in that sequence. Given a sequence code where each digit represents a module's difficulty level (0-9), determine how many balanced learning segments exist within the student's learning path.
    

    """
from collections import defaultdict

def count_Substrings(s):
    """
    Design a function that analyzes a student's learning sequence code to identify balanced learning segments, where a balanced segment is defined as a continuous sequence of modules whose combined difficulty levels sum equals the number of modules in that sequence. Given a sequence code where each digit represents a module's difficulty level (0-9), determine how many balanced learning segments exist within the student's learning path.
    

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