human
Number of balanced bracket subsequence of length 2 and 4 | Python 3 implementation of above approach.
Taking the frequency suffix sum of the number of 2 's present  after every index.
Storing the count of subsequence.
Subsequence of length 2.
Subsequence of length 4 of type 1 1 2 2.
Subsequence of length 4 of type 1 2 1 2.
Driver Code"
Solution in Python:

=====
Can you provide a code to number of balanced bracket subsequence of length 2 and 4 and the other steps required?
assistant
#Here is code to number of balanced bracket subsequence of length 2 and 4 and the other steps required.
 def countWays ( a , n ) :
	suff = [ 0 ] * n
	if ( a [ n - 1 ] == 2 ) :
		suff [ n - 1 ] = 1
	for i in range ( n - 2 , - 1 , - 1 ) :
		if ( a [ i ] == 2 ) :
			suff [ i ] = suff [ i + 1 ] + 1
		else :
			suff [ i ] = suff [ i + 1 ]
	ss = 0
	for i in range ( n ) :
		if ( a [ i ] == 1 ) :
			ss += suff [ i ]
	for i in range ( n ) :
		for j in range ( i + 1 , n ) :
			if ( a [ i ] == 1 and a [ j ] == 1 and suff [ j ] >= 2 ) :
				ss += ( suff [ j ] ) * ( suff [ j ] - 1 ) // 2
	for i in range ( n ) :
		for j in range ( i + 1 , n ) :
			if ( a [ i ] == 1 and a [ j ] == 1 and ( suff [ i ] - suff [ j ] ) >= 1 and suff [ j ] >= 1 ) :
				ss += ( suff [ i ] - suff [ j ] ) * suff [ j ]
	print ( ss )
if __name__ == " _ _ main _ _ " :
	a = [ 1 , 2 , 1 , 1 , 2 , 2 ]
	n = 6
	countWays ( a , n )