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>.
from collections import deque 

if __name__ == '__main__':
    stack = deque()
    resultados = list()
    initial_state = False
    parentesis = input()
    contador_substrings = 0
    max_substring = -1000000
    solo_string = 0
    for i in range(len(parentesis)):
        if (parentesis[i] == '('):
            stack.append('(')
            initial_state = True
            solo_string += 1
        elif (parentesis[i] == ')' and initial_state):
            stack.pop()
            if (len(stack) == 0):
                initial_state = False
                if (solo_string >= max_substring):
                    max_substring = solo_string
                resultados.append(solo_string*2)
                solo_string = 0
    if (len(resultados) == 0):
        print("0 1")
    else:
        resultados.sort(reverse = True)
        count = resultados.count(resultados[0])
        print(str(resultados[0]) + " " + str(count))


            
    
