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>.
s = input()
total = 0
from collections import defaultdict
ans = defaultdict(int)
pre = -1
for i,x in enumerate(s):
    if x == '(':
        total += 1
    else:
        total -= 1
        if total < 0:
            if i - 1 - pre > 0:
                ans[i - 1 - pre] += 1
            total = 0
            pre = i
stack = []
for i in range(pre + 1,len(s)):
    if s[i] == ')' and stack and s[stack[-1]] == '(':
        stack.pop()
    else:
        stack.append(i)
result = max((stack[i] - stack[i - 1] - 1 for i in range(1, len(stack))),default=len(s) - pre - 2)
ans[result] += 1
k = max(ans.keys())
print(k,ans[k])