Question: 
Write a python function to count number of substrings with the sum of digits equal to their length.


Model's Code:
def count_Substrings(s, n):
    count = 0
    for i in range(len(s)):
        curr_sum = 0
        for j in range(i, len(s)):
            curr_sum += int(s[j])
            if curr_sum == (j - i + 1):
                count += 1
    return count



Sample Correct Code:
from collections import defaultdict
def count_Substrings(s,n):
    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


Asserts:
assert count_Substrings('112112',6) == 6
assert count_Substrings('111',3) == 6
assert count_Substrings('1101112',7) == 12


Tests:
Test 1 of 3: PASS
Test 2 of 3: PASS
Test 3 of 3: PASS

Test 61 of 974: 46/61 (75.40983606557377%): success