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>.
input_str = input().strip()
stack = []
maxlen = 0
subs_count = 0
count = 0
open_bracks = 0
for i in input_str:
    if i=='(':
        stack.append('(')
        open_bracks += 1
    else:
        if stack != [] and open_bracks > 0:
            open_bracks -= 1
            temp = 2
            if stack[-1]!= '(':
                temp += int(stack.pop())
            if stack !=  [] and stack[-1] == '(':
                stack.pop()
                if stack!= [] and stack[-1] not in ['(', '\n']:
                    stack.append(temp+int(stack.pop()))
                else:
                    stack.append(temp)
        else:
            stack.append("\n")
            
while stack!= []:
    val = stack.pop()
    if val not in ['(','\n']:
        val = int(val)
        if maxlen < val:
            maxlen = val
            count = 1
        elif maxlen == val:
            count += 1
if maxlen == 0:
    count = 1
print(maxlen, count)
