
    Write a function to analyze a student's learning progress string, where each digit represents completed tasks in different learning modules, and determine how many learning segments demonstrate balanced progress - where the total number of completed tasks equals the length of the segment. For example, in a progress string "234", a segment would be considered balanced if the sum of completed tasks in that segment equals the number of modules in that segment.
    

    
from collections import defaultdict

def count_Substrings(s):
    """
    Write a function to analyze a student's learning progress string, where each digit represents completed tasks in different learning modules, and determine how many learning segments demonstrate balanced progress - where the total number of completed tasks equals the length of the segment. For example, in a progress string "234", a segment would be considered balanced if the sum of completed tasks in that segment equals the number of modules in that segment.
    

    """
from collections import defaultdict

def count_Substrings(s):
    """
    Write a function to analyze a student's learning progress string, where each digit represents completed tasks in different learning modules, and determine how many learning segments demonstrate balanced progress - where the total number of completed tasks equals the length of the segment. For example, in a progress string "234", a segment would be considered balanced if the sum of completed tasks in that segment equals the number of modules in 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