
    In a delivery route optimization system, write a function that identifies valid micro-routes from an encoded route string, where a valid micro-route is defined as a continuous sequence of segments whose total delivery points equal the number of segments in that sequence. Given a route identifier string where each digit represents the number of delivery stops in different segments, determine how many valid micro-routes exist within the complete route.
    

    
from collections import defaultdict

def count_Substrings(s):
    """
    In a delivery route optimization system, write a function that identifies valid micro-routes from an encoded route string, where a valid micro-route is defined as a continuous sequence of segments whose total delivery points equal the number of segments in that sequence. Given a route identifier string where each digit represents the number of delivery stops in different segments, determine how many valid micro-routes exist within the complete route.
    

    """
from collections import defaultdict

def count_Substrings(s):
    """
    In a delivery route optimization system, write a function that identifies valid micro-routes from an encoded route string, where a valid micro-route is defined as a continuous sequence of segments whose total delivery points equal the number of segments in that sequence. Given a route identifier string where each digit represents the number of delivery stops in different segments, determine how many valid micro-routes exist within the complete route.
    

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