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 queue import LifoQueue
test = 1
#test = input()
while test:
    s = input()
    n = len(s)
    stack = LifoQueue(n+1)
    mx = 0
    cnt = 0
    for i in range(n):
        if s[i] == '(':
            stack.put('(')
        else:
            if stack.empty():
                mx = max(cnt, mx)
                cnt = 0
            else:
                stack.get()
                cnt += 1
                mx = max(cnt, mx)
        mx = max(mx, cnt)
    if not mx:
        print("0 1")
        break
    numMax = 0
    while not stack.empty():
        stack.get()
    for i in range(len(s)):
        if s[i] == '(':
            stack.put('(')
        else:
            if stack.empty():
                numMax += cnt == mx
                cnt = 0
            else:
                stack.get()
                cnt += 1
            #    numMax += cnt == mx
    print(mx * 2, numMax)
    test -= 1