This is yet another problem dealing with regular bracket sequences.

We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. 

You are given a string of «(» and «)» characters. You are to find its longest substring that is a regular bracket sequence. You are to find the number of such substrings as well.
The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 10<sup class="upper-index">6</sup>.
import sys
import math

texto = sys.stdin.read().split("\n")
texto.pop(-1)
texto = texto[0]

open_b = []
close_b = []
count = 1
length = 0
max_length = 0
for char in texto:
    if char == "(":
        open_b.append(char) 
    elif char == ")":
        if len(open_b) == 0:
            length = 0
        else:
            length+=2
            open_b.pop(-1)
            if True:
                if length > max_length:
                    max_length = length
                    count = 1
                elif length == max_length:
                    count+= 1
            

print(str(max_length) + " " + str(count))
        
    
