Traverse all substrings beginning at index i
for j in range ( i , n ) : NEW_LINE INDENT if ( s [ j ] == ' a ' ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT elif ( s [ j ] == ' c ' ) : NEW_LINE INDENT cnt -= 1 NEW_LINE DEDENT DEDENT