
    Given a delivery route identifier string where each digit represents the number of stops in different route segments, write a function to find the number of continuous route segments where the sum of checkpoint counts equals the segment's total length. For example, in a route "1234", a segment "12" has length 2 and sum of stops 3, making it invalid, while "234" has length 3 and sum of stops 9, making it valid.
    

    
from collections import defaultdict

def count_Substrings(s):
    """
    Given a delivery route identifier string where each digit represents the number of stops in different route segments, write a function to find the number of continuous route segments where the sum of checkpoint counts equals the segment's total length. For example, in a route "1234", a segment "12" has length 2 and sum of stops 3, making it invalid, while "234" has length 3 and sum of stops 9, making it valid.
    

    """
from collections import defaultdict

def count_Substrings(s):
    """
    Given a delivery route identifier string where each digit represents the number of stops in different route segments, write a function to find the number of continuous route segments where the sum of checkpoint counts equals the segment's total length. For example, in a route "1234", a segment "12" has length 2 and sum of stops 3, making it invalid, while "234" has length 3 and sum of stops 9, making it valid.
    

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