Find all substrings with 0 sum
while ( i < n ) : NEW_LINE INDENT j = i - 1 NEW_LINE while ( i < n and a [ i ] != 0 ) : NEW_LINE INDENT i += 1 NEW_LINE DEDENT if ( i < n and a [ i - 1 ] < 0 ) : NEW_LINE INDENT ans += i - j NEW_LINE if ( j == 0 ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT i += 1 NEW_LINE DEDENT