human
Count of sub | Function to return the count of valid sub - Strings.
Variable ans to store all the possible subStrings Initialize its value as total number of subStrings that can be formed from the given String.
Stores recent index of the characters.
If character is a update a 's index  and the variable ans.
If character is b update b 's index  and the variable ans.
If character is c update c 's index  and the variable ans.
Driver code"
Solution in Python:

What is a code to count of sub and the other steps required?
assistant
#Here is code to count of sub and the other steps required.
 def CountSubString ( Str , n ) :
	ans = ( n * ( n + 1 ) ) // 2
	a_index = 0
	b_index = 0
	c_index = 0
	for i in range ( n ) :
		if ( Str [ i ] == ' a ' ) :
			a_index = i + 1
			ans -= min ( b_index , c_index )
		elif ( Str [ i ] == ' b ' ) :
			b_index = i + 1
			ans -= min ( a_index , c_index )
		else :
			c_index = i + 1
			ans -= min ( a_index , b_index )
	return ans
Str = " babac "
n = len ( Str )
print ( CountSubString ( Str , n ) )