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 sys import stdin

string = stdin.readline().rstrip()
max_length = 0
stack = list()
regular_length = 0
count = {0:1}
state = 1 # 0 if there is not break on the regular sequence counting, 1 otherwise
for c in string + ' ':
    if c == '(':
        stack.append(c)
        regular_length += 1
    elif stack:
        stack.pop()
        regular_length += 1
    elif regular_length:
        max_length = max(max_length, regular_length)
        count[max_length] = count.get(max_length, 0) + 1
        regular_length = 0

print(max_length, count[max_length])
