Base Condition
def parenthesis_count ( Str , i , j , isTrue , dp ) : NEW_LINE INDENT if ( i > j ) : NEW_LINE return 0 NEW_LINE if ( i == j ) : NEW_LINE if ( isTrue == 1 ) : NEW_LINE INDENT return 1 if Str [ i ] == ' T ' else 0 NEW_LINE DEDENT else : NEW_LINE INDENT return 1 if Str [ i ] == ' F ' else 0 NEW_LINE DEDENT if ( dp [ i ] [ j ] [ isTrue ] != - 1 ) : NEW_LINE return dp [ i ] [ j ] [ isTrue ] NEW_LINE temp_ans = 0 NEW_LINE for k in range ( i + 1 , j , 2 ) : NEW_LINE if ( dp [ i ] [ k - 1 ] [ 1 ] != - 1 ) : NEW_LINE INDENT leftTrue = dp [ i ] [ k - 1 ] [ 1 ] NEW_LINE DEDENT else : NEW_LINE DEDENT