human
Number of balanced parenthesis substrings | Function to find number of balanced parenthesis sub strings.
To store required answer.
Vector to stores the number of balanced brackets at each depth ..
d stores checks the depth of our sequence For example level of ( ) is 1 and that of ( ( ) ) is 2..
If open bracket increase depth.
If closing bracket.
Return the required answer.
Driver code.
Function call"
How can the above be solved in Python?

Write me a code to number of balanced parenthesis substrings and the other steps required?
assistant
#Here is code to number of balanced parenthesis substrings and the other steps required.
 def Balanced_Substring ( s , n ) :
	ans = 0 ;
	arr = [ 0 ] * ( int ( n / 2 ) + 1 ) ;
	d = 0 ;
	for i in range ( n ) :
		if ( s [ i ] == ' ( ' ) :
			d += 1 ;
		else :
			if ( d == 1 ) :
				j = 2
				while ( j <= n // 2 + 1 and arr [ j ] != 0 ) :
					arr [ j ] = 0
			ans += 1 ;
			ans += arr [ d ] ;
			arr [ d ] += 1 ;
			d -= 1 ;
	return ans ;
s = " ( ) ( ) ( ) " ;
n = len ( s ) ;
print ( Balanced_Substring ( s , n ) ) ;