human
Maximum Pairs of Bracket Sequences which can be concatenated to form a Regular Bracket Sequence | Function to count the number of pairs whose concatenation results in the regular bracket sequence.
Stores the count of opening and closing parenthesis for each string arr [ i ].
Stores maximum count of pairs.
Traverse the array arr [ ].
Traverse the string c [ ].
Opening Bracket.
Otherwise , Closing Bracket.
Count of closing brackets needed to balance string.
Count of opening brackets needed to balance string.
Add the count of balanced sequences.
Traverse the array.
Print the resultant count.
Driver Code"
Solution in Python:
assistant
#Here is code to maximum Pairs of Bracket Sequences which can be concatenated to form a Regular Bracket Sequence and the other steps required.
 def countPairs ( N , arr ) :
	open = [ 0 ] * 100
	close = [ 0 ] * 100
	ans = 0
	for i in range ( N ) :
		c = [ i for i in arr [ i ] ]
		d = 0
		minm = 0
		for j in range ( len ( c ) ) :
			if ( c [ j ] == ' ( ' ) :
				d += 1
			else :
				d -= 1
				if ( d < minm ) :
					minm = d
		if ( d >= 0 ) :
			if ( minm == 0 ) :
				close [ d ] += 1
		elif ( d < 0 ) :
			if ( minm == d ) :
				open [ - d ] += 1
	ans += close [ 0 ] // 2
	for i in range ( 1 , 100 ) :
		ans += min ( open [ i ] , close [ i ] )
	print ( ans )
if __name__ == ' _ _ main _ _ ' :
	N = 7
	list = [ ]
	list . append ( " ) ( ) ) " )
	list . append ( " ) " )
	list . append ( " ( ( " )
	list . append ( " ( ( " )
	list . append ( " ( " )
	list . append ( " ) " )
	list . append ( " ) " )
	countPairs ( N , list )